Skip to content

Commit

Permalink
Fix #1062 Merge entry with DOI information now also applies changes t…
Browse files Browse the repository at this point in the history
…o entry type
  • Loading branch information
stefan-kolb committed Mar 30, 2016
1 parent 71ebaab commit af38aa5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixed [#936](https://github.com/JabRef/jabref/issues/936): Preview panel is now updated when an entry is cut/deleted
- Fixed [#1001](https://github.com/JabRef/jabref/issues/1001): No NPE when exporting a complete database
- Fixed [#991](https://github.com/JabRef/jabref/issues/991): Entry is now correctly removed from the BibDatabase
- Fixed [#1062](https://github.com/JabRef/jabref/issues/1062): Merge entry with DOI information now also applies changes to entry type


### Removed
- Fixed [#627](https://github.com/JabRef/jabref/issues/627): The pdf field is removed from the export formats, use the file field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.TreeSet;

import javax.swing.*;

import net.sf.jabref.gui.undo.UndoableChangeType;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.JabRefPreferences;
Expand Down Expand Up @@ -156,15 +158,27 @@ public void componentMoved(ComponentEvent e) {
*/
private void buttonPressed(String button) {
BibEntry mergedEntry = mergeEntries.getMergeEntry();

if ("cancel".equals(button)) {
// Cancelled, throw it away
panel.output(Localization.lang("Cancelled merging entries"));
} else if ("done".equals(button)) {
// Updated the original entry with the new fields
Set<String> jointFields = new TreeSet<>(mergedEntry.getFieldNames());
Set<String> originalFields = new TreeSet<>(originalEntry.getFieldNames());
Boolean edited = false;
boolean edited = false;

// entry type
String oldType = originalEntry.getType();
String newType = mergedEntry.getType();

if(!oldType.equalsIgnoreCase(newType)) {
originalEntry.setType(newType);
ce.addEdit(new UndoableChangeType(originalEntry, oldType, newType));
edited = true;
}

// fields
for (String field : jointFields) {
String originalString = originalEntry.getField(field);
String mergedString = mergedEntry.getField(field);
Expand All @@ -185,12 +199,11 @@ private void buttonPressed(String button) {
}
}

//

if (edited) {
ce.end();
panel.undoManager.addEdit(ce);
panel.output(Localization.lang("Updated entry with info from DOI"));
panel.updateEntryEditorIfShowing();
panel.markBaseChanged();
} else {
panel.output(Localization.lang("No information added"));
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/net/sf/jabref/gui/undo/UndoableChangeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
* This class represents the change of type for an entry.
*/
public class UndoableChangeType extends AbstractUndoableEdit {

private final String oldType;
private final String newType;
private final BibEntry be;

private final BibEntry entry;

public UndoableChangeType(BibEntry be, String oldType, String newType) {
public UndoableChangeType(BibEntry entry, String oldType, String newType) {
this.oldType = oldType;
this.newType = newType;
this.be = be;
this.entry = entry;
}

@Override
Expand All @@ -48,13 +46,12 @@ public String getRedoPresentationName() {
@Override
public void undo() {
super.undo();
be.setType(oldType);
entry.setType(oldType);
}

@Override
public void redo() {
super.redo();
be.setType(newType);
entry.setType(newType);
}

}

0 comments on commit af38aa5

Please sign in to comment.