diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index 0d6bc1fecd0..f3edaba275a 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -112,6 +112,7 @@ public Optional showChoiceDialogAndWait(String title, String content, Str ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE); choiceDialog.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, okButtonType); choiceDialog.setHeaderText(title); + choiceDialog.setTitle(title); choiceDialog.setContentText(content); return choiceDialog.showAndWait(); diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index e8d410de343..d18d3f0b34b 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -1,6 +1,5 @@ package org.jabref.gui.help; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.util.HashSet; import java.util.Set; @@ -9,7 +8,6 @@ import javax.swing.Action; import javax.swing.Icon; -import javax.swing.JButton; import javax.swing.KeyStroke; import org.jabref.Globals; @@ -60,14 +58,6 @@ public HelpAction(HelpFile helpPage) { this(Localization.lang("Help"), Localization.lang("Help"), helpPage, IconTheme.JabRefIcons.HELP.getSmallIcon()); } - public JButton getHelpButton() { - JButton button = new JButton(this); - button.setText(null); - button.setPreferredSize(new Dimension(24, 24)); - button.setToolTipText(getValue(Action.SHORT_DESCRIPTION).toString()); - return button; - } - public static void openHelpPage(HelpFile helpPage) { String lang = Globals.prefs.get(JabRefPreferences.LANGUAGE); StringBuilder sb = new StringBuilder("https://help.jabref.org/"); diff --git a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java index 39f99b03e9c..26cf2ee6b40 100644 --- a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java @@ -26,11 +26,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.ListSelectionModel; - +import org.jabref.gui.DialogService; import org.jabref.logic.bibtex.comparator.FieldComparator; import org.jabref.logic.bibtex.comparator.FieldComparatorStack; import org.jabref.logic.l10n.Localization; @@ -130,14 +126,15 @@ class OOBibBase { private final List> authorYearTitleList = new ArrayList<>(3); private final List> yearAuthorTitleList = new ArrayList<>(3); - private final Map uniquefiers = new HashMap<>(); - private List sortedReferenceMarks; - public OOBibBase(String pathToOO, boolean atEnd) throws IOException, IllegalAccessException, - InvocationTargetException, BootstrapException, CreationException, UnknownPropertyException, - WrappedTargetException, IndexOutOfBoundsException, NoSuchElementException, NoDocumentException { + private final DialogService dialogService; + + public OOBibBase(String pathToOO, boolean atEnd, DialogService dialogService) throws IllegalAccessException, InvocationTargetException, BootstrapException, CreationException, IOException { + + this.dialogService = dialogService; + authorYearTitleList.add(authComp); authorYearTitleList.add(yearComp); authorYearTitleList.add(titleComp); @@ -151,40 +148,30 @@ public OOBibBase(String pathToOO, boolean atEnd) throws IOException, IllegalAcce this.atEnd = atEnd; xDesktop = simpleBootstrap(pathToOO); - selectDocument(); + } public boolean isConnectedToDocument() { return xCurrentComponent != null; } - public static XTextDocument selectComponent(List 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 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; - } + public XTextDocument selectComponent(List list) { + List viewModel = list.stream().map(DocumentTitleViewModel::new).collect(Collectors.toList()); + //this whole method is part of a background task when autodecting instances, so we need to show dialog in FX thread + Optional selectedDocument = dialogService.showChoiceDialogAndWait(Localization.lang("Select document"), Localization.lang("Found documents:"), Localization.lang("Use selected document"), viewModel); + return selectedDocument.map(DocumentTitleViewModel::getXtextDocument).orElse(null); } public Optional getCurrentDocumentTitle() { - if (mxDoc == null) { + return getDocumentTitle(mxDoc); + } + + private Optional getDocumentTitle(XTextDocument doc) { + if (doc == null) { return Optional.empty(); } else { try { - return Optional - .of(String.valueOf(OOUtil.getProperty(mxDoc.getCurrentController().getFrame(), "Title"))); + return Optional.of(String.valueOf(OOUtil.getProperty(doc.getCurrentController().getFrame(), "Title"))); } catch (UnknownPropertyException | WrappedTargetException e) { LOGGER.warn("Could not get document title", e); return Optional.empty(); @@ -192,8 +179,7 @@ public Optional getCurrentDocumentTitle() { } } - public void selectDocument() throws UnknownPropertyException, WrappedTargetException, IndexOutOfBoundsException, - NoSuchElementException, NoDocumentException { + public void selectDocument() throws NoDocumentException, NoSuchElementException, WrappedTargetException { List textDocumentList = getTextDocuments(); XTextDocument selected; if (textDocumentList.isEmpty()) { @@ -250,8 +236,8 @@ private List getTextDocuments() throws NoSuchElementException, Wr } private XDesktop simpleBootstrap(String pathToExecutable) - throws IllegalAccessException, InvocationTargetException, BootstrapException, - CreationException, IOException { + throws IllegalAccessException, InvocationTargetException, BootstrapException, + CreationException, IOException { ClassLoader loader = ClassLoader.getSystemClassLoader(); if (loader instanceof URLClassLoader) { @@ -268,7 +254,7 @@ private XDesktop simpleBootstrap(String pathToExecutable) } } else { LOGGER.error("Error occured, URLClassLoader expected but " + loader.getClass() - + " received. Could not continue."); + + " received. Could not continue."); } //Get the office component context: @@ -302,13 +288,13 @@ public void updateSortedReferenceMarks() throws WrappedTargetException, NoSuchEl } public void setCustomProperty(String property, String value) throws UnknownPropertyException, - NotRemoveableException, PropertyExistException, IllegalTypeException, IllegalArgumentException { + NotRemoveableException, PropertyExistException, IllegalTypeException, IllegalArgumentException { if (propertySet.getPropertySetInfo().hasPropertyByName(property)) { userProperties.removeProperty(property); } if (value != null) { userProperties.addProperty(property, com.sun.star.beans.PropertyAttribute.REMOVEABLE, - new Any(Type.STRING, value)); + new Any(Type.STRING, value)); } } @@ -339,10 +325,10 @@ public void setCustomProperty(String property, String value) throws UnknownPrope public void insertEntry(List entries, BibDatabase database, List allBases, OOBibStyle style, boolean inParenthesis, boolean withText, String pageInfo, boolean sync) - throws IllegalArgumentException, - UnknownPropertyException, NotRemoveableException, PropertyExistException, IllegalTypeException, - UndefinedCharacterFormatException, WrappedTargetException, NoSuchElementException, PropertyVetoException, - IOException, CreationException, BibEntryNotFoundException, UndefinedParagraphFormatException { + throws IllegalArgumentException, + UnknownPropertyException, NotRemoveableException, PropertyExistException, IllegalTypeException, + UndefinedCharacterFormatException, WrappedTargetException, NoSuchElementException, PropertyVetoException, + IOException, CreationException, BibEntryNotFoundException, UndefinedParagraphFormatException { try { @@ -357,10 +343,10 @@ public void insertEntry(List entries, BibDatabase database, } String keyString = String.join(",", - entries.stream().map(entry -> entry.getCiteKeyOptional().orElse("")).collect(Collectors.toList())); + entries.stream().map(entry -> entry.getCiteKeyOptional().orElse("")).collect(Collectors.toList())); // Insert bookmark: String bName = getUniqueReferenceMarkName(keyString, - withText ? inParenthesis ? OOBibBase.AUTHORYEAR_PAR : OOBibBase.AUTHORYEAR_INTEXT : OOBibBase.INVISIBLE_CIT); + withText ? inParenthesis ? OOBibBase.AUTHORYEAR_PAR : OOBibBase.AUTHORYEAR_INTEXT : OOBibBase.INVISIBLE_CIT); // If we should store metadata for page info, do that now: if (pageInfo != null) { @@ -375,7 +361,7 @@ public void insertEntry(List entries, BibDatabase database, try { xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle); } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | - WrappedTargetException ex) { + WrappedTargetException ex) { // Setting the character format failed, so we throw an exception that // will result in an error message for the user. Before that, // delete the space we inserted: @@ -390,7 +376,7 @@ public void insertEntry(List entries, BibDatabase database, databaseMap.put(entry, database); } String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, databaseMap, - inParenthesis, null, null); + inParenthesis, null, null); insertReferenceMark(bName, citeText, xViewCursor, withText, style); xViewCursor.collapseToEnd(); @@ -447,9 +433,9 @@ public List getJabRefReferenceMarks(XNameAccess nameAccess) { * @throws UnknownPropertyException */ public List refreshCiteMarkers(List databases, OOBibStyle style) - throws WrappedTargetException, IllegalArgumentException, NoSuchElementException, - UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, IOException, - CreationException, BibEntryNotFoundException { + throws WrappedTargetException, IllegalArgumentException, NoSuchElementException, + UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, IOException, + CreationException, BibEntryNotFoundException { try { return refreshCiteMarkersInternal(databases, style); } catch (DisposedException ex) { @@ -461,9 +447,9 @@ public List refreshCiteMarkers(List databases, OOBibStyle s } private List refreshCiteMarkersInternal(List databases, OOBibStyle style) - throws WrappedTargetException, IllegalArgumentException, NoSuchElementException, - UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, - CreationException, BibEntryNotFoundException { + throws WrappedTargetException, IllegalArgumentException, NoSuchElementException, + UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, + CreationException, BibEntryNotFoundException { List cited = findCitedKeys(); Map linkSourceBase = new HashMap<>(); @@ -570,7 +556,7 @@ private List refreshCiteMarkersInternal(List databases, OOB citationMarker = style.getNumCitationMarker(num, minGroupingCount, false); for (int j = 0; j < keys.length; j++) { normCitMarker[j] = style.getNumCitationMarker(Collections.singletonList(num.get(j)), - minGroupingCount, false); + minGroupingCount, false); } } else { // We need to find the number of the cited entry in the bibliography, @@ -579,7 +565,7 @@ private List refreshCiteMarkersInternal(List databases, OOB if (num.isEmpty()) { throw new BibEntryNotFoundException(names.get(i), Localization - .lang("Could not resolve BibTeX entry for citation marker '%0'.", names.get(i))); + .lang("Could not resolve BibTeX entry for citation marker '%0'.", names.get(i))); } else { citationMarker = style.getNumCitationMarker(num, minGroupingCount, false); } @@ -605,11 +591,11 @@ private List refreshCiteMarkersInternal(List databases, OOB } citationMarker = style.getCitationMarker(Arrays.asList(cEntries), entries, - type == OOBibBase.AUTHORYEAR_PAR, null, null); + type == OOBibBase.AUTHORYEAR_PAR, null, null); // We need "normalized" (in parenthesis) markers for uniqueness checking purposes: for (int j = 0; j < cEntries.length; j++) { normCitMarker[j] = style.getCitationMarker(Collections.singletonList(cEntries[j]), entries, - true, null, new int[]{-1}); + true, null, new int[] {-1}); } } citMarkers[i] = citationMarker; @@ -709,7 +695,7 @@ private List refreshCiteMarkersInternal(List databases, OOB } if (needsChange) { citMarkers[j] = style.getCitationMarker(Arrays.asList(cEntries), entries, - types[j] == OOBibBase.AUTHORYEAR_PAR, uniquif, firstLimAuthors); + types[j] == OOBibBase.AUTHORYEAR_PAR, uniquif, firstLimAuthors); } } } @@ -735,7 +721,7 @@ private List refreshCiteMarkersInternal(List databases, OOB try { xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle); } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | - WrappedTargetException ex) { + WrappedTargetException ex) { throw new UndefinedCharacterFormatException(charStyle); } } @@ -765,9 +751,9 @@ private List refreshCiteMarkersInternal(List databases, OOB } private List getSortedReferenceMarks(final XNameAccess nameAccess) - throws WrappedTargetException, NoSuchElementException { + throws WrappedTargetException, NoSuchElementException { XTextViewCursorSupplier cursorSupplier = UnoRuntime.queryInterface(XTextViewCursorSupplier.class, - mxDoc.getCurrentController()); + mxDoc.getCurrentController()); XTextViewCursor viewCursor = cursorSupplier.getViewCursor(); XTextRange initialPos = viewCursor.getStart(); @@ -817,8 +803,8 @@ private String getUniqueReferenceMarkName(String bibtexKey, int type) { } public void rebuildBibTextSection(List databases, OOBibStyle style) - throws NoSuchElementException, WrappedTargetException, IllegalArgumentException, - CreationException, PropertyVetoException, UnknownPropertyException, UndefinedParagraphFormatException { + throws NoSuchElementException, WrappedTargetException, IllegalArgumentException, + CreationException, PropertyVetoException, UnknownPropertyException, UndefinedParagraphFormatException { List cited = findCitedKeys(); Map linkSourceBase = new HashMap<>(); Map entries = findCitedEntries(databases, cited, linkSourceBase); // Although entries are redefined without use, this also updates linkSourceBase @@ -831,7 +817,7 @@ public void rebuildBibTextSection(List databases, OOBibStyle style) } else { SortedMap newMap = new TreeMap<>(entryComparator); for (Map.Entry bibtexEntryBibtexDatabaseEntry : findCitedEntries(databases, cited, - linkSourceBase).entrySet()) { + linkSourceBase).entrySet()) { newMap.put(bibtexEntryBibtexDatabaseEntry.getKey(), bibtexEntryBibtexDatabaseEntry.getValue()); } entries = newMap; @@ -961,7 +947,7 @@ private Map getSortedEntriesFromSortedRefMarks(List entries, OOBibStyle style, String parFormat) - throws UndefinedParagraphFormatException, IllegalArgumentException, - UnknownPropertyException, PropertyVetoException, WrappedTargetException { + throws UndefinedParagraphFormatException, IllegalArgumentException, + UnknownPropertyException, PropertyVetoException, WrappedTargetException { Map correctEntries; // If we don't have numbered entries, we need to sort the entries before adding them: if (style.isSortByPosition()) { @@ -1026,18 +1012,18 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map entries, OOBibStyle style) - throws NoSuchElementException, WrappedTargetException, PropertyVetoException, - UnknownPropertyException, UndefinedParagraphFormatException, IllegalArgumentException, CreationException { + throws NoSuchElementException, WrappedTargetException, PropertyVetoException, + UnknownPropertyException, UndefinedParagraphFormatException, IllegalArgumentException, CreationException { XTextSectionsSupplier supplier = UnoRuntime.queryInterface(XTextSectionsSupplier.class, mxDoc); XTextSection section = (XTextSection) ((Any) supplier.getTextSections().getByName(OOBibBase.BIB_SECTION_NAME)) - .getObject(); + .getObject(); XTextCursor cursor = text.createTextCursorByRange(section.getAnchor()); OOUtil.insertTextAtCurrentLocation(text, cursor, (String) style.getProperty(OOBibStyle.TITLE), - (String) style.getProperty(OOBibStyle.REFERENCE_HEADER_PARAGRAPH_FORMAT)); + (String) style.getProperty(OOBibStyle.REFERENCE_HEADER_PARAGRAPH_FORMAT)); insertFullReferenceAtCursor(cursor, entries, style, - (String) style.getProperty(OOBibStyle.REFERENCE_PARAGRAPH_FORMAT)); + (String) style.getProperty(OOBibStyle.REFERENCE_PARAGRAPH_FORMAT)); insertBookMark(OOBibBase.BIB_SECTION_END_NAME, cursor); } private XTextContent insertBookMark(String name, XTextCursor position) - throws IllegalArgumentException, CreationException { + throws IllegalArgumentException, CreationException { Object bookmark; try { bookmark = mxDocFactory.createInstance("com.sun.star.text.Bookmark"); @@ -1113,8 +1099,8 @@ private XTextContent insertBookMark(String name, XTextCursor position) private void insertReferenceMark(String name, String citationText, XTextCursor position, boolean withText, OOBibStyle style) - throws UnknownPropertyException, WrappedTargetException, - PropertyVetoException, IllegalArgumentException, UndefinedCharacterFormatException, CreationException { + throws UnknownPropertyException, WrappedTargetException, + PropertyVetoException, IllegalArgumentException, UndefinedCharacterFormatException, CreationException { // Check if there is "page info" stored for this citation. If so, insert it into // the citation text before inserting the citation: @@ -1147,7 +1133,7 @@ private void insertReferenceMark(String name, String citationText, XTextCursor p try { xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle); } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | - WrappedTargetException ex) { + WrappedTargetException ex) { throw new UndefinedCharacterFormatException(charStyle); } } @@ -1210,7 +1196,7 @@ private XNameAccess getBookmarks() { } private void italicizeOrBold(XTextCursor position, boolean italicize, int start, int end) - throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException { + throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException { XTextRange range = position.getStart(); XTextCursor cursor = position.getText().createTextCursorByRange(range); cursor.goRight((short) start, false); @@ -1224,9 +1210,9 @@ private void italicizeOrBold(XTextCursor position, boolean italicize, int start, } public void combineCiteMarkers(List databases, OOBibStyle style) - throws IOException, WrappedTargetException, NoSuchElementException, IllegalArgumentException, - UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, CreationException, - BibEntryNotFoundException { + throws IOException, WrappedTargetException, NoSuchElementException, IllegalArgumentException, + UndefinedCharacterFormatException, UnknownPropertyException, PropertyVetoException, CreationException, + BibEntryNotFoundException { XNameAccess nameAccess = getReferenceMarks(); // TODO: doesn't work for citations in footnotes/tables List names = getSortedReferenceMarks(nameAccess); @@ -1263,7 +1249,7 @@ public void combineCiteMarkers(List databases, OOBibStyle style) try { xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle); } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | - WrappedTargetException ex) { + WrappedTargetException ex) { // Setting the character format failed, so we throw an exception that // will result in an error message for the user: throw new UndefinedCharacterFormatException(charStyle); @@ -1303,7 +1289,7 @@ public void combineCiteMarkers(List databases, OOBibStyle style) } public BibDatabase generateDatabase(List databases) - throws NoSuchElementException, WrappedTargetException { + throws NoSuchElementException, WrappedTargetException { BibDatabase resultDatabase = new BibDatabase(); List cited = findCitedKeys(); @@ -1363,7 +1349,7 @@ public boolean equals(Object o) { if (o instanceof ComparableMark) { ComparableMark other = (ComparableMark) o; return (this.position.X == other.position.X) && (this.position.Y == other.position.Y) - && Objects.equals(this.name, other.name); + && Objects.equals(this.name, other.name); } return false; } @@ -1376,7 +1362,25 @@ public String getName() { public int hashCode() { return Objects.hash(position, name); } - } + private class DocumentTitleViewModel { + + private final XTextDocument xTextDocument; + private final String description; + + public DocumentTitleViewModel(XTextDocument xTextDocument) { + this.xTextDocument = xTextDocument; + this.description = getDocumentTitle(xTextDocument).orElse(""); + } + + public XTextDocument getXtextDocument() { + return xTextDocument; + } + + @Override + public String toString() { + return description; + } + } } diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 9f31cc17a8b..7d2c1c20e70 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -133,8 +133,8 @@ public OpenOfficePanel(JabRefFrame frame, JabRefPreferences jabRefPreferences, O update.setMaxWidth(Double.MAX_VALUE); loader = new StyleLoader(ooPrefs, - Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), - Globals.prefs.getDefaultEncoding()); + Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), + Globals.prefs.getDefaultEncoding()); initPanel(); } @@ -149,7 +149,7 @@ private static void addURL(List jarList) throws IOException { method.invoke(sysloader, anU); } } catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | - InvocationTargetException e) { + InvocationTargetException e) { LOGGER.error("Could not add URL to system classloader", e); sysloader.close(); throw new IOException("Error, could not add URL to system classloader", e); @@ -171,9 +171,9 @@ private void initPanel() { try { ooBase.selectDocument(); dialogService.notify(Localization.lang("Connected to document") + ": " - + ooBase.getCurrentDocumentTitle().orElse("")); - } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException | - NoSuchElementException | NoDocumentException ex) { + + ooBase.getCurrentDocumentTitle().orElse("")); + } catch (WrappedTargetException | IndexOutOfBoundsException | + NoSuchElementException | NoDocumentException ex) { LOGGER.warn("Problem connecting", ex); dialogService.showErrorDialogAndWait(ex); } @@ -226,8 +226,8 @@ private void initPanel() { ooBase.rebuildBibTextSection(databases, style); if (!unresolvedKeys.isEmpty()) { dialogService.showErrorDialogAndWait(Localization.lang("Unable to synchronize bibliography"), - 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("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", + unresolvedKeys.get(0))); } } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); @@ -238,14 +238,14 @@ private void initPanel() { } catch (IOException ex) { LOGGER.warn("Problem with style file", ex); dialogService.showErrorDialogAndWait(Localization.lang("No valid style file defined"), - Localization.lang("You must select either a valid style file, or use one of the default styles.")); + Localization.lang("You must select either a valid style file, or use one of the default styles.")); } catch (BibEntryNotFoundException ex) { LOGGER.debug("BibEntry not found", ex); dialogService.showErrorDialogAndWait(Localization.lang("Unable to synchronize bibliography"), Localization.lang( - "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", - ex.getBibtexKey())); + "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", + ex.getBibtexKey())); } catch (com.sun.star.lang.IllegalArgumentException | PropertyVetoException | UnknownPropertyException | WrappedTargetException | NoSuchElementException | - CreationException ex) { + CreationException ex) { LOGGER.warn("Could not update bibliography", ex); } }); @@ -258,8 +258,8 @@ private void initPanel() { } catch (UndefinedCharacterFormatException ex) { reportUndefinedCharacterFormat(ex); } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | - CreationException | NoSuchElementException | WrappedTargetException | IOException | - BibEntryNotFoundException ex) { + CreationException | NoSuchElementException | WrappedTargetException | IOException | + BibEntryNotFoundException ex) { LOGGER.warn("Problem combining cite markers", ex); } @@ -311,8 +311,8 @@ private void exportEntries() { if (!unresolvedKeys.isEmpty()) { dialogService.showErrorDialogAndWait(Localization.lang("Unable to generate new library"), - 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("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", + unresolvedKeys.get(0))); } @@ -323,12 +323,12 @@ private void exportEntries() { } catch (BibEntryNotFoundException ex) { LOGGER.debug("BibEntry not found", ex); dialogService.showErrorDialogAndWait(Localization.lang("Unable to synchronize bibliography"), - Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", - ex.getBibtexKey())); + Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", + ex.getBibtexKey())); } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | - UndefinedCharacterFormatException | NoSuchElementException | WrappedTargetException | IOException | - CreationException e) { + UndefinedCharacterFormatException | NoSuchElementException | WrappedTargetException | IOException | + CreationException e) { LOGGER.warn("Problem generating new database.", e); } @@ -397,6 +397,12 @@ protected OOBibBase call() throws Exception { connectTask.setOnSucceeded(value -> { ooBase = connectTask.getValue(); + try { + ooBase.selectDocument(); + } catch (WrappedTargetException | NoSuchElementException | NoDocumentException e) { + LOGGER.error("Error getting open writer documents", e); + } + if (ooBase.isConnectedToDocument()) { dialogService.notify(Localization.lang("Connected to document") + ": " + ooBase.getCurrentDocumentTitle().orElse("")); } @@ -418,16 +424,16 @@ protected OOBibBase call() throws Exception { LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); dialogService.showErrorDialogAndWait(Localization.lang("Unable to connect. One possible reason is that JabRef " - + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); + + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); } else if (ex instanceof IOException) { LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); dialogService.showErrorDialogAndWait(Localization.lang("Could not connect to running OpenOffice/LibreOffice."), - Localization.lang("Could not connect to running OpenOffice/LibreOffice.") - + "\n" - + Localization.lang("Make sure you have installed OpenOffice/LibreOffice with Java support.") + "\n" - + Localization.lang("If connecting manually, please verify program and library paths.") + "\n" + "\n" + Localization.lang("Error message:"), - ex); + Localization.lang("Could not connect to running OpenOffice/LibreOffice.") + + "\n" + + Localization.lang("Make sure you have installed OpenOffice/LibreOffice with Java support.") + "\n" + + Localization.lang("If connecting manually, please verify program and library paths.") + "\n" + "\n" + Localization.lang("Error message:"), + ex); } else { dialogService.showErrorDialogAndWait(Localization.lang("Autodetection failed"), Localization.lang("Autodetection failed"), ex); } @@ -453,10 +459,9 @@ private void loadOpenOfficeJars(Path configurationPath) throws IOException { } private OOBibBase createBibBase() throws IOException, InvocationTargetException, IllegalAccessException, - WrappedTargetException, BootstrapException, UnknownPropertyException, NoDocumentException, - NoSuchElementException, CreationException { + BootstrapException, CreationException { // Connect - return new OOBibBase(ooPrefs.getExecutablePath(), true); + return new OOBibBase(ooPrefs.getExecutablePath(), true, dialogService); } private Optional showManualConnectionDialog() { @@ -497,12 +502,12 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP style = loader.getUsedStyle(); } ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, - ooPrefs.getSyncWhenCiting()); + ooPrefs.getSyncWhenCiting()); } catch (FileNotFoundException ex) { dialogService.showErrorDialogAndWait( - Localization.lang("No valid style file defined"), - Localization.lang("You must select either a valid style file, or use one of the default styles.")); + Localization.lang("No valid style file defined"), + Localization.lang("You must select either a valid style file, or use one of the default styles.")); LOGGER.warn("Problem with style file", ex); } catch (ConnectionLostException ex) { @@ -512,9 +517,9 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP } catch (UndefinedParagraphFormatException ex) { reportUndefinedParagraphFormat(ex); } catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | - CreationException | NoSuchElementException | WrappedTargetException | IOException | - BibEntryNotFoundException | IllegalTypeException | PropertyExistException | - NotRemoveableException ex) { + CreationException | NoSuchElementException | WrappedTargetException | IOException | + BibEntryNotFoundException | IllegalTypeException | PropertyExistException | + NotRemoveableException ex) { LOGGER.warn("Could not insert entry", ex); } } @@ -547,9 +552,9 @@ private boolean checkThatEntriesHaveKeys(List entries) { // Ask if keys should be generated boolean citePressed = dialogService.showConfirmationDialogAndWait(Localization.lang("Cite"), - Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), - Localization.lang("Generate keys"), - Localization.lang("Cancel")); + Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), + Localization.lang("Generate keys"), + Localization.lang("Cancel")); BasePanel panel = frame.getCurrentBasePanel(); if (citePressed && (panel != null)) { @@ -560,8 +565,8 @@ private boolean checkThatEntriesHaveKeys(List entries) { if (!entry.getCiteKeyOptional().isPresent()) { // Generate key new BibtexKeyGenerator(panel.getBibDatabaseContext(), prefs) - .generateAndSetKey(entry) - .ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); + .generateAndSetKey(entry) + .ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); } } undoCompound.end(); @@ -577,23 +582,23 @@ private boolean checkThatEntriesHaveKeys(List entries) { private void showConnectionLostErrorMessage() { dialogService.showErrorDialogAndWait(Localization.lang("Connection lost"), - Localization.lang("Connection to OpenOffice/LibreOffice has been lost. " + "Please make sure OpenOffice/LibreOffice is running, and try to reconnect.")); + Localization.lang("Connection to OpenOffice/LibreOffice has been lost. " + "Please make sure OpenOffice/LibreOffice is running, and try to reconnect.")); } private void reportUndefinedParagraphFormat(UndefinedParagraphFormatException ex) { dialogService.showErrorDialogAndWait(Localization.lang("Undefined paragraph format"), - Localization.lang("Your style file specifies the paragraph format '%0', " - + "which is undefined in your current OpenOffice/LibreOffice document.", - ex.getFormatName()) + "\n" + Localization.lang("The paragraph format is controlled by the property 'ReferenceParagraphFormat' or 'ReferenceHeaderParagraphFormat' in the style file.")); + Localization.lang("Your style file specifies the paragraph format '%0', " + + "which is undefined in your current OpenOffice/LibreOffice document.", + ex.getFormatName()) + "\n" + Localization.lang("The paragraph format is controlled by the property 'ReferenceParagraphFormat' or 'ReferenceHeaderParagraphFormat' in the style file.")); } private void reportUndefinedCharacterFormat(UndefinedCharacterFormatException ex) { dialogService.showErrorDialogAndWait(Localization.lang("Undefined character format"), - Localization.lang("Your style file specifies the character format '%0', " - + "which is undefined in your current OpenOffice/LibreOffice document.", - ex.getFormatName()) + "\n" + Localization.lang("The character format is controlled by the citation property 'CitationCharacterFormat' in the style file.") + Localization.lang("Your style file specifies the character format '%0', " + + "which is undefined in your current OpenOffice/LibreOffice document.", + ex.getFormatName()) + "\n" + Localization.lang("The character format is controlled by the citation property 'CitationCharacterFormat' in the style file.") ); } diff --git a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java index 917b88b3ea4..1ad4e79b854 100644 --- a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java @@ -63,6 +63,7 @@ public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs) container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF, lightTheme, darkTheme); } + @Override public Node getBuilder() { return container; } diff --git a/src/main/java/org/jabref/gui/preferences/BibtexKeyPatternPrefTab.java b/src/main/java/org/jabref/gui/preferences/BibtexKeyPatternPrefTab.java index 8240accc730..2cf6495d54d 100644 --- a/src/main/java/org/jabref/gui/preferences/BibtexKeyPatternPrefTab.java +++ b/src/main/java/org/jabref/gui/preferences/BibtexKeyPatternPrefTab.java @@ -48,7 +48,6 @@ public BibtexKeyPatternPrefTab(JabRefPreferences prefs, BasePanel panel) { */ @Override public void storeSettings() { - // Set the default value: Globals.prefs.put(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, defaultPat.getText()); Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, warnBeforeOverwriting.isSelected()); @@ -98,6 +97,7 @@ private void appendKeyGeneratorSettings() { warnBeforeOverwriting.setDisable(dontOverwrite.isSelected())); } + @Override public Node getBuilder() { return builder; } diff --git a/src/main/java/org/jabref/gui/preferences/FileTab.java b/src/main/java/org/jabref/gui/preferences/FileTab.java index 3bbc387f130..4067cf08751 100644 --- a/src/main/java/org/jabref/gui/preferences/FileTab.java +++ b/src/main/java/org/jabref/gui/preferences/FileTab.java @@ -17,6 +17,8 @@ import javafx.scene.layout.Pane; import org.jabref.gui.DialogService; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.logic.help.HelpFile; @@ -52,22 +54,26 @@ class FileTab extends Pane implements PrefsTab { private final CheckBox allowFileAutoOpenBrowse; private final RadioButton useRegExpComboBox; private final RadioButton matchExactKeyOnly = new RadioButton( - Localization.lang("Autolink only files that match the BibTeX key")); + Localization.lang("Autolink only files that match the BibTeX key")); private final RadioButton matchStartsWithKey = new RadioButton( - Localization.lang("Autolink files with names starting with the BibTeX key")); + Localization.lang("Autolink files with names starting with the BibTeX key")); private final TextField regExpTextField; public FileTab(DialogService dialogService, JabRefPreferences prefs) { this.dialogService = dialogService; this.prefs = prefs; + + ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository()); + fileDir = new TextField(); + bibLocAsPrimaryDir = new CheckBox(Localization.lang("Use the BIB file location as primary file directory")); bibLocAsPrimaryDir.setAccessibleText(Localization.lang("When downloading files, or moving linked files to the " - + "file directory, prefer the BIB file location rather than the file directory set above")); + + "file directory, prefer the BIB file location rather than the file directory set above")); runAutoFileSearch = new CheckBox( - Localization.lang("When opening file link, search for matching file if no link is defined")); + Localization.lang("When opening file link, search for matching file if no link is defined")); allowFileAutoOpenBrowse = new CheckBox( - Localization.lang("Automatically open browse dialog when creating new file link")); + Localization.lang("Automatically open browse dialog when creating new file link")); regExpTextField = new TextField(); useRegExpComboBox = new RadioButton(Localization.lang("Use regular expression search")); useRegExpComboBox.setOnAction(e -> regExpTextField.setEditable(useRegExpComboBox.isSelected())); @@ -92,13 +98,13 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) { Label general = new Label(Localization.lang("General")); general.getStyleClass().add("sectionHeader"); builder.add(general, 1, 1); - builder.add(openLast, 1, 2); + builder.add(openLast, 1, 2); builder.add(backup, 1, 3); Label label = new Label(Localization.lang("Do not wrap the following fields when saving") + ":"); builder.add(label, 1, 4); final ToggleGroup resolveGroup = new ToggleGroup(); builder.add(nonWrappableFields, 2, 4); - builder.add(resolveStringsStandard, 1, 5); + builder.add(resolveStringsStandard, 1, 5); builder.add(resolveStringsAll, 1, 6); builder.add(doNotResolveStringsFor, 2, 6); resolveStringsStandard.setToggleGroup(resolveGroup); @@ -122,25 +128,23 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) { browse.setPrefSize(80, 20); browse.setOnAction(e -> { DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Paths.get(fileDir.getText())).build(); + .withInitialDirectory(Paths.get(fileDir.getText())).build(); dialogService.showDirectorySelectionDialog(dirDialogConfiguration) .ifPresent(f -> fileDir.setText(f.toString())); }); builder.add(browse, 3, 12); builder.add(bibLocAsPrimaryDir, 1, 13); final ToggleGroup autolinkGroup = new ToggleGroup(); - builder.add(matchStartsWithKey, 1, 14); - builder.add(matchExactKeyOnly, 1, 15); + builder.add(matchStartsWithKey, 1, 14); + builder.add(matchExactKeyOnly, 1, 15); builder.add(useRegExpComboBox, 1, 16); builder.add(regExpTextField, 2, 16); matchStartsWithKey.setToggleGroup(autolinkGroup); matchExactKeyOnly.setToggleGroup(autolinkGroup); useRegExpComboBox.setToggleGroup(autolinkGroup); - Button help = new Button("?"); - help.setOnAction(event -> new HelpAction(Localization.lang("Help on regular expression search"), - HelpFile.REGEX_SEARCH).getHelpButton().doClick()); - + Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on regular expression search"), + HelpFile.REGEX_SEARCH).getCommand()); builder.add(help, 3, 16); builder.add(runAutoFileSearch, 1, 17); builder.add(allowFileAutoOpenBrowse, 1, 18); @@ -151,10 +155,10 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) { Label autosave = new Label(Localization.lang("Autosave")); autosave.getStyleClass().add("sectionHeader"); builder.add(autosave, 1, 20); - builder.add(localAutoSave, 1, 21); - Button help1 = new Button("?"); - help1.setOnAction(event -> new HelpAction(HelpFile.AUTOSAVE).getHelpButton().doClick()); - builder.add(help1, 2, 21); + builder.add(localAutoSave, 1, 21); + + Button helpAutosave = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE).getCommand()); + builder.add(helpAutosave, 2, 21); } @Override @@ -194,6 +198,7 @@ public void setValues() { localAutoSave.setSelected(prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE)); } + @Override public Node getBuilder() { return builder; } @@ -247,8 +252,8 @@ public boolean validateSettings() { boolean valid = Files.exists(path) && Files.isDirectory(path); if (!valid) { dialogService.showErrorDialogAndWait( - String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"), - Localization.lang("Main file directory"), Localization.lang("Directory not found"), path)); + String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"), + Localization.lang("Main file directory"), Localization.lang("Directory not found"), path)); } return valid; } diff --git a/src/main/java/org/jabref/gui/preferences/GeneralTab.java b/src/main/java/org/jabref/gui/preferences/GeneralTab.java index d2c27c1a97c..c7f3759755d 100644 --- a/src/main/java/org/jabref/gui/preferences/GeneralTab.java +++ b/src/main/java/org/jabref/gui/preferences/GeneralTab.java @@ -15,6 +15,8 @@ import javafx.scene.shape.Line; import org.jabref.gui.DialogService; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelListCellFactory; @@ -55,6 +57,9 @@ class GeneralTab extends Pane implements PrefsTab { public GeneralTab(DialogService dialogService, JabRefPreferences prefs) { this.prefs = prefs; this.dialogService = dialogService; + + ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository()); + biblatexMode = new ComboBox<>(FXCollections.observableArrayList(BibDatabaseMode.values())); memoryStick = new CheckBox(Localization.lang("Load and Save preferences from/to jabref.xml on start-up (memory stick mode)")); useOwner = new CheckBox(Localization.lang("Mark new entries with owner name") + ':'); @@ -90,10 +95,8 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) { builder.add(defOwnerField, 2, 10); builder.add(overwriteOwner, 3, 10); - Button help = new Button("?"); - help.setPrefSize(10, 10); - help.setOnAction(event -> new HelpAction(HelpFile.OWNER).getHelpButton().doClick()); - builder.add(help, 4, 10); + Button helpOwner = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER).getCommand()); + builder.add(helpOwner, 4, 10); builder.add(useTimeStamp, 1, 13); builder.add(timeStampFormat, 2, 13); @@ -102,9 +105,8 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) { builder.add(fieldName, 3, 13); builder.add(timeStampField, 4, 13); - Button help1 = new Button("?"); - help1.setOnAction(event -> new HelpAction(HelpFile.TIMESTAMP).getHelpButton().doClick()); - builder.add(help1, 6, 13); + Button helpTimestamp = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.TIMESTAMP).getCommand()); + builder.add(helpTimestamp, 6, 13); builder.add(updateTimeStamp, 1, 14); builder.add(new Line(), 1, 15); diff --git a/src/main/java/org/jabref/gui/preferences/NameFormatterTab.java b/src/main/java/org/jabref/gui/preferences/NameFormatterTab.java index bac74718d33..da1f649fb2c 100644 --- a/src/main/java/org/jabref/gui/preferences/NameFormatterTab.java +++ b/src/main/java/org/jabref/gui/preferences/NameFormatterTab.java @@ -1,6 +1,7 @@ package org.jabref.gui.preferences; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -21,6 +22,8 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.help.HelpAction; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; @@ -31,24 +34,25 @@ public class NameFormatterTab extends Pane implements PrefsTab { private final JabRefPreferences prefs; private boolean tableChanged; - private final TableView table; + private final TableView table; private final GridPane builder = new GridPane(); - private final List tableRows = new ArrayList<>(10); - private final ObservableList data = FXCollections.observableArrayList(); + private final List tableRows = new ArrayList<>(10); + private final ObservableList data = FXCollections.observableArrayList(); - public static class TableRow { - private SimpleStringProperty name; - private SimpleStringProperty format; + public static class NameFormatterViewModel { - TableRow() { + private final SimpleStringProperty name; + private final SimpleStringProperty format; + + NameFormatterViewModel() { this(""); } - TableRow(String name) { + NameFormatterViewModel(String name) { this(name, NameFormatter.DEFAULT_FORMAT); } - TableRow(String name, String format) { + NameFormatterViewModel(String name, String format) { this.name = new SimpleStringProperty(name); this.format = new SimpleStringProperty(format); } @@ -77,28 +81,32 @@ public void setFormat(String format) { public NameFormatterTab(JabRefPreferences prefs) { this.prefs = Objects.requireNonNull(prefs); - TableColumn firstCol = new TableColumn<>(Localization.lang("Formatter name")); - TableColumn lastCol = new TableColumn<>(Localization.lang("Format string")); - table = new TableView(); + ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository()); + + TableColumn firstCol = new TableColumn<>(Localization.lang("Formatter name")); + TableColumn lastCol = new TableColumn<>(Localization.lang("Format string")); + table = new TableView<>(); table.setEditable(true); firstCol.setCellValueFactory(new PropertyValueFactory<>("name")); firstCol.setCellFactory(TextFieldTableCell.forTableColumn()); firstCol.setOnEditCommit( - (TableColumn.CellEditEvent t) -> { - t.getTableView().getItems().get( - t.getTablePosition().getRow()).setName(t.getNewValue()); - }); + (TableColumn.CellEditEvent t) -> { + t.getTableView().getItems().get( + t.getTablePosition().getRow()) + .setName(t.getNewValue()); + }); lastCol.setCellValueFactory(new PropertyValueFactory<>("format")); lastCol.setCellFactory(TextFieldTableCell.forTableColumn()); lastCol.setOnEditCommit( - (TableColumn.CellEditEvent t) -> { - t.getTableView().getItems().get( - t.getTablePosition().getRow()).setFormat(t.getNewValue()); - }); + (TableColumn.CellEditEvent t) -> { + t.getTableView().getItems().get( + t.getTablePosition().getRow()) + .setFormat(t.getNewValue()); + }); firstCol.setPrefWidth(140); lastCol.setPrefWidth(200); table.setItems(data); - table.getColumns().addAll(firstCol, lastCol); + table.getColumns().addAll(Arrays.asList(firstCol, lastCol)); final TextField addName = new TextField(); addName.setPromptText("name"); addName.setMaxWidth(100); @@ -116,9 +124,9 @@ public NameFormatterTab(JabRefPreferences prefs) { Label insertRows = new Label(Localization.lang("Insert rows")); insertRows.setVisible(false); Button add = new Button("Insert"); - add.setOnAction(e-> { + add.setOnAction(e -> { if (!addName.getText().isEmpty() && !addLast.getText().isEmpty()) { - TableRow tableRow = new TableRow(addName.getText(), addLast.getText()); + NameFormatterViewModel tableRow = new NameFormatterViewModel(addName.getText(), addLast.getText()); addName.clear(); addLast.clear(); data.add(tableRow); @@ -131,21 +139,22 @@ public NameFormatterTab(JabRefPreferences prefs) { Label deleteRows = new Label(Localization.lang("Delete rows")); deleteRows.setVisible(false); Button delete = new Button("Delete"); - delete.setOnAction(e-> { - if (table.getFocusModel() != null && table.getFocusModel().getFocusedIndex() != -1) { + delete.setOnAction(e -> { + if ((table.getFocusModel() != null) && (table.getFocusModel().getFocusedIndex() != -1)) { tableChanged = true; int row = table.getFocusModel().getFocusedIndex(); - TableRow tableRow = tableRows.get(row); + NameFormatterViewModel tableRow = tableRows.get(row); tableRows.remove(tableRow); data.remove(tableRow); table.setItems(data); table.refresh(); - }}); - Button help = new Button("?"); - help.setOnAction(e-> new HelpAction(Localization.lang("Help on Name Formatting"), - HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER).getHelpButton().doClick()); + } + }); + + Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on Name Formatting"), + HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER).getCommand()); HBox toolbar = new HBox(); - toolbar.getChildren().addAll(addName, addLast,add,delete,help); + toolbar.getChildren().addAll(addName, addLast, add, delete, help); tabPanel.setBottom(toolbar); Label specialNameFormatters = new Label(Localization.lang("Special name formatters")); @@ -154,6 +163,7 @@ public NameFormatterTab(JabRefPreferences prefs) { builder.add(tabPanel, 1, 2); } + @Override public Node getBuilder() { return builder; } @@ -166,9 +176,9 @@ public void setValues() { for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { - tableRows.add(new TableRow(names.get(i), formats.get(i))); + tableRows.add(new NameFormatterViewModel(names.get(i), formats.get(i))); } else { - tableRows.add(new TableRow(names.get(i))); + tableRows.add(new NameFormatterViewModel(names.get(i))); } } } @@ -198,7 +208,7 @@ public void storeSettings() { List names = new ArrayList<>(tableRows.size()); List formats = new ArrayList<>(tableRows.size()); - for (TableRow tr : tableRows) { + for (NameFormatterViewModel tr : tableRows) { names.add(tr.getName()); formats.add(tr.getFormat()); } diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsTab.java b/src/main/java/org/jabref/gui/preferences/TableColumnsTab.java index 090f22d3020..fe9dd582df7 100644 --- a/src/main/java/org/jabref/gui/preferences/TableColumnsTab.java +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTab.java @@ -35,6 +35,8 @@ import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.StandardActions; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.help.HelpAction; @@ -113,16 +115,17 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { field.setCellFactory(TextFieldTableCell.forTableColumn()); field.setEditable(true); field.setOnEditCommit( - (TableColumn.CellEditEvent t) -> { - t.getTableView().getItems().get( - t.getTablePosition().getRow()).setName(t.getNewValue()); - // Since data is an ObservableList, updating it updates the displayed field name. - this.data.set(t.getTablePosition().getRow(), new TableRow(t.getNewValue())); - // Update the User Preference of COLUMN_NAMES - List tempColumnNames = this.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); - tempColumnNames.set(t.getTablePosition().getRow(), t.getNewValue()); - this.prefs.putStringList(JabRefPreferences.COLUMN_NAMES, tempColumnNames); - }); + (TableColumn.CellEditEvent t) -> { + t.getTableView().getItems().get( + t.getTablePosition().getRow()) + .setName(t.getNewValue()); + // Since data is an ObservableList, updating it updates the displayed field name. + this.data.set(t.getTablePosition().getRow(), new TableRow(t.getNewValue())); + // Update the User Preference of COLUMN_NAMES + List tempColumnNames = this.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); + tempColumnNames.set(t.getTablePosition().getRow(), t.getNewValue()); + this.prefs.putStringList(JabRefPreferences.COLUMN_NAMES, tempColumnNames); + }); colSetup.setItems(data); colSetup.getColumns().add(field); @@ -150,7 +153,7 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { deleteRow = new Button("Delete"); deleteRow.setPrefSize(80, 20); deleteRow.setOnAction(e -> { - if (colSetup.getFocusModel() != null && colSetup.getFocusModel().getFocusedIndex() != -1) { + if ((colSetup.getFocusModel() != null) && (colSetup.getFocusModel().getFocusedIndex() != -1)) { tableChanged = true; int row = colSetup.getFocusModel().getFocusedIndex(); TableRow tableRow = data.get(row); @@ -162,7 +165,7 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { up.setOnAction(e -> { if (colSetup.getFocusModel() != null) { int row = colSetup.getFocusModel().getFocusedIndex(); - if (row > data.size() || row == 0) { + if ((row > data.size()) || (row == 0)) { return; } TableRow tableRow1 = data.get(row); @@ -178,7 +181,7 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { down.setOnAction(e -> { if (colSetup.getFocusModel() != null) { int row = colSetup.getFocusModel().getFocusedIndex(); - if (row + 1 > data.size()) { + if ((row + 1) > data.size()) { return; } TableRow tableRow1 = data.get(row); @@ -224,10 +227,10 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { /** begin: special table columns and special fields ***/ - Button helpButton = new Button("?"); - helpButton.setPrefSize(20, 20); - helpButton.setOnAction(e -> new HelpAction(Localization.lang("Help on special fields"), - HelpFile.SPECIAL_FIELDS).getHelpButton().doClick()); + ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository()); + + Button helpButton = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on special fields"), + HelpFile.SPECIAL_FIELDS).getCommand()); rankingColumn = new CheckBox(Localization.lang("Show rank")); qualityColumn = new CheckBox(Localization.lang("Show quality")); @@ -300,6 +303,7 @@ public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { builder.add(buttonOrder, 1, 7); } + @Override public Node getBuilder() { return builder; } @@ -331,7 +335,7 @@ public void setValues() { listOfFileColumns.getSelectionModel().select(indicesToSelect[i]); } } else { - listOfFileColumns.getSelectionModel().select(new int[]{}); + listOfFileColumns.getSelectionModel().select(new int[] {}); } /*** begin: special fields ***/ @@ -379,8 +383,8 @@ public void setValues() { public static class TableRow { - private SimpleStringProperty name; - private SimpleDoubleProperty length; + private final SimpleStringProperty name; + private final SimpleDoubleProperty length; public TableRow() { name = new SimpleStringProperty(""); @@ -447,19 +451,19 @@ public void storeSettings() { boolean restartRequired; restartRequired = (oldSpecialFieldsEnabled != newSpecialFieldsEnabled) || - (oldRankingColumn != newRankingColumn) || - (oldQualityColumn != newQualityColumn) || - (oldPriorityColumn != newPriorityColumn) || - (oldRelevanceColumn != newRelevanceColumn) || - (oldPrintedColumn != newPrintedColumn) || - (oldReadStatusColumn != newReadStatusColumn) || - (oldSyncKeyWords != newSyncKeyWords) || - (oldWriteSpecialFields != newWriteSpecialFields); + (oldRankingColumn != newRankingColumn) || + (oldQualityColumn != newQualityColumn) || + (oldPriorityColumn != newPriorityColumn) || + (oldRelevanceColumn != newRelevanceColumn) || + (oldPrintedColumn != newPrintedColumn) || + (oldReadStatusColumn != newReadStatusColumn) || + (oldSyncKeyWords != newSyncKeyWords) || + (oldWriteSpecialFields != newWriteSpecialFields); if (restartRequired) { DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().showWarningDialogAndWait(Localization.lang("Changed special field settings"), - Localization.lang("You have changed settings for special fields.") - .concat(" ") - .concat(Localization.lang("You must restart JabRef for this to come into effect.")))); + Localization.lang("You have changed settings for special fields.") + .concat(" ") + .concat(Localization.lang("You must restart JabRef for this to come into effect.")))); } @@ -479,11 +483,11 @@ public void storeSettings() { /*** end: special fields ***/ -// if (colSetup.isEditing()) { -// int col = colSetup.getEditingColumn(); -// int row = colSetup.getEditingRow(); -// colSetup.getCellEditor(row, col).stopCellEditing(); -// } + // if (colSetup.isEditing()) { + // int col = colSetup.getEditingColumn(); + // int row = colSetup.getEditingRow(); + // colSetup.getCellEditor(row, col).stopCellEditing(); + // } // Now we need to make sense of the contents the user has made to the // table setup table. diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 1c95118f7c1..2f5131a84a9 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2135,3 +2135,6 @@ Search\ document\ identifier\ online=Search document identifier online Search\ for\ unlinked\ local\ files=Search for unlinked local files Search\ full\ text\ documents\ online=Search full text documents online Find\ and\ replace=Find and replace + +Found\ documents\:=Found documents\: +Use\ selected\ document=Use selected document