Search in sources :

Example 1 with XEnumerationAccess

use of com.sun.star.container.XEnumerationAccess in project zotero-libreoffice-integration by zotero.

the class Document method cursorInField.

public ReferenceMark cursorInField(String fieldType) throws Exception {
    // create two text cursors containing the selection
    XTextViewCursor selectionCursor = getSelection();
    XText text = selectionCursor.getText();
    XParagraphCursor paragraphCursor1 = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, text.createTextCursorByRange(selectionCursor));
    XParagraphCursor paragraphCursor2 = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, text.createTextCursorByRange(selectionCursor));
    // extend one cursor to the beginning of the paragraph and one to the end
    paragraphCursor1.goLeft((short) 1, false);
    paragraphCursor1.gotoStartOfParagraph(true);
    paragraphCursor2.gotoEndOfParagraph(true);
    // get enumerator corresponding to first cursor
    XEnumerationAccess enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, paragraphCursor1);
    Object nextElement = enumeratorAccess.createEnumeration().nextElement();
    enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, nextElement);
    XEnumeration enumerator = enumeratorAccess.createEnumeration();
    while (enumerator.hasMoreElements()) {
        // look for a ReferenceMark or Bookmark
        XPropertySet textProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, enumerator.nextElement());
        String textPropertyType = (String) textProperties.getPropertyValue("TextPortionType");
        if (textPropertyType.equals(fieldType)) {
            ReferenceMark mark = mMarkManager.getMark(textProperties.getPropertyValue(fieldType), fieldType);
            if (mark != null) {
                // check second enumerator for the same field
                enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, paragraphCursor2);
                nextElement = enumeratorAccess.createEnumeration().nextElement();
                enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, nextElement);
                XEnumeration enumerator2 = enumeratorAccess.createEnumeration();
                while (enumerator2.hasMoreElements()) {
                    textProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, enumerator2.nextElement());
                    textPropertyType = (String) textProperties.getPropertyValue("TextPortionType");
                    if (textPropertyType.equals(fieldType)) {
                        if (mark == mMarkManager.getMark(textProperties.getPropertyValue(fieldType), fieldType)) {
                            return mark;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XPropertySet(com.sun.star.beans.XPropertySet) XParagraphCursor(com.sun.star.text.XParagraphCursor) XText(com.sun.star.text.XText) XEnumeration(com.sun.star.container.XEnumeration) XTextViewCursor(com.sun.star.text.XTextViewCursor) XEnumerationAccess(com.sun.star.container.XEnumerationAccess)

Example 2 with XEnumerationAccess

use of com.sun.star.container.XEnumerationAccess in project jabref by JabRef.

the class OOBibBase method getTextDocuments.

private List<XTextDocument> getTextDocuments() throws NoSuchElementException, WrappedTargetException {
    List<XTextDocument> result = new ArrayList<>();
    XEnumerationAccess enumAccess = xDesktop.getComponents();
    XEnumeration componentEnumeration = enumAccess.createEnumeration();
    while (componentEnumeration.hasMoreElements()) {
        Object nextElement = componentEnumeration.nextElement();
        XComponent component = UnoRuntime.queryInterface(XComponent.class, nextElement);
        XTextDocument document = UnoRuntime.queryInterface(XTextDocument.class, component);
        if (document != null) {
            result.add(document);
        }
    }
    return result;
}
Also used : XTextDocument(com.sun.star.text.XTextDocument) XComponent(com.sun.star.lang.XComponent) ArrayList(java.util.ArrayList) XEnumeration(com.sun.star.container.XEnumeration) XEnumerationAccess(com.sun.star.container.XEnumerationAccess)

Aggregations

XEnumeration (com.sun.star.container.XEnumeration)2 XEnumerationAccess (com.sun.star.container.XEnumerationAccess)2 XPropertySet (com.sun.star.beans.XPropertySet)1 XComponent (com.sun.star.lang.XComponent)1 XParagraphCursor (com.sun.star.text.XParagraphCursor)1 XText (com.sun.star.text.XText)1 XTextDocument (com.sun.star.text.XTextDocument)1 XTextViewCursor (com.sun.star.text.XTextViewCursor)1 ArrayList (java.util.ArrayList)1