Skip to content

Commit 7239503

Browse files
Show a warning in the merge dialog when authors are the same but formatted differently (#9088)
* Show a warning when the authors are the same but formatted differently * Update CHANGELOG.md * Link issue rather than pr in the changelog * Checkstyle * Show the warning for all fields with person names * Modify warning message Co-authored-by: ThiloteE <[email protected]> * Use an info icon rather than a warning * Checkstyle * Add a comment for why InfoButton command is empty * Delete FieldRowController.java * Hide diffs if persons names are the same * i18n Co-authored-by: ThiloteE <[email protected]>
1 parent 5a34184 commit 7239503

File tree

6 files changed

+108
-7
lines changed

6 files changed

+108
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
1515
- On startup, JabRef notifies the user if there were parsing errors during opening.
1616
- 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)
1717
- We added the ability to merge groups, keywords, comments and files when merging entries. [#9022](https://github.com/JabRef/jabref/pull/9022)
18+
- 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)
1819

1920
### Changed
2021

src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import javax.swing.undo.CannotUndoException;
66
import javax.swing.undo.CompoundEdit;
77

8+
import javafx.beans.property.BooleanProperty;
89
import javafx.beans.property.ReadOnlyStringProperty;
10+
import javafx.beans.property.SimpleBooleanProperty;
911
import javafx.scene.control.ToggleGroup;
1012
import javafx.scene.layout.GridPane;
1113

@@ -35,15 +37,17 @@
3537
*/
3638
public class FieldRowView {
3739
private static final Logger LOGGER = LoggerFactory.getLogger(FieldRowView.class);
40+
41+
protected final FieldRowViewModel viewModel;
42+
43+
protected final BooleanProperty shouldShowDiffs = new SimpleBooleanProperty(true);
3844
private final FieldNameCell fieldNameCell;
3945
private final FieldValueCell leftValueCell;
4046
private final FieldValueCell rightValueCell;
4147
private final MergedFieldCell mergedValueCell;
4248

4349
private final ToggleGroup toggleGroup = new ToggleGroup();
4450

45-
private final FieldRowViewModel viewModel;
46-
4751
private final CompoundEdit fieldsMergedEdit = new CompoundEdit();
4852

4953
public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) {
@@ -160,10 +164,12 @@ public void showDiff(ShowDiffConfig diffConfig) {
160164
StyleClassedTextArea rightLabel = rightValueCell.getStyleClassedLabel();
161165
// Clearing old diff styles based on previous diffConfig
162166
hideDiff();
163-
if (diffConfig.diffView() == ThreeWayMergeToolbar.DiffView.UNIFIED) {
164-
new UnifiedDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight();
165-
} else {
166-
new SplitDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight();
167+
if (shouldShowDiffs.get()) {
168+
if (diffConfig.diffView() == ThreeWayMergeToolbar.DiffView.UNIFIED) {
169+
new UnifiedDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight();
170+
} else {
171+
new SplitDiffHighlighter(leftLabel, rightLabel, diffConfig.diffHighlightingMethod()).highlight();
172+
}
167173
}
168174
}
169175

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.jabref.gui.mergeentries.newmergedialog;
2+
3+
import org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons.InfoButton;
4+
import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory;
5+
import org.jabref.logic.importer.AuthorListParser;
6+
import org.jabref.logic.l10n.Localization;
7+
import org.jabref.model.entry.AuthorList;
8+
import org.jabref.model.entry.BibEntry;
9+
import org.jabref.model.entry.field.Field;
10+
import org.jabref.model.entry.field.FieldProperty;
11+
12+
public class PersonsNameFieldRowView extends FieldRowView {
13+
private final AuthorList leftEntryNames;
14+
private final AuthorList rightEntryNames;
15+
16+
public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) {
17+
super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, rowIndex);
18+
assert field.getProperties().contains(FieldProperty.PERSON_NAMES);
19+
20+
var authorsParser = new AuthorListParser();
21+
leftEntryNames = authorsParser.parse(viewModel.getLeftFieldValue());
22+
rightEntryNames = authorsParser.parse(viewModel.getRightFieldValue());
23+
24+
if (!leftEntry.equals(rightEntry) && leftEntryNames.equals(rightEntryNames)) {
25+
showPersonsNamesAreTheSameInfo();
26+
shouldShowDiffs.set(false);
27+
}
28+
}
29+
30+
private void showPersonsNamesAreTheSameInfo() {
31+
InfoButton infoButton = new InfoButton(Localization.lang("The %0s are the same. However, the order of field content differs", viewModel.getField().getName()));
32+
getFieldNameCell().addSideButton(infoButton);
33+
}
34+
}

