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 5b4dd1cb7dd..5588e9b32d1 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; @@ -31,13 +32,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); @@ -56,26 +54,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)); } }; @@ -86,13 +88,12 @@ 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 } @@ -101,8 +102,11 @@ public boolean include(Entry entry) { GUIUtil.correctRowHeight(table); + // 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/model/database/BibDatabase.java b/src/main/java/net/sf/jabref/model/database/BibDatabase.java index 87ca8a7ce98..f018173c27a 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,21 @@ 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) { + for (BibEntry entry : entries) { + if (entry.getId().equals(id)) { + return Optional.of(entry); + } + } + return Optional.empty(); + } + /** * 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";