Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show merge entries for modified entries #5688

Merged
merged 34 commits into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7eab878
[WIP] Show merge entries for modified entries
Siedlerchr Nov 30, 2019
1965b74
refactor and insert entry
Siedlerchr Nov 30, 2019
ceb9a6a
remove obsolete l10n key
Siedlerchr Nov 30, 2019
abd0d5d
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 5, 2019
ab2beef
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 7, 2019
743554a
fix spacing
Siedlerchr Dec 8, 2019
21b4de3
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 14, 2019
dd3defe
fix javadoc
Siedlerchr Dec 14, 2019
ab48a98
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 20, 2019
6884034
pass second entry to merge dialog
Siedlerchr Dec 20, 2019
475fb6b
add Exception logging to Databsae Change Monitor
Siedlerchr Dec 20, 2019
014edb1
fix l10n
Siedlerchr Dec 20, 2019
916498f
add changelog
Siedlerchr Dec 20, 2019
340a43f
remove old entry, move merge Panel init to description
Siedlerchr Dec 20, 2019
c909db9
fix error
Siedlerchr Dec 20, 2019
2750183
beautify controls
Siedlerchr Dec 20, 2019
22b0939
improve layout of merge dialog
Siedlerchr Dec 21, 2019
c825212
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 23, 2019
7b0ee12
remove checkbox when merge entries
Siedlerchr Dec 24, 2019
392f51c
make koppor happy
Siedlerchr Dec 26, 2019
001e3f0
fix tests
Siedlerchr Dec 26, 2019
e830f52
remove obsolete parameter
Siedlerchr Dec 26, 2019
798d497
Fix parameter name
koppor Dec 26, 2019
0b62ff6
Remove obsolete newline
koppor Dec 26, 2019
f266af3
Fix localization
koppor Dec 26, 2019
241502c
Change arrows
koppor Dec 26, 2019
1432148
Fix checkstyle
koppor Dec 26, 2019
53a0b11
Center selection column
koppor Dec 26, 2019
55e2f23
Remove obsolete language keys
koppor Dec 26, 2019
09fbfca
Remove l10n from arrows
Siedlerchr Dec 26, 2019
f033134
Update arrows (#5787)
koppor Dec 26, 2019
756d4bc
preselect left
Siedlerchr Dec 29, 2019
fa6fb54
Merge remote-tracking branch 'upstream/master' into changemergesdialog
Siedlerchr Dec 29, 2019
4c0e055
fix checkstyle
Siedlerchr Dec 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/gui/collab/ChangeDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class ChangeDisplayDialog extends BaseDialog<Boolean> {
private final ListView<DatabaseChangeViewModel> tree;
private final BorderPane infoPanel = new BorderPane();
private final CheckBox cb = new CheckBox(Localization.lang("Accept change"));
private final BibDatabaseContext database;
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved

public ChangeDisplayDialog(BibDatabaseContext database, List<DatabaseChangeViewModel> changes) {
this.database = database;
this.setTitle(Localization.lang("External changes"));
this.getDialogPane().setPrefSize(800, 600);

Expand All @@ -43,9 +45,8 @@ public ChangeDisplayDialog(BibDatabaseContext database, List<DatabaseChangeViewM
infoPanel.setCenter(rootInfo);

getDialogPane().getButtonTypes().setAll(
new ButtonType(Localization.lang("Accept changes"), ButtonBar.ButtonData.APPLY),
ButtonType.CANCEL
);
new ButtonType(Localization.lang("Accept changes"), ButtonBar.ButtonData.APPLY),
ButtonType.CANCEL);

setResultConverter(button -> {
if (button == ButtonType.CANCEL) {
Expand All @@ -66,7 +67,7 @@ public ChangeDisplayDialog(BibDatabaseContext database, List<DatabaseChangeViewM
});

EasyBind.subscribe(cb.selectedProperty(), selected -> {
if (selected != null && tree.getSelectionModel().getSelectedItem() != null) {
if ((selected != null) && (tree.getSelectionModel().getSelectedItem() != null)) {
tree.getSelectionModel().getSelectedItem().setAccepted(selected);
}
});
Expand Down
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());
return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry(), database);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

class EntryAddChangeViewModel extends DatabaseChangeViewModel {
class EntryAddChangeViewModel extends DatabaseChangeViewModel {

private final BibEntry diskEntry;

Expand Down
110 changes: 24 additions & 86 deletions src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package org.jabref.gui.collab;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

import org.jabref.gui.mergeentries.MergeEntries;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.undo.UndoableInsertEntry;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.strings.StringUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,41 +18,37 @@ class EntryChangeViewModel extends DatabaseChangeViewModel {

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

private final List<FieldChangeViewModel> fieldChanges = new ArrayList<>();
private final BibEntry firstEntry;

private final BibEntry secondEntry;

public EntryChangeViewModel(BibEntry entry, BibEntry newEntry) {
private final MergeEntries mergePanel;

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

this.firstEntry = entry;
this.secondEntry = newEntry;

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

Set<Field> allFields = new TreeSet<>(Comparator.comparing(Field::getName));
allFields.addAll(entry.getFields());
allFields.addAll(newEntry.getFields());

for (Field field : allFields) {
Optional<String> value = entry.getField(field);
Optional<String> newValue = newEntry.getField(field);

if (value.isPresent() && newValue.isPresent()) {
if (!value.equals(newValue)) {
// Modified externally.
fieldChanges.add(new FieldChangeViewModel(entry, field, value.get(), newValue.get()));
}
} else {
// Added/removed externally.
fieldChanges.add(new FieldChangeViewModel(entry, field, value.orElse(null), newValue.orElse(null)));
}
}
mergePanel = new MergeEntries(firstEntry, secondEntry, database.getMode());
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
for (DatabaseChangeViewModel c : fieldChanges) {
if (c.isAccepted()) {
c.makeChange(database, undoEdit);
}
}
database.getDatabase().insertEntry(mergePanel.getMergeEntry());
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
undoEdit.addEdit(new UndoableInsertEntry(database.getDatabase(), mergePanel.getMergeEntry()));
}

public BibEntry getFirst() {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
return this.firstEntry;
}

public BibEntry getSecond() {
return this.secondEntry;
}

@Override
Expand All @@ -70,56 +57,7 @@ public Node description() {
Label header = new Label(name);
header.getStyleClass().add("sectionHeader");
container.getChildren().add(header);

for (FieldChangeViewModel change : fieldChanges) {
container.getChildren().add(change.description());
}

container.getChildren().add(mergePanel);
return container;
}

static class FieldChangeViewModel extends DatabaseChangeViewModel {

private final BibEntry entry;
private final Field field;
private final String value;
private final String newValue;

public FieldChangeViewModel(BibEntry entry, Field field, String value, String newValue) {
super(field.getName());
this.entry = entry;
this.field = field;
this.value = value;
this.newValue = newValue;
}

@Override
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
Optional<FieldChange> change;
if (StringUtil.isBlank(newValue)) {
change = entry.clearField(field);
} else {
change = entry.setField(field, newValue);
}

change.map(UndoableFieldChange::new).ifPresent(undoEdit::addEdit);
}

@Override
public Node description() {
VBox container = new VBox();
container.getChildren().add(new Label(Localization.lang("Modification of field") + " " + field.getDisplayName()));

if (StringUtil.isNotBlank(newValue)) {
container.getChildren().add(new Label(Localization.lang("Value set externally") + ": " + newValue));
} else {
container.getChildren().add(new Label(Localization.lang("Value cleared externally")));
}

container.getChildren().add(new Label(Localization.lang("Current value") + ": " + value));

return container;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class EntryDeleteChangeViewModel extends DatabaseChangeViewModel {
class EntryDeleteChangeViewModel extends DatabaseChangeViewModel {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger LOGGER = LoggerFactory.getLogger(EntryDeleteChangeViewModel.class);
private final BibEntry entry;
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,6 @@ Memory\ stick\ mode=Memory stick mode
Merged\ external\ changes=Merged external changes
Merge\ fields=Merge fields

Modification\ of\ field=Modification of field

Modified\ group\ "%0".=Modified group "%0".

Modified\ groups=Modified groups
Expand Down