Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-for-issue-8189
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix missing CSS for some dialogs (JabRef#9150)
  Bump org.eclipse.jgit from 6.2.0.202206071550-r to 6.3.0.202209071007-r (JabRef#9152)
  Bump mockito-core from 4.7.0 to 4.8.0 (JabRef#9151)
  [GSOC22] - D - Test the Three Way Merge UI (JabRef#9069)
  • Loading branch information
Siedlerchr committed Sep 12, 2022
2 parents 9150938 + 9604f7d commit b81c1a5
Show file tree
Hide file tree
Showing 23 changed files with 719 additions and 297 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where title case didn't capitalize words after en-dash characters and skip capitalization of conjunctions that comes after en-dash characters. [#9068](https://github.com/JabRef/jabref/pull/9068),[#9142](https://github.com/JabRef/jabref/pull/9142)
- We fixed an issue where JabRef would not exit when a connection to a LibreOffice document was established previously and the document is still open. [#9075](https://github.com/JabRef/jabref/issues/9075)
- We fixed an issue about selecting the save order in the preferences. [#9175](https://github.com/JabRef/jabref/issues/9147)
- We fixed an issue where the CSS styles are missing in some dialogs. [#9150](https://github.com/JabRef/jabref/pull/9150)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ dependencies {
antlr4 'org.antlr:antlr4:4.9.3'
implementation 'org.antlr:antlr4-runtime:4.9.3'

implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.2.0.202206071550-r'
implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.3.0.202209071007-r'

implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.13.4'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.13.4'
Expand Down Expand Up @@ -207,7 +207,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.9.0'

testImplementation 'org.mockito:mockito-core:4.7.0'
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'org.xmlunit:xmlunit-core:2.9.0'
testImplementation 'org.xmlunit:xmlunit-matchers:2.9.0'
testRuntimeOnly 'com.tngtech.archunit:archunit-junit5-engine:0.23.1'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public JabRefFrame(Stage mainStage) {
this.themeManager = Globals.getThemeManager();
this.dialogService = new JabRefDialogService(mainStage, this, themeManager);
this.undoManager = Globals.undoManager;
this.globalSearchBar = new GlobalSearchBar(this, stateManager, prefs, undoManager);
this.globalSearchBar = new GlobalSearchBar(this, stateManager, prefs, undoManager, dialogService);
this.pushToApplicationCommand = new PushToApplicationCommand(stateManager, dialogService, prefs);
this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction());
this.taskExecutor = Globals.TASK_EXECUTOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public ValidationStatus fileExistsValidationStatus() {
public void parsePdfMetadataAndShowMergeDialog() {
linkedFile.findIn(databaseContext, preferences.getFilePreferences()).ifPresent(filePath -> {
MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor);
dialog.setTitle(Localization.lang("Merge PDF metadata"));
dialog.addSource(Localization.lang("Entry"), entry);
dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath));
dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath));
Expand All @@ -565,7 +566,7 @@ public void parsePdfMetadataAndShowMergeDialog() {
}
dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath));
dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferences.getImportFormatPreferences()), filePath));
dialog.showAndWait().ifPresent(newEntry -> {
dialogService.showCustomDialogAndWait(dialog).ifPresent(newEntry -> {
databaseContext.getDatabase().removeEntry(entry);
databaseContext.getDatabase().insertEntry(newEntry);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package org.jabref.gui.mergeentries.newmergedialog;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
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;

import org.jabref.gui.actions.SimpleCommand;
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.cell.sidebuttons.ToggleMergeUnmergeButton;
import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.SplitDiffHighlighter;
import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.UnifiedDiffHighlighter;
import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMerger;
import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory;
import org.jabref.gui.mergeentries.newmergedialog.toolbar.ThreeWayMergeToolbar;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -48,10 +41,8 @@ public class FieldRowView {

private final ToggleGroup toggleGroup = new ToggleGroup();

private final CompoundEdit fieldsMergedEdit = new CompoundEdit();

public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) {
viewModel = new FieldRowViewModel(field, leftEntry, rightEntry, mergedEntry);
viewModel = new FieldRowViewModel(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory);

fieldNameCell = new FieldNameCell(field.getDisplayName(), rowIndex);
leftValueCell = new FieldValueCell(viewModel.getLeftFieldValue(), rowIndex);
Expand All @@ -66,9 +57,9 @@ public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEnt
EasyBind.listen(toggleMergeUnmergeButton.fieldStateProperty(), ((observableValue, old, fieldState) -> {
LOGGER.debug("Field merge state is {} for field {}", fieldState, field);
if (fieldState == ToggleMergeUnmergeButton.FieldState.MERGED) {
new MergeCommand(fieldMergerFactory.create(field)).execute();
viewModel.mergeFields();
} else {
new UnmergeCommand().execute();
viewModel.unmergeFields();
}
}));
}
Expand Down Expand Up @@ -188,71 +179,4 @@ public void hideDiff() {
getRightValueCell().getStyleClassedLabel().clearStyle(0, rightValueLength);
getRightValueCell().getStyleClassedLabel().replaceText(viewModel.getRightFieldValue());
}

public class MergeCommand extends SimpleCommand {
private final FieldMerger fieldMerger;

public MergeCommand(FieldMerger fieldMerger) {
this.fieldMerger = fieldMerger;

this.executable.bind(viewModel.hasEqualLeftAndRightBinding().not());
}

@Override
public void execute() {
assert !viewModel.getLeftFieldValue().equals(viewModel.getRightFieldValue());

String oldLeftFieldValue = viewModel.getLeftFieldValue();
String oldRightFieldValue = viewModel.getRightFieldValue();

String mergedFields = fieldMerger.merge(viewModel.getLeftFieldValue(), viewModel.getRightFieldValue());
viewModel.setLeftFieldValue(mergedFields);
viewModel.setRightFieldValue(mergedFields);

if (fieldsMergedEdit.canRedo()) {
fieldsMergedEdit.redo();
} else {
fieldsMergedEdit.addEdit(new MergeFieldsUndo(oldLeftFieldValue, oldRightFieldValue, mergedFields));
fieldsMergedEdit.end();
}
}
}

public class UnmergeCommand extends SimpleCommand {

public UnmergeCommand() { }

@Override
public void execute() {
if (fieldsMergedEdit.canUndo()) {
fieldsMergedEdit.undo();
}
}
}

class MergeFieldsUndo extends AbstractUndoableEdit {
private final String oldLeft;
private final String oldRight;
private final String mergedFields;

MergeFieldsUndo(String oldLeft, String oldRight, String mergedFields) {
this.oldLeft = oldLeft;
this.oldRight = oldRight;
this.mergedFields = mergedFields;
}

@Override
public void undo() throws CannotUndoException {
super.undo();
viewModel.setLeftFieldValue(oldLeft);
viewModel.setRightFieldValue(oldRight);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
viewModel.setLeftFieldValue(mergedFields);
viewModel.setRightFieldValue(mergedFields);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.jabref.gui.mergeentries.newmergedialog;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.CompoundEdit;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
Expand All @@ -9,6 +14,8 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMerger;
import org.jabref.gui.mergeentries.newmergedialog.fieldsmerger.FieldMergerFactory;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
Expand Down Expand Up @@ -49,11 +56,16 @@ public enum Selection {

private final BooleanBinding hasEqualLeftAndRight;

public FieldRowViewModel(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry) {
private final FieldMergerFactory fieldMergerFactory;

private final CompoundEdit fieldsMergedEdit = new CompoundEdit();

public FieldRowViewModel(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory) {
this.field = field;
this.leftEntry = leftEntry;
this.rightEntry = rightEntry;
this.mergedEntry = mergedEntry;
this.fieldMergerFactory = fieldMergerFactory;

if (field.equals(InternalField.TYPE_HEADER)) {
setLeftFieldValue(leftEntry.getType().getDisplayName());
Expand Down Expand Up @@ -125,7 +137,7 @@ public void selectLeftValue() {
}

public void selectRightValue() {
if (isIsFieldsMerged()) {
if (isFieldsMerged()) {
selectLeftValue();
} else {
setSelection(Selection.RIGHT);
Expand All @@ -148,8 +160,33 @@ public String getMergedFieldValue() {
return mergedFieldValue.get();
}

public void merge() {
setIsFieldsMerged(true);
public void mergeFields() {
assert !hasEqualLeftAndRightValues();

if (!FieldMergerFactory.canMerge(field)) {
throw new UnsupportedOperationException();
}

String oldLeftFieldValue = getLeftFieldValue();
String oldRightFieldValue = getRightFieldValue();

FieldMerger fieldMerger = fieldMergerFactory.create(field);
String mergedFields = fieldMerger.merge(getLeftFieldValue(), getRightFieldValue());
setLeftFieldValue(mergedFields);
setRightFieldValue(mergedFields);

if (fieldsMergedEdit.canRedo()) {
fieldsMergedEdit.redo();
} else {
fieldsMergedEdit.addEdit(new MergeFieldsUndo(oldLeftFieldValue, oldRightFieldValue, mergedFields));
fieldsMergedEdit.end();
}
}

public void unmergeFields() {
if (fieldsMergedEdit.canUndo()) {
fieldsMergedEdit.undo();
}
}

public BooleanBinding hasEqualLeftAndRightBinding() {
Expand All @@ -168,7 +205,7 @@ public Selection getSelection() {
return selectionProperty().get();
}

public boolean isIsFieldsMerged() {
public boolean isFieldsMerged() {
return isFieldsMerged.get();
}

Expand Down Expand Up @@ -219,4 +256,30 @@ public BibEntry getRightEntry() {
public BibEntry getMergedEntry() {
return mergedEntry;
}

class MergeFieldsUndo extends AbstractUndoableEdit {
private final String oldLeft;
private final String oldRight;
private final String mergedFields;

MergeFieldsUndo(String oldLeft, String oldRight, String mergedFields) {
this.oldLeft = oldLeft;
this.oldRight = oldRight;
this.mergedFields = mergedFields;
}

@Override
public void undo() throws CannotUndoException {
super.undo();
setLeftFieldValue(oldLeft);
setRightFieldValue(oldRight);
}

@Override
public void redo() throws CannotRedoException {
super.redo();
setLeftFieldValue(mergedFields);
setRightFieldValue(mergedFields);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
-fx-background-color: -jr-row-even-background;
}

.field-cell {
-fx-padding: 8;
}

.merge-toolbox {
-fx-background-color: -jr-menu-background;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ private void initializeColumnConstraints() {
private void initializeMergeGridPane() {
mergeGridPane.getColumnConstraints().addAll(fieldNameColumnConstraints, leftEntryColumnConstraints, rightEntryColumnConstraints, mergedEntryColumnConstraints);

for (int fieldIndex = 0; fieldIndex < viewModel.allFieldsSize(); fieldIndex++) {
for (int fieldIndex = 0; fieldIndex < viewModel.numberOfVisibleFields(); fieldIndex++) {
addRow(fieldIndex);

mergeGridPane.getRowConstraints().add(new RowConstraints());
}
}

private Field getFieldAtIndex(int index) {
return viewModel.allFields().get(index);
return viewModel.getVisibleFields().get(index);
}

private void addRow(int fieldIndex) {
Expand Down
Loading

0 comments on commit b81c1a5

Please sign in to comment.