Ask Your Question

Java sidebar extension and LibreOffice

asked 2015-02-06 09:03:26 +0200

fma gravatar image

Hi all,

I need to create a sidebar extension for LibreOffice users and it must be Java-based.

My starting point was the OpenOffice Wiki page for sidebar developers:

Unfortunately, the sample code on the wiki page for the Analog Clock Extension works fine for OpenOffice 4.1.1 but the UI is not shown on LibreOffice 4.4.

Steps to reproduce the problem:

original dependencies tag content:

< value="4.0" d:name="Apache OpenOffice"/>

new dependencies tag content:

< value="4.x" dep:name=" 4.x""4.0"/>

  • install the extension on LibreOffice (enable Java Runtime Environment if needed)

  • after restarting LibreOffice, you will see the icon of the new sidebar panel just below the others, but no interface is shown when clicking on it (i.e. the analog clock and also its container panel are not visible)

I gave a look to the source code but with no luck: can someone give me a hint about the possible cause of the problem?

Thanks in advance and best regards.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-02-10 15:30:33 +0200

vmiklos gravatar image

It would be great if you could check your Java/UNO code with an older version of LibreOffice -- if it works there, then that's a regression and you should report it at . Once there is an older version that's known to be good, it's much easier to track down such a problem.

Alternatively, you could check if your problems are sidebar-specific or not, e.g. modify one of the Java examples from to do the same what you do inside the sidebar code and see if your code works then, without the sidebar.

edit flag offensive delete link more


Thanks for your suggestions, I will try and let you know (and report bugs if I will find any). Thanks again and best regards.

fma gravatar imagefma ( 2015-02-10 15:57:29 +0200 )edit

answered 2015-02-10 14:50:19 +0200

fma gravatar image

updated 2015-02-12 09:41:16 +0200




I found it!!!

Still don't know what's going on behind the scenes, but at least the panel is now visible.

In the build path of the extension, I changed the pointing of unoil.jar from the file included in the path of AOO installation ( [aoo_installation_path]\program\classes ) to the one in the installation path of LO ( [aoo_installation_path]\program\classes ).

This raised an error in, which was asking for adding the unimplemented method getMinimalWidth(): I added it, generated the oxt file and... Voila!... the extension now runs fine on LO 4.4 too.



Got it!!!

More similar to a workaround than a real solution, at least it works: a gotoStart() call was included in the original code (even if not in the snippets) and it didn't work, but simply putting the code to change font and alignment as well as to add page breaks (see code snippets in my previous reply) at the beginning, before doing everything else, was the solution.

Now all kind of formatting, replacements and insertions are correctly put in the active document.


Unfortunately, I have now two problems with my custom extension, which manipulates in several ways the active text document.

In details, I have two operations running fine in AOO 4.1.1 but having unexpected results in LO 4.4; here they are:

Code snippet 1 - expected behaviour: formatting the whole document with font Arial Black, size 14, justified; current behaviour: only the last paragraph is formatted

// active writer document
XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xCurrentComponent);

// creating text range and cursor
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.createTextCursor();

// going to the end of document

// getting properties
XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextRange);

// setting font size
xTextProps.setPropertyValue("CharHeight", new Float(14));

// justifying

// setting font
xTextProps.setPropertyValue("CharFontName", "Arial Black");

Code snippet 2 - expected behaviour: inserting a page break just before each paragraph starting with the word "Chapter"; current behaviour: nothing happens

XTextCursor xTextCursor = xText.createTextCursor();

// using a search descriptor to perform insert operations
XSearchable xSearchable = (XSearchable) UnoRuntime.queryInterface(XSearchable.class, xTextDocument);
XSearchDescriptor xSearchDescriptor = xSearchable.createSearchDescriptor(); 

xSearchDescriptor.setPropertyValue("SearchRegularExpression", new Boolean(true));
xSearchDescriptor.setPropertyValue("SearchCaseSensitive", new Boolean(true));

XInterface xInterface= (XInterface) xSearchable.findFirst(xSearchDescriptor); 
while (xInterface != null){

XTextRange xStart = ( UnoRuntime.queryInterface(, xInterface); 

xTextCursor.gotoRange(xStart, false); 

XPropertySet cursorProperty = UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);    

cursorProperty.setPropertyValue("BreakType", BreakType.PAGE_BEFORE); //$NON-NLS-1$

xInterface = (XInterface) xSearchable.findNext(xInterface, xSearchDescriptor); 

Any ideas about the reasons of the misbehaviour?

Thanks in advance and best regards

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-02-06 09:03:26 +0200

Seen: 587 times

Last updated: Feb 12 '15