Skip to content

Commit

Permalink
Fixes #914 EntryEditor must store the currently displayed BibEntry ty…
Browse files Browse the repository at this point in the history
…pe to redraw correctly onChange
  • Loading branch information
stefan-kolb committed Mar 10, 2016
1 parent 5fc915e commit 046e2e7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2025,36 +2025,36 @@ public void stringsClosing() {
stringDialog = null;
}

public void changeType(String type) {
public void changeTypeOfSelectedEntries(String newType) {
List<BibEntry> bes = mainTable.getSelectedEntries();
changeType(bes, type);
changeTypeOfSelectedEntries(bes, newType);
}

private void changeType(List<BibEntry> bes, String type) {

if ((bes == null) || (bes.isEmpty())) {
private void changeTypeOfSelectedEntries(List<BibEntry> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public ChangeTypeAction(EntryType type, BasePanel bp) {

@Override
public void actionPerformed(ActionEvent evt) {
panel.changeType(type);
panel.changeTypeOfSelectedEntries(type);
}
}
7 changes: 5 additions & 2 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -305,8 +308,8 @@ private void setupFieldPanels() {
srcPanel.setFocusCycleRoot(true);
}

public String getType() {
return entry.getType();
public String getDisplayedBibEntryType() {
return displayedBibEntryType;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sf/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 046e2e7

Please sign in to comment.