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.

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; }

Environment

None

Activity

Tim Anderson October 14, 2021 at 11:47 PM

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.

Details

Assignee

Reporter

Original estimate

Time tracking

5h logged

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created January 6, 2013 at 4:24 PM
Updated August 7, 2024 at 10:58 PM
Who's Looking?