diff --git a/CHANGELOG.md b/CHANGELOG.md index bfb7283b70b..ab3b180cd20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by - Fixed [#1364](https://github.com/JabRef/jabref/issues/1364): Windows: install to LOCALAPPDATA directory for non-admin users - Fixed [#1365](https://github.com/JabRef/jabref/issues/1365): Default label pattern back to "[auth][year]" - Fixed [#796](https://github.com/JabRef/jabref/issues/796): Undoing more than one entry at the same time is now working +- Fixed [#1353](https://github.com/JabRef/jabref/issues/1353): Fetch-Preview did not display updated BibTeX-Key after clicking on `Generate Now` ### Removed - Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic diff --git a/src/main/java/net/sf/jabref/gui/DuplicateResolverDialog.java b/src/main/java/net/sf/jabref/gui/DuplicateResolverDialog.java index be6b096e396..03efbc1d549 100644 --- a/src/main/java/net/sf/jabref/gui/DuplicateResolverDialog.java +++ b/src/main/java/net/sf/jabref/gui/DuplicateResolverDialog.java @@ -68,7 +68,7 @@ public DuplicateResolverDialog(JabRefFrame frame, BibEntry one, BibEntry two, Du public DuplicateResolverDialog(ImportInspectionDialog dialog, BibEntry one, BibEntry two, DuplicateResolverType type) { super(dialog, Localization.lang("Possible duplicate entries"), true); - this.frame = dialog.frame; + this.frame = dialog.getFrame(); init(one, two, type); } diff --git a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java index ad7376347bf..b4e1edfc2c7 100644 --- a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java +++ b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2015 JabRef contributors. +/* Copyright (C) 2003-2016 JabRef contributors. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -141,73 +141,48 @@ * any more results via addEntry, call entryListComplete() or dispose(), after * receiving this call). */ + public class ImportInspectionDialog extends JDialog implements ImportInspector, OutputPrinter { - private static final Log LOGGER = LogFactory.getLog(ImportInspectionDialog.class); + private static final Log LOGGER = LogFactory.getLog(ImportInspectionDialog.class); private BasePanel panel; - - public final JabRefFrame frame; - + private final JabRefFrame frame; private final BibDatabaseContext bibDatabaseContext; - private final JSplitPane contentPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - private final JTable glTable; - private final TableComparatorChooser comparatorChooser; - private final DefaultEventSelectionModel selectionModel; - private final JProgressBar progressBar = new JProgressBar(SwingConstants.HORIZONTAL); - private final JButton ok = new JButton(Localization.lang("OK")); private final JButton generate = new JButton(Localization.lang("Generate now")); - private final EventList entries = new BasicEventList<>(); - private final SortedList sortedList; /** * Duplicate resolving may require deletion of old entries. */ private final List entriesToDelete = new ArrayList<>(); - private final String undoName; - private final List callBacks = new ArrayList<>(); - private final boolean newDatabase; - private final JPopupMenu popup = new JPopupMenu(); - private final JButton deselectAllDuplicates = new JButton(Localization.lang("Deselect all duplicates")); - private final JButton stop = new JButton(Localization.lang("Stop")); - private final PreviewPanel preview; - private boolean generatedKeys; // Set to true after keys have been generated. - private boolean defaultSelected = true; - private final Rectangle toRect = new Rectangle(0, 0, 1, 1); - private final Map> groupAdditions = new HashMap<>(); - private final JCheckBox autoGenerate = new JCheckBox(Localization.lang("Generate keys"), Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION)); - private final JLabel duplLabel = new JLabel(IconTheme.JabRefIcon.DUPLICATE.getSmallIcon()); private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon()); private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon()); - private static final List INSPECTION_FIELDS = Arrays.asList("author", "title", "year", BibEntry.KEY_FIELD); - private static final int DUPL_COL = 1; private static final int FILE_COL = 2; private static final int URL_COL = 3; private static final int PAD = 4; - private static final String URL_FIELD = "url"; @@ -284,8 +259,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam bb.addGlue(); bb.addButton(ok); bb.addButton(stop); - JButton cancel = new JButton( - Localization.lang("Cancel")); + JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addRelatedGap(); JButton help = new HelpAction(HelpFiles.IMPORT_INSPECTION).getHelpButton(); @@ -341,8 +315,8 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Remember and default to last size: - setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), Globals.prefs - .getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); + setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), + Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); addWindowListener(new WindowAdapter() { @Override @@ -413,8 +387,11 @@ public void addEntries(Collection entriesToAdd) { deselectAllDuplicates.setEnabled(true); } this.entries.getReadWriteLock().writeLock().lock(); - this.entries.add(entry); - this.entries.getReadWriteLock().writeLock().unlock(); + try { + this.entries.add(entry); + } finally { + this.entries.getReadWriteLock().writeLock().unlock(); + } } } @@ -438,7 +415,6 @@ private Optional internalDuplicate(Collection entriesDupe, B return Optional.empty(); } - /* (non-Javadoc) * @see net.sf.jabref.gui.ImportInspection#entryListComplete() */ @@ -458,7 +434,6 @@ public void entryListComplete() { } } - /** * Generate key for the selected entry only. */ @@ -468,31 +443,32 @@ private void generateKeySelectedEntry() { } BibEntry entry = selectionModel.getSelected().get(0); entries.getReadWriteLock().writeLock().lock(); + try { + BibDatabase database; + MetaData localMetaData; + + // Relate to existing database, if any: + if (panel == null) { + database = new BibDatabase(); + localMetaData = new MetaData(); + } else { + database = panel.getDatabase(); + localMetaData = panel.getBibDatabaseContext().getMetaData(); + } - BibDatabase database; - MetaData localMetaData; + entry.setId(IdGenerator.next()); + // Add the entry to the database we are working with: + database.insertEntry(entry); - // Relate to existing database, if any: - if (panel == null) { - database = new BibDatabase(); - localMetaData = new MetaData(); - } else { - database = panel.getDatabase(); - localMetaData = panel.getBibDatabaseContext().getMetaData(); + // Generate a unique key: + LabelPatternUtil.makeLabel(localMetaData, database, entry); + // Remove the entry from the database again, since we only added it in + // order to + // make sure the key was unique: + database.removeEntry(entry); + } finally { + entries.getReadWriteLock().writeLock().unlock(); } - - entry.setId(IdGenerator.next()); - // Add the entry to the database we are working with: - database.insertEntry(entry); - - // Generate a unique key: - LabelPatternUtil.makeLabel(localMetaData, database, entry); - // Remove the entry from the database again, since we only added it in - // order to - // make sure the key was unique: - database.removeEntry(entry); - - entries.getReadWriteLock().writeLock().lock(); glTable.repaint(); } @@ -503,41 +479,48 @@ private void generateKeySelectedEntry() { */ private void generateKeys() { entries.getReadWriteLock().writeLock().lock(); + try { - BibDatabase database; - MetaData localMetaData; + BibDatabase database; + MetaData localMetaData; - // Relate to existing database, if any: - if (panel == null) { - database = new BibDatabase(); - localMetaData = new MetaData(); - } else { - database = panel.getDatabase(); - localMetaData = panel.getBibDatabaseContext().getMetaData(); - } + // Relate to existing database, if any: + if (panel == null) { + database = new BibDatabase(); + localMetaData = new MetaData(); + } else { + database = panel.getDatabase(); + localMetaData = panel.getBibDatabaseContext().getMetaData(); + } - List keys = new ArrayList<>(entries.size()); - // Iterate over the entries, add them to the database we are working - // with, - // and generate unique keys: - for (BibEntry entry : entries) { + List keys = new ArrayList<>(entries.size()); + // Iterate over the entries, add them to the database we are working + // with, + // and generate unique keys: + for (BibEntry entry : entries) { - entry.setId(IdGenerator.next()); - database.insertEntry(entry); + entry.setId(IdGenerator.next()); + database.insertEntry(entry); - LabelPatternUtil.makeLabel(localMetaData, database, entry); - // Add the generated key to our list: - keys.add(entry.getCiteKey()); - } - // Remove the entries from the database again, since they are not - // supposed to - // added yet. They only needed to be in it while we generated the keys, - // to keep - // control over key uniqueness. - for (BibEntry entry : entries) { - database.removeEntry(entry); + LabelPatternUtil.makeLabel(localMetaData, database, entry); + // Add the generated key to our list: + keys.add(entry.getCiteKey()); + } + + preview.update(); + preview.repaint(); + // Remove the entries from the database again, since they are not + // supposed to + // added yet. They only needed to be in it while we generated the keys, + // to keep + // control over key uniqueness. + for (BibEntry entry : entries) { + database.removeEntry(entry); + } + } finally { + entries.getReadWriteLock().writeLock().unlock(); } - entries.getReadWriteLock().writeLock().lock(); + glTable.repaint(); } @@ -580,6 +563,7 @@ private AbstractAction getAction(GroupTreeNode node) { return action; } + /** * Stores the information about the selected entries being scheduled for * addition to this group. The entries are *not* added to the group at this @@ -590,6 +574,7 @@ class AddToGroupAction extends AbstractAction { private final GroupTreeNode node; + public AddToGroupAction(GroupTreeNode node) { super(node.getName()); this.node = node; @@ -599,26 +584,31 @@ public AddToGroupAction(GroupTreeNode node) { public void actionPerformed(ActionEvent event) { selectionModel.getSelected().getReadWriteLock().writeLock().lock(); - for (BibEntry entry : selectionModel.getSelected()) { - // We store the groups this entry should be added to in a Set in - // the Map: - Set groups = groupAdditions.get(entry); - if (groups == null) { - // No previous definitions, so we create the Set now: - groups = new HashSet<>(); - groupAdditions.put(entry, groups); + try { + for (BibEntry entry : selectionModel.getSelected()) { + // We store the groups this entry should be added to in a Set in + // the Map: + Set groups = groupAdditions.get(entry); + if (groups == null) { + // No previous definitions, so we create the Set now: + groups = new HashSet<>(); + groupAdditions.put(entry, groups); + } + // Add the group: + groups.add(node); } - // Add the group: - groups.add(node); + } finally { + selectionModel.getSelected().getReadWriteLock().writeLock().unlock(); } - selectionModel.getSelected().getReadWriteLock().writeLock().unlock(); } } + public void addCallBack(CallBack cb) { callBacks.add(cb); } + private class OkListener implements ActionListener { @Override @@ -642,10 +632,11 @@ public void actionPerformed(ActionEvent event) { // is indicated by the entry's group hit status: if (entry.isGroupHit()) { CheckBoxMessage cbm = new CheckBoxMessage( - Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), + Localization + .lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"), Localization.lang("Disable this confirmation dialog"), false); - int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this, - cbm, Localization.lang("Duplicates found"), JOptionPane.YES_NO_OPTION); + int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this, cbm, + Localization.lang("Duplicates found"), JOptionPane.YES_NO_OPTION); if (cbm.isSelected()) { Globals.prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, false); } @@ -707,7 +698,8 @@ private void removeEntriesToDelete(NamedCompound ce) { private void addSelectedEntries(NamedCompound ce, final List selected) { if (newDatabase) { // Create a new BasePanel for the entries: - Defaults defaults = new Defaults(BibDatabaseMode.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); + Defaults defaults = new Defaults(BibDatabaseMode + .fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE))); panel = new BasePanel(frame, new BibDatabaseContext(defaults), Globals.prefs.getDefaultEncoding()); } @@ -741,7 +733,6 @@ private void addSelectedEntries(NamedCompound ce, final List selected) groupingCanceled = addToGroups(ce, entry, groups); } - entry.setId(IdGenerator.next()); panel.getDatabase().insertEntry(entry); ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel)); @@ -760,11 +751,9 @@ private boolean addToGroups(NamedCompound ce, BibEntry entry, Set // The best course of action is probably to ask the // user if a key should be generated // immediately. - int answer = JOptionPane - .showConfirmDialog( - ImportInspectionDialog.this, - Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"), - Localization.lang("Add to group"), JOptionPane.YES_NO_OPTION); + int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this, + Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"), + Localization.lang("Add to group"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { generateKeys(); } else { @@ -808,6 +797,7 @@ private List getSelectedEntries() { } + private void signalStopFetching() { callBacks.forEach(CallBack::stopFetching); } @@ -830,6 +820,7 @@ private void setWidths() { } } + private class DeleteListener extends AbstractAction { public DeleteListener() { @@ -849,11 +840,15 @@ private void removeSelectedEntries() { int row = glTable.getSelectedRow(); List toRemove = new ArrayList<>(); toRemove.addAll(selectionModel.getSelected()); + entries.getReadWriteLock().writeLock().lock(); - for (Object o : toRemove) { - entries.remove(o); + try { + for (Object o : toRemove) { + entries.remove(o); + } + } finally { + entries.getReadWriteLock().writeLock().unlock(); } - entries.getReadWriteLock().writeLock().unlock(); glTable.clearSelection(); if ((row >= 0) && (!entries.isEmpty())) { row = Math.min(entries.size() - 1, row); @@ -866,6 +861,7 @@ private class SelectionButton implements ActionListener { private final Boolean enable; + public SelectionButton(boolean enable) { this.enable = enable; } @@ -916,9 +912,8 @@ public void mouseClicked(MouseEvent e) { return; } FileListEntry fl = tableModel.getEntry(0); - (new ExternalFileMenuItem(frame, entry, "", fl.link, null, - panel.getBibDatabaseContext(), fl.type)) - .actionPerformed(null); + (new ExternalFileMenuItem(frame, entry, "", fl.link, null, panel.getBibDatabaseContext(), + fl.type)).actionPerformed(null); } } else { // Must be URL_COL openExternalLink(URL_FIELD, e); @@ -1029,7 +1024,8 @@ public void mousePressed(MouseEvent e) { // Is this the duplicate icon column, and is there an icon? if ((col == DUPL_COL) && (glTable.getValueAt(row, col) != null)) { BibEntry first = sortedList.get(row); - Optional other = DuplicateCheck.containsDuplicate(panel.getDatabase(), first, panel.getBibDatabaseContext().getMode()); + Optional other = DuplicateCheck.containsDuplicate(panel.getDatabase(), first, + panel.getBibDatabaseContext().getMode()); if (other.isPresent()) { // This will be true if the duplicate is in the existing // database. @@ -1046,20 +1042,30 @@ public void mousePressed(MouseEvent e) { // Clear duplicate icon, which is controlled by the // group hit // field of the entry: + entries.getReadWriteLock().writeLock().lock(); - first.setGroupHit(false); - entries.getReadWriteLock().writeLock().unlock(); + try { + first.setGroupHit(false); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } } else if (diag.getSelected() == DuplicateResolverResult.KEEP_LOWER) { // Remove the entry from the import inspection dialog. entries.getReadWriteLock().writeLock().lock(); - entries.remove(first); - entries.getReadWriteLock().writeLock().unlock(); + try { + entries.remove(first); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } } else if (diag.getSelected() == DuplicateResolverResult.KEEP_BOTH) { // Do nothing. entries.getReadWriteLock().writeLock().lock(); - first.setGroupHit(false); - entries.getReadWriteLock().writeLock().unlock(); + try { + first.setGroupHit(false); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } } else if (diag.getSelected() == DuplicateResolverResult.KEEP_MERGE) { // Remove old entry. Or... add it to a list of entries // to be deleted. We only delete @@ -1070,12 +1076,15 @@ public void mousePressed(MouseEvent e) { // group hit // field of the entry: entries.getReadWriteLock().writeLock().lock(); - diag.getMergedEntry().setGroupHit(false); - diag.getMergedEntry().setSearchHit(true); - entries.add(diag.getMergedEntry()); - entries.remove(first); - first = new BibEntry(); // Reset first so the next duplicate doesn't trigger - entries.getReadWriteLock().writeLock().unlock(); + try { + diag.getMergedEntry().setGroupHit(false); + diag.getMergedEntry().setSearchHit(true); + entries.add(diag.getMergedEntry()); + entries.remove(first); + first = new BibEntry(); // Reset first so the next duplicate doesn't trigger + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } } } // Check if the duplicate is of another entry in the import: @@ -1122,23 +1131,26 @@ public void actionPerformed(ActionEvent event) { String result = JOptionPane.showInputDialog(ImportInspectionDialog.this, Localization.lang("Enter URL"), entry.getField(URL_FIELD)); entries.getReadWriteLock().writeLock().lock(); - if (result != null) { - if (result.isEmpty()) { - entry.clearField(URL_FIELD); - } else { - entry.setField(URL_FIELD, result); + try { + if (result != null) { + if (result.isEmpty()) { + entry.clearField(URL_FIELD); + } else { + entry.setField(URL_FIELD, result); + } } + } finally { + entries.getReadWriteLock().writeLock().unlock(); } - entries.getReadWriteLock().writeLock().unlock(); glTable.repaint(); } } - class DownloadFile extends JMenuItem implements ActionListener, - DownloadExternalFile.DownloadCallback { + class DownloadFile extends JMenuItem implements ActionListener, DownloadExternalFile.DownloadCallback { private BibEntry entry; + public DownloadFile() { super(Localization.lang("Download file")); addActionListener(this); @@ -1154,8 +1166,7 @@ public void actionPerformed(ActionEvent actionEvent) { if (bibtexKey == null) { int answer = JOptionPane.showConfirmDialog(frame, Localization.lang("This entry has no BibTeX key. Generate key now?"), - Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE); + Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.OK_OPTION) { generateKeySelectedEntry(); bibtexKey = entry.getCiteKey(); @@ -1176,8 +1187,11 @@ public void downloadComplete(FileListEntry file) { entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), file); entries.getReadWriteLock().writeLock().lock(); - entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); - entries.getReadWriteLock().writeLock().unlock(); + try { + entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } glTable.repaint(); } } @@ -1198,8 +1212,7 @@ public void actionPerformed(ActionEvent actionEvent) { if (entry.getCiteKey() == null) { int answer = JOptionPane.showConfirmDialog(frame, Localization.lang("This entry has no BibTeX key. Generate key now?"), - Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE); + Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.OK_OPTION) { generateKeySelectedEntry(); } else { @@ -1214,21 +1227,25 @@ public void actionPerformed(ActionEvent actionEvent) { JabRefExecutorService.INSTANCE.execute( net.sf.jabref.external.AutoSetLinks.autoSetLinks(entry, localModel, bibDatabaseContext, e -> { if (e.getID() > 0) { + entries.getReadWriteLock().writeLock().lock(); - entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); - entries.getReadWriteLock().writeLock().unlock(); + try { + entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } glTable.repaint(); } - } , diag)); + }, diag)); } } - private class LinkLocalFile extends JMenuItem implements ActionListener, - DownloadExternalFile.DownloadCallback { + private class LinkLocalFile extends JMenuItem implements ActionListener, DownloadExternalFile.DownloadCallback { private BibEntry entry; + public LinkLocalFile() { super(Localization.lang("Link local file")); addActionListener(this); @@ -1248,8 +1265,11 @@ public void actionPerformed(ActionEvent actionEvent) { entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), flEntry); entries.getReadWriteLock().writeLock().lock(); - entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); - entries.getReadWriteLock().writeLock().unlock(); + try { + entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } glTable.repaint(); } } @@ -1261,12 +1281,16 @@ public void downloadComplete(FileListEntry file) { entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(localModel::setContent); localModel.addEntry(localModel.getRowCount(), file); entries.getReadWriteLock().writeLock().lock(); - entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); - entries.getReadWriteLock().writeLock().unlock(); + try { + entry.setField(Globals.FILE_FIELD, localModel.getStringRepresentation()); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } glTable.repaint(); } } + private void setupComparatorChooser() { // First column: @@ -1294,19 +1318,12 @@ private void setupComparatorChooser() { comparators.add(new FieldComparator(INSPECTION_FIELDS.get(i - PAD))); } - // Set initial sort columns: - - /* - * // Default sort order: String[] sortFields = new String[] - * {Globals.prefs.get(JabRefPreferences.PRIMARY_SORT_FIELD), Globals.prefs.get(JabRefPreferences.SECONDARY_SORT_FIELD), - * Globals.prefs.get(JabRefPreferences.TERTIARY_SORT_FIELD)}; boolean[] sortDirections = new - * boolean[] {Globals.prefs.getBoolean(JabRefPreferences.PRIMARY_SORT_DESCENDING), - * Globals.prefs.getBoolean(JabRefPreferences.SECONDARY_SORT_DESCENDING), - * Globals.prefs.getBoolean(JabRefPreferences.TERTIARY_SORT_DESCENDING)}; // descending - */ sortedList.getReadWriteLock().writeLock().lock(); - comparatorChooser.appendComparator(PAD, 0, false); - sortedList.getReadWriteLock().writeLock().unlock(); + try { + comparatorChooser.appendComparator(PAD, 0, false); + } finally { + sortedList.getReadWriteLock().writeLock().unlock(); + } } @@ -1338,6 +1355,7 @@ class EntryTable extends JTable { private final GeneralRenderer renderer = new GeneralRenderer(Color.white); + public EntryTable(TableModel model) { super(model); getTableHeader().setReorderingAllowed(false); @@ -1369,9 +1387,12 @@ public void setValueAt(Object value, int row, int column) { // Only column 0, which is controlled by BibEntry.searchHit, is // editable: entries.getReadWriteLock().writeLock().lock(); - BibEntry entry = sortedList.get(row); - entry.setSearchHit((Boolean) value); - entries.getReadWriteLock().writeLock().unlock(); + try { + BibEntry entry = sortedList.get(row); + entry.setSearchHit((Boolean) value); + } finally { + entries.getReadWriteLock().writeLock().unlock(); + } } } @@ -1426,8 +1447,7 @@ public Object getColumnValue(BibEntry entry, int i) { } else { String field = INSPECTION_FIELDS.get(i - PAD); if (InternalBibtexFields.getFieldExtras(field).contains(FieldProperties.PERSON_NAMES)) { - return entry.getFieldOptional(field).map(AuthorList::fixAuthorNatbib) - .orElse(""); + return entry.getFieldOptional(field).map(AuthorList::fixAuthorNatbib).orElse(""); } else { return entry.getField(field); } @@ -1436,6 +1456,7 @@ public Object getColumnValue(BibEntry entry, int i) { } + @Override public void setStatus(String s) { frame.setStatus(s); @@ -1450,4 +1471,8 @@ public void showMessage(Object message, String title, int msgType) { public void showMessage(String message) { JOptionPane.showMessageDialog(this, message); } + + public JabRefFrame getFrame() { + return frame; + } } diff --git a/src/test/java/net/sf/jabref/importer/fetcher/CrossRefTest.java b/src/test/java/net/sf/jabref/importer/fetcher/CrossRefTest.java index a97ca9454a9..c826d0203f2 100644 --- a/src/test/java/net/sf/jabref/importer/fetcher/CrossRefTest.java +++ b/src/test/java/net/sf/jabref/importer/fetcher/CrossRefTest.java @@ -10,7 +10,7 @@ public class CrossRefTest { @Test - public void findExactData() throws Exception { + public void findExactData() { BibEntry entry = new BibEntry(); entry.setField("title", "Service Interaction Patterns"); entry.setField("author", "Barros, Alistair and Dumas, Marlon and Arthur H.M. ter Hofstede"); @@ -19,7 +19,7 @@ public void findExactData() throws Exception { } @Test - public void findMissingAuthor() throws Exception { + public void findMissingAuthor() { BibEntry entry = new BibEntry(); entry.setField("title", "Towards Application Portability in Platform as a Service"); entry.setField("author", "Stefan Kolb"); @@ -27,14 +27,14 @@ public void findMissingAuthor() throws Exception { } @Test - public void findTitleOnly() throws Exception { + public void findTitleOnly() { BibEntry entry = new BibEntry(); entry.setField("title", "Towards Application Portability in Platform as a Service"); assertEquals("10.1109/sose.2014.26", CrossRef.findDOI(entry).get().getDOI().toLowerCase(Locale.ENGLISH)); } @Test - public void findIncompleteTitle() throws Exception { + public void findIncompleteTitle() { BibEntry entry = new BibEntry(); entry.setField("title", "Towards Application Portability"); entry.setField("author", "Stefan Kolb and Guido Wirtz"); @@ -42,7 +42,7 @@ public void findIncompleteTitle() throws Exception { } @Test - public void findWrongAuthor() throws Exception { + public void findWrongAuthor() { BibEntry entry = new BibEntry(); entry.setField("title", "Towards Application Portability in Platform as a Service"); entry.setField("author", "Stefan Kolb and Simon Harrer");