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