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