src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.jabref.logic.l10n.Localization;
1818
import org.jabref.model.entry.BibEntry;
1919
import org.jabref.model.entry.field.Field;
20+
import org.jabref.model.entry.field.FieldProperty;
2021

2122
public class ThreeWayMergeView extends VBox {
2223
public static final int GRID_COLUMN_MIN_WIDTH = 250;
@@ -119,7 +120,12 @@ private Field getFieldAtIndex(int index) {
119120
private void addRow(int fieldIndex) {
120121
Field field = getFieldAtIndex(fieldIndex);
121122

122-
FieldRowView fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex);
123+
FieldRowView fieldRow;
124+
if (field.getProperties().contains(FieldProperty.PERSON_NAMES)) {
125+
fieldRow = new PersonsNameFieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex);
126+
} else {
127+
fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex);
128+
}
123129

124130
fieldRows.add(fieldIndex, fieldRow);
125131

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.jabref.gui.mergeentries.newmergedialog.cell.sidebuttons;
2+
3+
import javafx.beans.property.SimpleStringProperty;
4+
import javafx.beans.property.StringProperty;
5+
import javafx.scene.control.Button;
6+
7+
import org.jabref.gui.Globals;
8+
import org.jabref.gui.actions.Action;
9+
import org.jabref.gui.actions.ActionFactory;
10+
import org.jabref.gui.actions.SimpleCommand;
11+
import org.jabref.gui.icon.IconTheme;
12+
13+
import com.tobiasdiez.easybind.EasyBind;
14+
15+
public class InfoButton extends Button {
16+
private final StringProperty infoMessage = new SimpleStringProperty();
17+
private final ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs());
18+
19+
public InfoButton(String infoMessage) {
20+
setInfoMessage(infoMessage);
21+
configureButton();
22+
EasyBind.subscribe(infoMessageProperty(), newWarningMessage -> {
23+
configureButton();
24+
});
25+
}
26+
27+
private void configureButton() {
28+
setMaxHeight(Double.MAX_VALUE);
29+
setFocusTraversable(false);
30+
Action mergeAction = new Action.Builder(getInfoMessage()).setIcon(IconTheme.JabRefIcons.INTEGRITY_INFO);
31+
32+
actionFactory.configureIconButton(mergeAction, new SimpleCommand() {
33+
@Override
34+
public void execute() {
35+
// The info button is not meant to be clickable that's why this is empty
36+
}
37+
}, this);
38+
}
39+
40+
private void setInfoMessage(String infoMessage) {
41+
infoMessageProperty().set(infoMessage);
42+
}
43+
44+
public StringProperty infoMessageProperty() {
45+
return infoMessage;
46+
}
47+
48+
public String getInfoMessage() {
49+
return infoMessage.get();
50+
}
51+
}

src/main/resources/l10n/JabRef_en.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,3 +2526,6 @@ Merge\ %0=Merge %0
25262526
Right\ Entry=Right Entry
25272527
Unmerge\ %0=Unmerge %0
25282528
plain\ text=plain text
2529+
2530+
The\ %0s\ are\ the\ same.\ However,\ the\ order\ of\ field\ content\ differs=The %0s are the same. However, the order of field content differs
2531+

0 commit comments

Comments
 (0)