Sort document input fields according to document position
Description
Document input fields returned by OpenOfficeDocument.getInputFields() are returned in random order. When prompting for documents parameters, this means that the parameters appear in a different order each time a document is generated.
Using XTextViewCursor.gotoRange() suffers from timing issues. Calling gotoRange() followed by getPosition() multiple times on different fields within an short period can return the same position for different fields. It looks like gotoRange() is done asynchronously, because the same calls with a short delay return the correct positions.
Document input fields returned by OpenOfficeDocument.getInputFields() are returned in random order.
When prompting for documents parameters, this means that the parameters appear in a different order each time a document is generated.
According to http://www.oooforum.org/forum/viewtopic.phtml?t=124460 it should be possible to sort the fields according to their X,Y coordinates in the document.
The coordinates may be accessed as follows:
XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier)UnoRuntime.queryInterface(XTextFieldsSupplier.class, xCurrentComponent); XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields(); XEnumeration enumeration = xEnumeratedFields.createEnumeration(); LlistaMarquesFusionables retorn = new LlistaMarquesFusionables(); while(enumeration.hasMoreElements()){ Object nextMark = enumeration.nextElement(); XDependentTextField dependentTextField = (XDependentTextField)UnoRuntime.queryInterface(XDependentTextField.class, nextMark); ... XTextViewCursor xTextViewCursor = xViewCursorSupplier.getViewCursor(); XTextRange xTextRange = dependentTextField.getAnchor(); xTextViewCursor.gotoRange(xTextRange, false); int x = xTextViewCursor.getPosition().X; int y= xTextViewCursor.getPosition().Y; }