# Java sidebar extension and LibreOffice

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: https://wiki.openoffice.org/wiki/Side...

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:

<OpenOffice.org-minimal-version value="4.0" d:name="Apache OpenOffice"/>

new dependencies tag content:

<OpenOffice.org-maximal-version value="4.x" dep:name="OpenOffice.org 4.x" dep:OpenOffice.org-minimal-version="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 close merge delete

Sort by » oldest newest most voted

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 https://bugs.documentfoundation.org/e... . 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 http://api.libreoffice.org/examples/e... to do the same what you do inside the sidebar code and see if your code works then, without the sidebar.

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.

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

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

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 AnalogClockPanel.java, 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.

-------------------------------------------------------------------------------

PROBLEMS MENTIONED BELOW HAVE BEEN SOLVED:

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
((XTextCursor)xTextRange).gotoEnd(true);

// 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));
xSearchDescriptor.setSearchString("Chapter");

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

XTextRange xStart = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface(com.sun.star.text.XTextRange.class, 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

more