diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index d600fb0f212..f89a0a9bcfb 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1299,16 +1299,16 @@ public void insertEntry(final BibEntry bibEntry) { } } - public void editEntryByKeyAndFocusField(final String bibtexKey, final String fieldName) { - final List entries = bibDatabaseContext.getDatabase().getEntriesByKey(bibtexKey); - if (entries.size() == 1) { - mainTable.setSelected(mainTable.findEntry(entries.get(0))); + public void editEntryByIdAndFocusField(final String entryId, final String fieldName) { + final Optional entry = bibDatabaseContext.getDatabase().getEntryById(entryId); + entry.ifPresent(e -> { + mainTable.setSelected(mainTable.findEntry(e)); selectionListener.editSignalled(); - final EntryEditor editor = getEntryEditor(entries.get(0)); + final EntryEditor editor = getEntryEditor(e); editor.setFocusToField(fieldName); this.showEntryEditor(editor); editor.requestFocus(); - } + }); } public void updateTableFont() { diff --git a/src/main/java/net/sf/jabref/gui/actions/IntegrityCheckAction.java b/src/main/java/net/sf/jabref/gui/actions/IntegrityCheckAction.java index c0a70627a43..029568f674f 100644 --- a/src/main/java/net/sf/jabref/gui/actions/IntegrityCheckAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/IntegrityCheckAction.java @@ -16,6 +16,7 @@ import javax.swing.ListSelectionModel; import javax.swing.RowFilter; import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; @@ -30,13 +31,10 @@ import com.jgoodies.forms.layout.FormLayout; public class IntegrityCheckAction extends MnemonicAwareAction { - private static final String ELLIPSES = "..."; - private final JabRefFrame frame; - public IntegrityCheckAction(JabRefFrame frame) { this.frame = frame; putValue(Action.NAME, Localization.menuTitle("Check integrity") + ELLIPSES); @@ -55,26 +53,30 @@ public void actionPerformed(ActionEvent e) { } else { Map showMessage = new HashMap<>(); // prepare data model - Object[][] model = new Object[messages.size()][3]; + Object[][] model = new Object[messages.size()][4]; int i = 0; for (IntegrityMessage message : messages) { - model[i][0] = message.getEntry().getCiteKeyOptional().orElse(""); - model[i][1] = message.getFieldName(); - model[i][2] = message.getMessage(); + model[i][0] = message.getEntry().getId(); + model[i][1] = message.getEntry().getCiteKeyOptional().orElse(""); + model[i][2] = message.getFieldName(); + model[i][3] = message.getMessage(); showMessage.put(message.getMessage(), true); i++; } // construct view JTable table = new JTable(model, - new Object[] {Localization.lang("BibTeX key"), Localization.lang("Field"), + new Object[] {"ID", Localization.lang("BibTeX key"), Localization.lang("Field"), Localization.lang("Message")}); - RowFilter filter = new RowFilter() { + // hide IDs + TableColumnModel columnModel = table.getColumnModel(); + columnModel.removeColumn(columnModel.getColumn(0)); + RowFilter filter = new RowFilter() { @Override public boolean include(Entry entry) { - return showMessage.get(entry.getStringValue(2)); + return showMessage.get(entry.getStringValue(3)); } }; @@ -85,21 +87,23 @@ public boolean include(Entry entry) { table.setDefaultEditor(Object.class, null); ListSelectionModel selectionModel = table.getSelectionModel(); - selectionModel.addListSelectionListener(event -> { if (!event.getValueIsAdjusting()) { try { - String citeKey = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0]; - String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][1]; - frame.getCurrentBasePanel().editEntryByKeyAndFocusField(citeKey, fieldName); + String entryId = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][0]; + String fieldName = (String) model[table.convertRowIndexToModel(table.getSelectedRow())][2]; + frame.getCurrentBasePanel().editEntryByIdAndFocusField(entryId, fieldName); } catch (ArrayIndexOutOfBoundsException exception) { // Ignore -- most likely caused by filtering out the earlier selected row } } }); - + + // BibTeX key table.getColumnModel().getColumn(0).setPreferredWidth(100); + // field name table.getColumnModel().getColumn(1).setPreferredWidth(60); + // message table.getColumnModel().getColumn(2).setPreferredWidth(400); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); JScrollPane scrollPane = new JScrollPane(table); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java index 8a9c6a85fb0..7f681de9dcc 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditorTab.java @@ -6,6 +6,7 @@ import java.awt.Dimension; import java.awt.KeyboardFocusManager; import java.awt.event.FocusListener; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -80,9 +81,9 @@ class EntryEditorTab { public EntryEditorTab(JabRefFrame frame, BasePanel panel, List fields, EntryEditor parent, boolean addKeyField, boolean compressed, String tabTitle) { if (fields == null) { - this.fields = Collections.emptyList(); + this.fields = new ArrayList<>(); } else { - this.fields = fields; + this.fields = new ArrayList<>(fields); } this.parent = parent; @@ -195,6 +196,7 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField setupJTextComponent(textField, null); editors.put(BibEntry.KEY_FIELD, textField); + fields.add(BibEntry.KEY_FIELD); /* * If the key field is the only field, we should have only one * editor, and this one should be set as active initially: @@ -278,7 +280,7 @@ public FieldEditor getActive() { } public List getFields() { - return fields; + return Collections.unmodifiableList(fields); } public void focus() { diff --git a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java index 57410de09c7..3c549e00bd8 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/BibtexkeyChecker.java @@ -10,6 +10,9 @@ import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.model.strings.StringUtil; +/** + * Currently only checks the key if there is an author, year, and title present. + */ public class BibtexkeyChecker implements Checker { @Override diff --git a/src/main/java/net/sf/jabref/model/database/BibDatabase.java b/src/main/java/net/sf/jabref/model/database/BibDatabase.java index 87ca8a7ce98..b19e3a66523 100644 --- a/src/main/java/net/sf/jabref/model/database/BibDatabase.java +++ b/src/main/java/net/sf/jabref/model/database/BibDatabase.java @@ -38,7 +38,6 @@ * A bibliography database. */ public class BibDatabase { - private static final Log LOGGER = LogFactory.getLog(BibDatabase.class); /** @@ -151,6 +150,16 @@ public synchronized List getEntriesByKey(String key) { return result; } + /** + * Finds the entry with a specified ID. + * + * @param id + * @return The entry that has the given id + */ + public synchronized Optional getEntryById(String id) { + return entries.stream().filter(entry -> entry.getId().equals(id)).findFirst(); + } + /** * Inserts the entry, given that its ID is not already in use. * use Util.createId(...) to make up a unique ID for an entry. diff --git a/src/main/java/net/sf/jabref/model/entry/BibEntry.java b/src/main/java/net/sf/jabref/model/entry/BibEntry.java index 4c0bc0568d3..bcb786f6273 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibEntry.java @@ -36,7 +36,6 @@ import org.apache.commons.logging.LogFactory; public class BibEntry implements Cloneable { - private static final Log LOGGER = LogFactory.getLog(BibEntry.class); public static final String TYPE_HEADER = "entrytype";