From 10fec835b6c9da33465c7c4640d16b00e3686a01 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Tue, 23 Aug 2022 18:36:56 +0100 Subject: [PATCH 01/12] Show a warning when the authors are the same but formatted differently --- .../newmergedialog/AuthorsFieldRowView.java | 30 +++++++++++ .../newmergedialog/FieldRowView.java | 4 +- .../newmergedialog/ThreeWayMergeView.java | 8 ++- .../cell/sidebuttons/WarningButton.java | 50 +++++++++++++++++++ src/main/resources/l10n/JabRef_en.properties | 2 + 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java create mode 100644 src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java new file mode 100644 index 00000000000..5b0c2d81c32 --- /dev/null +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java @@ -0,0 +1,30 @@ +package org.jabref.gui.mergeentries.newmergedialog; + +import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.WarningButton; +import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory; +import org.jabref.logic.importer.AuthorListParser; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.AuthorList; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + +public class AuthorsFieldRowView extends FieldRowView { + private final AuthorList leftEntryAuthors; + private final AuthorList rightEntryAuthors; + + public AuthorsFieldRowView(BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { + super(StandardField.AUTHOR, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, rowIndex); + var authorsParser = new AuthorListParser(); + leftEntryAuthors = authorsParser.parse(viewModel.getLeftFieldValue()); + rightEntryAuthors = authorsParser.parse(viewModel.getRightFieldValue()); + + if (leftEntryAuthors.equals(rightEntryAuthors)) { + showAuthorsAreTheSameWarning(); + } + } + + private void showAuthorsAreTheSameWarning() { + WarningButton warningButton = new WarningButton(Localization.lang("The authors are the same, but the fields are formatted differently.")); + getFieldNameCell().addSideButton(warningButton); + } +} diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java index 78888ba787c..ec50762d970 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java @@ -34,6 +34,8 @@ */ public class FieldRowView { private static final Logger LOGGER = LoggerFactory.getLogger(FieldRowView.class); + + protected final FieldRowViewModel viewModel; private final FieldNameCell fieldNameCell; private final FieldValueCell leftValueCell; private final FieldValueCell rightValueCell; @@ -41,8 +43,6 @@ public class FieldRowView { private final ToggleGroup toggleGroup = new ToggleGroup(); - private final FieldRowViewModel viewModel; - private final CompoundEdit fieldsMergedEdit = new CompoundEdit(); public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java index a61833456f8..a694f8d2109 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java @@ -17,6 +17,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.StandardField; public class ThreeWayMergeView extends VBox { public static final int GRID_COLUMN_MIN_WIDTH = 250; @@ -119,7 +120,12 @@ private Field getFieldAtIndex(int index) { private void addRow(int fieldIndex) { Field field = getFieldAtIndex(fieldIndex); - FieldRowView fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + FieldRowView fieldRow; + if (field == StandardField.AUTHOR) { + fieldRow = new AuthorsFieldRowView(getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + } else { + fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + } fieldRows.add(fieldIndex, fieldRow); diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java new file mode 100644 index 00000000000..113d8f696b2 --- /dev/null +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java @@ -0,0 +1,50 @@ +package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.scene.control.Button; + +import org.jabref.gui.Globals; +import org.jabref.gui.actions.Action; +import org.jabref.gui.actions.ActionFactory; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.icon.IconTheme; + +import com.tobiasdiez.easybind.EasyBind; + +public class WarningButton extends Button { + private final StringProperty warningMessage = new SimpleStringProperty(); + private final ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); + + public WarningButton(String warningMessage) { + setWarningMessage(warningMessage); + configureButton(); + EasyBind.subscribe(warningMessageProperty(), newWarningMessage -> { + configureButton(); + }); + } + + private void configureButton() { + setMaxHeight(Double.MAX_VALUE); + setFocusTraversable(false); + Action mergeAction = new Action.Builder(getWarningMessage()).setIcon(IconTheme.JabRefIcons.WARNING); + + actionFactory.configureIconButton(mergeAction, new SimpleCommand() { + @Override + public void execute() { + } + }, this); + } + + private void setWarningMessage(String warningMessage) { + warningMessageProperty().set(warningMessage); + } + + public StringProperty warningMessageProperty() { + return warningMessage; + } + + public String getWarningMessage() { + return warningMessage.get(); + } +} diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 43a9c75a6dc..e71f54c1733 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2525,3 +2525,5 @@ Merge\ %0=Merge %0 Right\ Entry=Right Entry Unmerge\ %0=Unmerge %0 plain\ text=plain text + +The\ authors\ are\ the\ same,\ but\ the\ fields\ are\ formatted\ differently.=The authors are the same, but the fields are formatted differently. From 25941f09b3c5402c0f1d0faf4fca387fd0d6e218 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Tue, 23 Aug 2022 18:44:01 +0100 Subject: [PATCH 02/12] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 560c53118de..c2cea870486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - On startup, JabRef notifies the user if there were parsing errors during opening. - We integrated a new three-way merge UI for merging entries in the Entries Merger Dialog, the Duplicate Resolver Dialog, the Entry Importer Dialog, and the External Changes Resolver Dialog. [#8945](https://github.com/JabRef/jabref/pull/8945) - We added the ability to merge groups, keywords, comments and files when merging entries. [#9022](https://github.com/JabRef/jabref/pull/9022) +- We added a warning message next to the authors field in the merge dialog to warn users when the authors are the same but formatted differently. [#9088](https://github.com/JabRef/jabref/pull/9088) ### Changed From c6d989b65c3c5cbf43ec99c864475260aa80935a Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Tue, 23 Aug 2022 18:49:06 +0100 Subject: [PATCH 03/12] Link issue rather than pr in the changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2cea870486..c3301e81b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - On startup, JabRef notifies the user if there were parsing errors during opening. - We integrated a new three-way merge UI for merging entries in the Entries Merger Dialog, the Duplicate Resolver Dialog, the Entry Importer Dialog, and the External Changes Resolver Dialog. [#8945](https://github.com/JabRef/jabref/pull/8945) - We added the ability to merge groups, keywords, comments and files when merging entries. [#9022](https://github.com/JabRef/jabref/pull/9022) -- We added a warning message next to the authors field in the merge dialog to warn users when the authors are the same but formatted differently. [#9088](https://github.com/JabRef/jabref/pull/9088) +- We added a warning message next to the authors field in the merge dialog to warn users when the authors are the same but formatted differently. [#8745](https://github.com/JabRef/jabref/issues/8745) ### Changed From 7f20d6bc4c867a1b6ee7be3b373a92bee58a9f65 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Tue, 23 Aug 2022 18:59:30 +0100 Subject: [PATCH 04/12] Checkstyle --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3301e81b28..842f924349b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - On startup, JabRef notifies the user if there were parsing errors during opening. - We integrated a new three-way merge UI for merging entries in the Entries Merger Dialog, the Duplicate Resolver Dialog, the Entry Importer Dialog, and the External Changes Resolver Dialog. [#8945](https://github.com/JabRef/jabref/pull/8945) - We added the ability to merge groups, keywords, comments and files when merging entries. [#9022](https://github.com/JabRef/jabref/pull/9022) -- We added a warning message next to the authors field in the merge dialog to warn users when the authors are the same but formatted differently. [#8745](https://github.com/JabRef/jabref/issues/8745) +- We added a warning message next to the authors field in the merge dialog to warn users when the authors are the same but formatted differently. [#8745](https://github.com/JabRef/jabref/issues/8745) ### Changed From 6bd8e703e17c8018ae4c0f7d22d69fb39aff6989 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:24:16 +0100 Subject: [PATCH 05/12] Show the warning for all fields with person names --- .../newmergedialog/AuthorsFieldRowView.java | 30 ----------------- .../PersonsNameFieldRowView.java | 33 +++++++++++++++++++ .../newmergedialog/ThreeWayMergeView.java | 5 +-- 3 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java create mode 100644 src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java deleted file mode 100644 index 5b0c2d81c32..00000000000 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/AuthorsFieldRowView.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.jabref.gui.mergeentries.newmergedialog; - -import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.WarningButton; -import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory; -import org.jabref.logic.importer.AuthorListParser; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.AuthorList; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.StandardField; - -public class AuthorsFieldRowView extends FieldRowView { - private final AuthorList leftEntryAuthors; - private final AuthorList rightEntryAuthors; - - public AuthorsFieldRowView(BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { - super(StandardField.AUTHOR, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, rowIndex); - var authorsParser = new AuthorListParser(); - leftEntryAuthors = authorsParser.parse(viewModel.getLeftFieldValue()); - rightEntryAuthors = authorsParser.parse(viewModel.getRightFieldValue()); - - if (leftEntryAuthors.equals(rightEntryAuthors)) { - showAuthorsAreTheSameWarning(); - } - } - - private void showAuthorsAreTheSameWarning() { - WarningButton warningButton = new WarningButton(Localization.lang("The authors are the same, but the fields are formatted differently.")); - getFieldNameCell().addSideButton(warningButton); - } -} diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java new file mode 100644 index 00000000000..2aa384a72eb --- /dev/null +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java @@ -0,0 +1,33 @@ +package org.jabref.gui.mergeentries.newmergedialog; + +import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.WarningButton; +import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory; +import org.jabref.logic.importer.AuthorListParser; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.AuthorList; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldProperty; + +public class PersonsNameFieldRowView extends FieldRowView { + private final AuthorList leftEntryNames; + private final AuthorList rightEntryNames; + + public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { + super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, rowIndex); + assert field.getProperties().contains(FieldProperty.PERSON_NAMES); + + var authorsParser = new AuthorListParser(); + leftEntryNames = authorsParser.parse(viewModel.getLeftFieldValue()); + rightEntryNames = authorsParser.parse(viewModel.getRightFieldValue()); + + if (leftEntryNames.equals(rightEntryNames)) { + showPersonsNamesAreTheSameWarning(); + } + } + + private void showPersonsNamesAreTheSameWarning() { + WarningButton warningButton = new WarningButton(Localization.lang("The {}s are the same, but the fields are formatted differently.", viewModel.getField().getName())); + getFieldNameCell().addSideButton(warningButton); + } +} diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java index a694f8d2109..27055bdedab 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java @@ -17,6 +17,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldProperty; import org.jabref.model.entry.field.StandardField; public class ThreeWayMergeView extends VBox { @@ -121,8 +122,8 @@ private void addRow(int fieldIndex) { Field field = getFieldAtIndex(fieldIndex); FieldRowView fieldRow; - if (field == StandardField.AUTHOR) { - fieldRow = new AuthorsFieldRowView(getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + if (field.getProperties().contains(FieldProperty.PERSON_NAMES)) { + fieldRow = new PersonsNameFieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); } else { fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); } From 2206d9ae02d0a37352365ffa0a128edd03a70834 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:28:15 +0100 Subject: [PATCH 06/12] Modify warning message Co-authored-by: ThiloteE <73715071+thilotee@users.noreply.github.com> --- .../mergeentries/newmergedialog/PersonsNameFieldRowView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java index 2aa384a72eb..394cc4d669a 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java @@ -27,7 +27,7 @@ public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEn } private void showPersonsNamesAreTheSameWarning() { - WarningButton warningButton = new WarningButton(Localization.lang("The {}s are the same, but the fields are formatted differently.", viewModel.getField().getName())); + WarningButton warningButton = new WarningButton(Localization.lang("The {}s are the same. However, the order of field content differs", viewModel.getField().getName())); getFieldNameCell().addSideButton(warningButton); } } From 1e8b0cd17b9d56086f0d8b3d14cee136c625215d Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:45:39 +0100 Subject: [PATCH 07/12] Use an info icon rather than a warning --- .../PersonsNameFieldRowView.java | 12 +++++----- .../{WarningButton.java => InfoButton.java} | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/{WarningButton.java => InfoButton.java} (57%) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java index 394cc4d669a..bd9033b072c 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java @@ -1,6 +1,6 @@ package org.jabref.gui.mergeentries.newmergedialog; -import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.WarningButton; +import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.InfoButton; import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory; import org.jabref.logic.importer.AuthorListParser; import org.jabref.logic.l10n.Localization; @@ -21,13 +21,13 @@ public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEn leftEntryNames = authorsParser.parse(viewModel.getLeftFieldValue()); rightEntryNames = authorsParser.parse(viewModel.getRightFieldValue()); - if (leftEntryNames.equals(rightEntryNames)) { - showPersonsNamesAreTheSameWarning(); + if (!leftEntry.equals(rightEntry) && leftEntryNames.equals(rightEntryNames)) { + showPersonsNamesAreTheSameInfo(); } } - private void showPersonsNamesAreTheSameWarning() { - WarningButton warningButton = new WarningButton(Localization.lang("The {}s are the same. However, the order of field content differs", viewModel.getField().getName())); - getFieldNameCell().addSideButton(warningButton); + private void showPersonsNamesAreTheSameInfo() { + InfoButton infoButton = new InfoButton(Localization.lang("The %0s are the same. However, the order of field content differs", viewModel.getField().getName())); + getFieldNameCell().addSideButton(infoButton); } } diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java similarity index 57% rename from src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java rename to src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java index 113d8f696b2..490096cbff5 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/WarningButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java @@ -12,14 +12,14 @@ import com.tobiasdiez.easybind.EasyBind; -public class WarningButton extends Button { - private final StringProperty warningMessage = new SimpleStringProperty(); +public class InfoButton extends Button { + private final StringProperty infoMessage = new SimpleStringProperty(); private final ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - public WarningButton(String warningMessage) { - setWarningMessage(warningMessage); + public InfoButton(String infoMessage) { + setInfoMessage(infoMessage); configureButton(); - EasyBind.subscribe(warningMessageProperty(), newWarningMessage -> { + EasyBind.subscribe(infoMessageProperty(), newWarningMessage -> { configureButton(); }); } @@ -27,7 +27,7 @@ public WarningButton(String warningMessage) { private void configureButton() { setMaxHeight(Double.MAX_VALUE); setFocusTraversable(false); - Action mergeAction = new Action.Builder(getWarningMessage()).setIcon(IconTheme.JabRefIcons.WARNING); + Action mergeAction = new Action.Builder(getInfoMessage()).setIcon(IconTheme.JabRefIcons.INTEGRITY_INFO); actionFactory.configureIconButton(mergeAction, new SimpleCommand() { @Override @@ -36,15 +36,15 @@ public void execute() { }, this); } - private void setWarningMessage(String warningMessage) { - warningMessageProperty().set(warningMessage); + private void setInfoMessage(String infoMessage) { + infoMessageProperty().set(infoMessage); } - public StringProperty warningMessageProperty() { - return warningMessage; + public StringProperty infoMessageProperty() { + return infoMessage; } - public String getWarningMessage() { - return warningMessage.get(); + public String getInfoMessage() { + return infoMessage.get(); } } From 2e99c0016c092ba71f84d7266b9ef8ba14830db1 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:48:31 +0100 Subject: [PATCH 08/12] Checkstyle --- .../gui/mergeentries/newmergedialog/ThreeWayMergeView.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java index 27055bdedab..06f6861d751 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java @@ -18,7 +18,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldProperty; -import org.jabref.model.entry.field.StandardField; public class ThreeWayMergeView extends VBox { public static final int GRID_COLUMN_MIN_WIDTH = 250; From 0dcde2082f0c80fec992d3fa122709f8cad4297f Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:53:35 +0100 Subject: [PATCH 09/12] Add a comment for why InfoButton command is empty --- .../mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java index 490096cbff5..da37e2267ce 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/sidebuttons/InfoButton.java @@ -32,6 +32,7 @@ private void configureButton() { actionFactory.configureIconButton(mergeAction, new SimpleCommand() { @Override public void execute() { + // The info button is not meant to be clickable that's why this is empty } }, this); } From fc0436679e67f479fd773f0ea78ea0967b917cca Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 00:56:55 +0100 Subject: [PATCH 10/12] Delete FieldRowController.java --- .../newmergedialog/FieldRowController.java | 139 ------------------ 1 file changed, 139 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowController.java diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowController.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowController.java deleted file mode 100644 index 8f2411d89cf..00000000000 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowController.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.jabref.gui.mergeentries.newmergedialog; - -import javafx.beans.property.ReadOnlyStringProperty; -import javafx.scene.control.ToggleGroup; - -import org.jabref.gui.mergeentries.newmergedialog.cell.FieldNameCell; -import org.jabref.gui.mergeentries.newmergedialog.cell.FieldValueCell; -import org.jabref.gui.mergeentries.newmergedialog.cell.MergedFieldCell; -import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.SplitDiffHighlighter; -import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.UnifiedDiffHighlighter; -import org.jabref.gui.mergeentries.newmergedialog.toolbar.ThreeWayMergeToolbar; -import org.jabref.model.strings.StringUtil; - -import org.fxmisc.richtext.StyleClassedTextArea; - -public class FieldRowController { - private final FieldNameCell fieldNameCell; - private final FieldValueCell leftValueCell; - private FieldValueCell rightValueCell; - private final MergedFieldCell mergedValueCell; - - private final String leftValue; - - private final String rightValue; - - private final ToggleGroup toggleGroup = new ToggleGroup(); - - public FieldRowController(String fieldName, String leftValue, String rightValue, int rowIndex) { - fieldNameCell = new FieldNameCell(fieldName, rowIndex); - leftValueCell = new FieldValueCell(leftValue, rowIndex); - rightValueCell = new FieldValueCell(rightValue, rowIndex); - mergedValueCell = new MergedFieldCell(StringUtil.isNullOrEmpty(leftValue) ? rightValue : leftValue, rowIndex); - - this.leftValue = leftValue; - this.rightValue = rightValue; - - toggleGroup.getToggles().addAll(leftValueCell, rightValueCell); - toggleGroup.selectToggle(StringUtil.isNullOrEmpty(leftValue) ? rightValueCell : leftValueCell); - toggleGroup.selectedToggleProperty().addListener(invalidated -> { - if (toggleGroup.getSelectedToggle() != null) { - mergedValueCell.setText((String) toggleGroup.getSelectedToggle().getUserData()); - } - }); - - mergedValueCell.textProperty().addListener((observable, old, mergedValue) -> { - if (mergedValue.equals(leftValue)) { - toggleGroup.selectToggle(leftValueCell); - } else if (mergedValue.equals(rightValue)) { - toggleGroup.selectToggle(rightValueCell); - } else { - // deselect all toggles because left and right values don't equal the merged value - toggleGroup.selectToggle(null); - } - }); - - // When both the left and right cells have the same value, only the left value is displayed, - // making it unnecessary to keep allocating memory for the right cell. - if (hasEqualLeftAndRightValues()) { - // Setting this to null so the GC release the memory allocated to the right cell. - this.rightValueCell = null; - } - } - - public void selectLeftValue() { - toggleGroup.selectToggle(leftValueCell); - } - - public void selectRightValue() { - if (isRightValueCellHidden()) { - selectLeftValue(); - } else { - toggleGroup.selectToggle(rightValueCell); - } - } - - public String getMergedValue() { - return mergedValueProperty().getValue(); - } - - public ReadOnlyStringProperty mergedValueProperty() { - return mergedValueCell.textProperty(); - } - - public FieldNameCell getFieldNameCell() { - return fieldNameCell; - } - - public FieldValueCell getLeftValueCell() { - return leftValueCell; - } - - public FieldValueCell getRightValueCell() { - return rightValueCell; - } - - public MergedFieldCell getMergedValueCell() { - return mergedValueCell; - } - - public boolean hasEqualLeftAndRightValues() { - return isRightValueCellHidden() || (!StringUtil.isNullOrEmpty(leftValueCell.getText()) && - !StringUtil.isNullOrEmpty(rightValueCell.getText()) && - leftValueCell.getText().equals(rightValueCell.getText())); - } - - public void showDiff(ShowDiffConfig diffConfig) { - if (isRightValueCellHidden()) { - return; - } - - StyleClassedTextArea leftLabel = leftValueCell.getStyleClassedLabel(); - StyleClassedTextArea rightLabel = rightValueCell.getStyleClassedLabel(); - // Clearing old diff styles based on previous diffConfig - hideDiff(); - if (diffConfig.diffView() == ThreeWayMergeToolbar.DiffView.UNIFIED) { - new UnifiedDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); - } else { - new SplitDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); - } - } - - public void hideDiff() { - if (isRightValueCellHidden()) { - return; - } - - int leftValueLength = getLeftValueCell().getStyleClassedLabel().getLength(); - getLeftValueCell().getStyleClassedLabel().clearStyle(0, leftValueLength); - getLeftValueCell().getStyleClassedLabel().replaceText(leftValue); - - int rightValueLength = getRightValueCell().getStyleClassedLabel().getLength(); - getRightValueCell().getStyleClassedLabel().clearStyle(0, rightValueLength); - getRightValueCell().getStyleClassedLabel().replaceText(rightValue); - } - - private boolean isRightValueCellHidden() { - return rightValueCell == null; - } -} From 991f92507b61e3f502ad32cb0304c2b0d9fd197a Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Sat, 27 Aug 2022 01:03:17 +0100 Subject: [PATCH 11/12] Hide diffs if persons names are the same --- .../mergeentries/newmergedialog/FieldRowView.java | 14 ++++++++++---- .../newmergedialog/PersonsNameFieldRowView.java | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java index ec50762d970..2a84eb1d1f8 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java @@ -5,7 +5,9 @@ import javax.swing.undo.CannotUndoException; import javax.swing.undo.CompoundEdit; +import javafx.beans.property.BooleanProperty; import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.SimpleBooleanProperty; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.GridPane; @@ -36,6 +38,8 @@ public class FieldRowView { private static final Logger LOGGER = LoggerFactory.getLogger(FieldRowView.class); protected final FieldRowViewModel viewModel; + + protected final BooleanProperty shouldShowDiffs = new SimpleBooleanProperty(true); private final FieldNameCell fieldNameCell; private final FieldValueCell leftValueCell; private final FieldValueCell rightValueCell; @@ -159,10 +163,12 @@ public void showDiff(ShowDiffConfig diffConfig) { StyleClassedTextArea rightLabel = rightValueCell.getStyleClassedLabel(); // Clearing old diff styles based on previous diffConfig hideDiff(); - if (diffConfig.diffView() == ThreeWayMergeToolbar.DiffView.UNIFIED) { - new UnifiedDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); - } else { - new SplitDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); + if (shouldShowDiffs.get()) { + if (diffConfig.diffView() == ThreeWayMergeToolbar.DiffView.UNIFIED) { + new UnifiedDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); + } else { + new SplitDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight(); + } } } diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java index bd9033b072c..e42bb91743b 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java @@ -23,6 +23,7 @@ public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEn if (!leftEntry.equals(rightEntry) && leftEntryNames.equals(rightEntryNames)) { showPersonsNamesAreTheSameInfo(); + shouldShowDiffs.set(false); } } From b34d83c23a7b6151087d76b29cc3795de92c5c2c Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Wed, 31 Aug 2022 20:15:29 +0100 Subject: [PATCH 12/12] i18n --- src/main/resources/l10n/JabRef_en.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e71f54c1733..b20df8c379b 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2526,4 +2526,5 @@ Right\ Entry=Right Entry Unmerge\ %0=Unmerge %0 plain\ text=plain text -The\ authors\ are\ the\ same,\ but\ the\ fields\ are\ formatted\ differently.=The authors are the same, but the fields are formatted differently. +The\ %0s\ are\ the\ same.\ However,\ the\ order\ of\ field\ content\ differs=The %0s are the same. However, the order of field content differs +