From 046e2e7f2aaa865bfd5e1895690639c61e67672b Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Thu, 10 Mar 2016 14:33:13 +0100 Subject: [PATCH] Fixes #914 EntryEditor must store the currently displayed BibEntry type to redraw correctly onChange --- .../java/net/sf/jabref/gui/BasePanel.java | 30 +++++++++---------- .../jabref/gui/actions/ChangeTypeAction.java | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 7 +++-- .../net/sf/jabref/model/entry/BibEntry.java | 3 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index eb4d29a59aa..80cbb0b3b60 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1859,7 +1859,7 @@ public void ensureNotShowing(BibEntry be) { public void updateEntryEditorIfShowing() { if (mode == BasePanel.SHOWING_EDITOR) { - if (currentEditor.getType().equals(currentEditor.getEntry().getType())) { + if (currentEditor.getDisplayedBibEntryType().equals(currentEditor.getEntry().getType())) { currentEditor.updateAllFields(); currentEditor.updateSource(); } else { @@ -2025,36 +2025,36 @@ public void stringsClosing() { stringDialog = null; } - public void changeType(String type) { + public void changeTypeOfSelectedEntries(String newType) { List bes = mainTable.getSelectedEntries(); - changeType(bes, type); + changeTypeOfSelectedEntries(bes, newType); } - private void changeType(List bes, String type) { - - if ((bes == null) || (bes.isEmpty())) { + private void changeTypeOfSelectedEntries(List entries, String newType) { + if ((entries == null) || (entries.isEmpty())) { LOGGER.error("At least one entry must be selected to be able to change the type."); return; } - if (bes.size() > 1) { + + if (entries.size() > 1) { int choice = JOptionPane.showConfirmDialog(this, Localization.lang("Multiple entries selected. Do you want to change the type of all these to '%0'?", - type), + newType), Localization.lang("Change entry type"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } - NamedCompound ce = new NamedCompound(Localization.lang("Change entry type")); - for (BibEntry be : bes) { - ce.addEdit(new UndoableChangeType(be, be.getType(), type)); - be.setType(type); + NamedCompound compound = new NamedCompound(Localization.lang("Change entry type")); + for (BibEntry entry : entries) { + compound.addEdit(new UndoableChangeType(entry, entry.getType(), newType)); + entry.setType(newType); } - output(formatOutputMessage(Localization.lang("Changed type to '%0' for", type), bes.size())); - ce.end(); - undoManager.addEdit(ce); + output(formatOutputMessage(Localization.lang("Changed type to '%0' for", newType), entries.size())); + compound.end(); + undoManager.addEdit(compound); markBaseChanged(); updateEntryEditorIfShowing(); } diff --git a/src/main/java/net/sf/jabref/gui/actions/ChangeTypeAction.java b/src/main/java/net/sf/jabref/gui/actions/ChangeTypeAction.java index a4203a2343d..df8d7bee258 100644 --- a/src/main/java/net/sf/jabref/gui/actions/ChangeTypeAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/ChangeTypeAction.java @@ -19,6 +19,6 @@ public ChangeTypeAction(EntryType type, BasePanel bp) { @Override public void actionPerformed(ActionEvent evt) { - panel.changeType(type); + panel.changeTypeOfSelectedEntries(type); } } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index b0bde8311e8..72d27abaa79 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -90,6 +90,8 @@ public class EntryEditor extends JPanel implements VetoableChangeListener, Entry // A reference to the entry this object works on. private BibEntry entry; + // The currently displayed type + private final String displayedBibEntryType; // The action concerned with closing the window. private final CloseAction closeAction; @@ -168,6 +170,7 @@ public EntryEditor(JabRefFrame frame, BasePanel panel, BibEntry entry) { this.entry.addPropertyChangeListener(this); this.entry.addPropertyChangeListener(SpecialFieldUpdateListener.getInstance()); + displayedBibEntryType = entry.getType(); helpAction = new HelpAction(HelpFiles.entryEditorHelp, IconTheme.JabRefIcon.HELP.getIcon()); closeAction = new CloseAction(); @@ -305,8 +308,8 @@ private void setupFieldPanels() { srcPanel.setFocusCycleRoot(true); } - public String getType() { - return entry.getType(); + public String getDisplayedBibEntryType() { + return displayedBibEntryType; } /** 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 63a42657abb..7b469a7b86c 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibEntry.java @@ -109,13 +109,12 @@ public void setType(String type) { } String oldType = this.type; - type = type.toLowerCase(); try { // We set the type before throwing the changeEvent, to enable // the change listener to access the new value if the change // sets off a change in database sorting etc. - this.type = type; + this.type = type.toLowerCase(); changed = true; firePropertyChangedEvent(TYPE_HEADER, oldType == null ? null : oldType, type); } catch (PropertyVetoException pve) {