Search in sources :

Example 1 with XTextDocument

use of com.sun.star.text.XTextDocument 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)

Example 2 with XTextDocument

use of com.sun.star.text.XTextDocument in project jabref by JabRef.

the class OOBibBase method selectDocument.

public void selectDocument() throws UnknownPropertyException, WrappedTargetException, IndexOutOfBoundsException, NoSuchElementException, NoDocumentException {
    List<XTextDocument> textDocumentList = getTextDocuments();
    XTextDocument selected;
    if (textDocumentList.isEmpty()) {
        // No text documents found.
        throw new NoDocumentException("No Writer documents found");
    } else if (textDocumentList.size() == 1) {
        // Get the only one
        selected = textDocumentList.get(0);
    } else {
        // Bring up a dialog
        selected = selectComponent(textDocumentList);
    }
    if (selected == null) {
        return;
    }
    xCurrentComponent = UnoRuntime.queryInterface(XComponent.class, selected);
    mxDoc = selected;
    UnoRuntime.queryInterface(XDocumentIndexesSupplier.class, xCurrentComponent);
    XModel xModel = UnoRuntime.queryInterface(XModel.class, xCurrentComponent);
    XController xController = xModel.getCurrentController();
    xViewCursorSupplier = UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
    // get a reference to the body text of the document
    text = mxDoc.getText();
    // Access the text document's multi service factory:
    mxDocFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, mxDoc);
    XDocumentPropertiesSupplier supp = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, mxDoc);
    userProperties = supp.getDocumentProperties().getUserDefinedProperties();
    propertySet = UnoRuntime.queryInterface(XPropertySet.class, userProperties);
}
Also used : XPropertySet(com.sun.star.beans.XPropertySet) XDocumentPropertiesSupplier(com.sun.star.document.XDocumentPropertiesSupplier) XTextViewCursorSupplier(com.sun.star.text.XTextViewCursorSupplier) XTextDocument(com.sun.star.text.XTextDocument) XComponent(com.sun.star.lang.XComponent) XMultiServiceFactory(com.sun.star.lang.XMultiServiceFactory) XController(com.sun.star.frame.XController) XModel(com.sun.star.frame.XModel)

Example 3 with XTextDocument

use of com.sun.star.text.XTextDocument in project jabref by JabRef.

the class OOBibBase method selectComponent.

public static XTextDocument selectComponent(List<XTextDocument> list) throws UnknownPropertyException, WrappedTargetException, IndexOutOfBoundsException {
    String[] values = new String[list.size()];
    int ii = 0;
    for (XTextDocument doc : list) {
        values[ii] = String.valueOf(OOUtil.getProperty(doc.getCurrentController().getFrame(), "Title"));
        ii++;
    }
    JList<String> sel = new JList<>(values);
    sel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sel.setSelectedIndex(0);
    int ans = JOptionPane.showConfirmDialog(null, new JScrollPane(sel), Localization.lang("Select document"), JOptionPane.OK_CANCEL_OPTION);
    if (ans == JOptionPane.OK_OPTION) {
        return list.get(sel.getSelectedIndex());
    } else {
        return null;
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) XTextDocument(com.sun.star.text.XTextDocument) Point(com.sun.star.awt.Point) JList(javax.swing.JList)

Aggregations

XTextDocument (com.sun.star.text.XTextDocument)3 XComponent (com.sun.star.lang.XComponent)2 Point (com.sun.star.awt.Point)1 XPropertySet (com.sun.star.beans.XPropertySet)1 XEnumeration (com.sun.star.container.XEnumeration)1 XEnumerationAccess (com.sun.star.container.XEnumerationAccess)1 XDocumentPropertiesSupplier (com.sun.star.document.XDocumentPropertiesSupplier)1 XController (com.sun.star.frame.XController)1 XModel (com.sun.star.frame.XModel)1 XMultiServiceFactory (com.sun.star.lang.XMultiServiceFactory)1 XTextViewCursorSupplier (com.sun.star.text.XTextViewCursorSupplier)1 ArrayList (java.util.ArrayList)1 JList (javax.swing.JList)1 JScrollPane (javax.swing.JScrollPane)1