From 1573d486642a56cd79ae516d665af7b14c2470bb Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 10 Jan 2020 11:41:08 +0100 Subject: [PATCH] Fix KeyCollisionException --- .../org/jabref/gui/collab/ChangeScanner.java | 2 +- .../gui/collab/EntryChangeViewModel.java | 19 ++++++------------- .../gui/collab/MetaDataChangeViewModel.java | 4 +++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index 97dde224108..424018d9080 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -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()); } } diff --git a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java index adc8de730d7..a7de6536a1e 100644 --- a/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java @@ -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")); - } /** @@ -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 @@ -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; } } diff --git a/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java b/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java index a2cb62818be..20d04162b42 100644 --- a/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java @@ -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));