use of com.sun.star.beans.PropertyVetoException in project jabref by JabRef.
the class OpenOfficePanel method initPanel.
private void initPanel() {
connect.addActionListener(e -> connect(true));
manualConnect.addActionListener(e -> connect(false));
selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on"));
selectDocument.addActionListener(e -> {
try {
ooBase.selectDocument();
frame.output(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle().orElse(""));
} catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | NoSuchElementException | NoDocumentException ex) {
JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
LOGGER.warn("Problem connecting", ex);
}
});
setStyleFile.addActionListener(event -> {
if (styleDialog == null) {
styleDialog = new StyleSelectDialog(frame, preferences, loader);
}
styleDialog.setVisible(true);
styleDialog.getStyle().ifPresent(selectedStyle -> {
style = selectedStyle;
try {
style.ensureUpToDate();
} catch (IOException e) {
LOGGER.warn("Unable to reload style file '" + style.getPath() + "'", e);
}
frame.setStatus(Localization.lang("Current style is '%0'", style.getName()));
});
});
pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis"));
pushEntries.addActionListener(e -> pushEntries(true, true, false));
pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation"));
pushEntriesInt.addActionListener(e -> pushEntries(false, true, false));
pushEntriesEmpty.setToolTipText(Localization.lang("Insert a citation without text (the entry will appear in the reference list)"));
pushEntriesEmpty.addActionListener(e -> pushEntries(false, false, false));
pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information"));
pushEntriesAdvanced.addActionListener(e -> pushEntries(false, true, true));
update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date"));
Action updateAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (style == null) {
style = loader.getUsedStyle();
} else {
style.ensureUpToDate();
}
ooBase.updateSortedReferenceMarks();
List<BibDatabase> databases = getBaseList();
List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style);
ooBase.rebuildBibTextSection(databases, style);
if (!unresolvedKeys.isEmpty()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
}
} catch (UndefinedCharacterFormatException ex) {
reportUndefinedCharacterFormat(ex);
} catch (UndefinedParagraphFormatException ex) {
reportUndefinedParagraphFormat(ex);
} catch (ConnectionLostException ex) {
showConnectionLostErrorMessage();
} catch (IOException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
LOGGER.warn("Problem with style file", ex);
} catch (BibEntryNotFoundException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
LOGGER.debug("BibEntry not found", ex);
} catch (com.sun.star.lang.IllegalArgumentException | PropertyVetoException | UnknownPropertyException | WrappedTargetException | NoSuchElementException | CreationException ex) {
LOGGER.warn("Could not update bibliography", ex);
}
}
};
update.addActionListener(updateAction);
merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only"));
merge.addActionListener(e -> {
try {
ooBase.combineCiteMarkers(getBaseList(), style);
} catch (UndefinedCharacterFormatException ex) {
reportUndefinedCharacterFormat(ex);
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException ex) {
LOGGER.warn("Problem combining cite markers", ex);
}
});
settingsB.addActionListener(e -> showSettingsPopup());
manageCitations.addActionListener(e -> {
try {
CitationManager cm = new CitationManager(frame, ooBase);
cm.showDialog();
} catch (NoSuchElementException | WrappedTargetException | UnknownPropertyException ex) {
LOGGER.warn("Problem showing citation manager", ex);
}
});
exportCitations.addActionListener(event -> exportEntries());
selectDocument.setEnabled(false);
pushEntries.setEnabled(false);
pushEntriesInt.setEnabled(false);
pushEntriesEmpty.setEnabled(false);
pushEntriesAdvanced.setEnabled(false);
update.setEnabled(false);
merge.setEnabled(false);
manageCitations.setEnabled(false);
exportCitations.setEnabled(false);
diag = new JDialog((JFrame) null, "OpenOffice/LibreOffice panel", false);
FormBuilder mainBuilder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "p,p,p,p,p,p,p,p,p,p,p"));
FormBuilder topRowBuilder = FormBuilder.create().layout(new FormLayout("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref", "pref"));
topRowBuilder.add(connect).xy(1, 1);
topRowBuilder.add(manualConnect).xy(3, 1);
topRowBuilder.add(selectDocument).xy(5, 1);
topRowBuilder.add(update).xy(7, 1);
topRowBuilder.add(help).xy(9, 1);
mainBuilder.add(topRowBuilder.getPanel()).xy(1, 1);
mainBuilder.add(setStyleFile).xy(1, 2);
mainBuilder.add(pushEntries).xy(1, 3);
mainBuilder.add(pushEntriesInt).xy(1, 4);
mainBuilder.add(pushEntriesAdvanced).xy(1, 5);
mainBuilder.add(pushEntriesEmpty).xy(1, 6);
mainBuilder.add(merge).xy(1, 7);
mainBuilder.add(manageCitations).xy(1, 8);
mainBuilder.add(exportCitations).xy(1, 9);
mainBuilder.add(settingsB).xy(1, 10);
JPanel content = new JPanel();
sidePane.setContentContainer(content);
content.setLayout(new BorderLayout());
content.add(mainBuilder.getPanel(), BorderLayout.CENTER);
frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO");
frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction);
}
use of com.sun.star.beans.PropertyVetoException in project jabref by JabRef.
the class OOBibBase method combineCiteMarkers.
public void combineCiteMarkers(List<BibDatabase> databases, OOBibStyle style) throws IOException, WrappedTargetException, NoSuchElementException, IllegalArgumentException, UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, CreationException, BibEntryNotFoundException {
XNameAccess nameAccess = getReferenceMarks();
// TODO: doesn't work for citations in footnotes/tables
List<String> names = getSortedReferenceMarks(nameAccess);
final XTextRangeCompare compare = UnoRuntime.queryInterface(XTextRangeCompare.class, text);
int piv = 0;
boolean madeModifications = false;
while (piv < (names.size() - 1)) {
XTextRange range1 = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(names.get(piv))).getAnchor().getEnd();
XTextRange range2 = UnoRuntime.queryInterface(XTextContent.class, nameAccess.getByName(names.get(piv + 1))).getAnchor().getStart();
if (range1.getText() != range2.getText()) {
piv++;
continue;
}
XTextCursor mxDocCursor = range1.getText().createTextCursorByRange(range1);
mxDocCursor.goRight((short) 1, true);
boolean couldExpand = true;
while (couldExpand && (compare.compareRegionEnds(mxDocCursor, range2) > 0)) {
couldExpand = mxDocCursor.goRight((short) 1, true);
}
String cursorText = mxDocCursor.getString();
// Check if the string contains no line breaks and only whitespace:
if ((cursorText.indexOf('\n') == -1) && cursorText.trim().isEmpty()) {
// marks are removed, preventing damage to the user's document:
if (style.isFormatCitations()) {
XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, mxDocCursor);
String charStyle = style.getCitationCharacterFormat();
try {
xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
} catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | WrappedTargetException ex) {
// will result in an error message for the user:
throw new UndefinedCharacterFormatException(charStyle);
}
}
List<String> keys = parseRefMarkName(names.get(piv));
keys.addAll(parseRefMarkName(names.get(piv + 1)));
removeReferenceMark(names.get(piv));
removeReferenceMark(names.get(piv + 1));
List<BibEntry> entries = new ArrayList<>();
for (String key : keys) {
for (BibDatabase database : databases) {
Optional<BibEntry> entry = database.getEntryByKey(key);
if (entry.isPresent()) {
entries.add(entry.get());
break;
}
}
}
Collections.sort(entries, new FieldComparator(FieldName.YEAR));
String keyString = String.join(",", entries.stream().map(entry -> entry.getCiteKeyOptional().orElse("")).collect(Collectors.toList()));
// Insert bookmark:
String bName = getUniqueReferenceMarkName(keyString, OOBibBase.AUTHORYEAR_PAR);
insertReferenceMark(bName, "tmp", mxDocCursor, true, style);
names.set(piv + 1, bName);
madeModifications = true;
}
piv++;
}
if (madeModifications) {
updateSortedReferenceMarks();
refreshCiteMarkers(databases, style);
}
}
Aggregations