Skip to content

Commit

Permalink
Fix KeyCollisionException
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Jan 10, 2020
1 parent 34e3c50 commit 1573d48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ private DatabaseChangeViewModel createBibEntryDiff(BibEntryDiff diff) {
return new EntryDeleteChangeViewModel(diff.getOriginalEntry());
}

return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry(), database);
return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry());
}
}
19 changes: 6 additions & 13 deletions src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class EntryChangeViewModel extends DatabaseChangeViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(EntryChangeViewModel.class);

private final BibEntry oldEntry;
private final BibEntry newEntry;
private MergeEntries mergePanel;

private final BibDatabaseContext database;

public EntryChangeViewModel(BibEntry entry, BibEntry newEntry, BibDatabaseContext database) {
public EntryChangeViewModel(BibEntry entry, BibEntry newEntry) {
super();

this.oldEntry = entry;
this.newEntry = newEntry;
this.database = database;

name = entry.getCiteKeyOptional()
.map(key -> Localization.lang("Modified entry") + ": '" + key + '\'')
.orElse(Localization.lang("Modified entry"));

}

/**
Expand All @@ -55,9 +46,11 @@ public void setAccepted(boolean accepted) {
@Override
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
database.getDatabase().removeEntry(oldEntry);
database.getDatabase().insertEntry(mergePanel.getMergeEntry());
BibEntry mergedEntry = mergePanel.getMergeEntry();
mergedEntry.setId(oldEntry.getId()); // Keep ID
database.getDatabase().insertEntry(mergedEntry);
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), oldEntry));
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), mergePanel.getMergeEntry()));
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), mergedEntry));
}

@Override
Expand All @@ -68,7 +61,7 @@ public Node description() {
header.getStyleClass().add("sectionHeader");
container.getChildren().add(header);
container.getChildren().add(mergePanel);
container.setMargin(mergePanel, new Insets(5, 5, 5, 5));
VBox.setMargin(mergePanel, new Insets(5, 5, 5, 5));
return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public MetaDataChangeViewModel(MetaDataDiff metaDataDiff) {
public Node description() {
VBox container = new VBox(15);

container.getChildren().add(new Label(Localization.lang("The following metadata changed:")));
Label header = new Label(Localization.lang("The following metadata changed:"));
header.getStyleClass().add("sectionHeader");
container.getChildren().add(header);

for (String change : metaDataDiff.getDifferences()) {
container.getChildren().add(new Label(change));
Expand Down

0 comments on commit 1573d48

Please sign in to comment.