Skip to content

Commit c1707d9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into librarypropertiestofx
* upstream/master: Rework import inspection dialog in JavaFX (#4692) Use action handler (#4726) # Conflicts: # src/main/java/org/jabref/preferences/PreferencesService.java
2 parents e214240 + 1d4e2d1 commit c1707d9

33 files changed

+816
-1665
lines changed

src/main/java/org/jabref/Globals.java

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jabref.gui.ClipBoardManager;
1010
import org.jabref.gui.StateManager;
1111
import org.jabref.gui.keyboard.KeyBindingRepository;
12+
import org.jabref.gui.undo.CountingUndoManager;
1213
import org.jabref.gui.util.DefaultFileUpdateMonitor;
1314
import org.jabref.gui.util.DefaultTaskExecutor;
1415
import org.jabref.gui.util.TaskExecutor;
@@ -57,6 +58,7 @@ public class Globals {
5758

5859
public static StateManager stateManager = new StateManager();
5960
public static ExporterFactory exportFactory;
61+
public static CountingUndoManager undoManager = new CountingUndoManager();
6062
// Key binding preferences
6163
private static KeyBindingRepository keyBindingRepository;
6264
private static DefaultFileUpdateMonitor fileUpdateMonitor;

src/main/java/org/jabref/gui/Base.css

+34
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@
364364
-fx-fill: white;
365365
}
366366

367+
.toggle-button:selected.icon-button:selected {
368+
-fx-background-color: transparent;
369+
-fx-fill: -jr-selected;
370+
}
371+
367372
.icon-buttonNoSpaceBottom {
368373
-fx-padding: 0.5em 0.5em -0.1em 0.5em;
369374
}
@@ -976,6 +981,35 @@ We want to have a look that matches our icons in the tool-bar */
976981
-fx-border-width: 0px;
977982
}
978983

984+
.bibEntry {
985+
986+
}
987+
988+
.bibEntry .type {
989+
-fx-font-size: 110%;
990+
}
991+
992+
.bibEntry .title {
993+
-fx-font-size: 110%;
994+
-fx-font-weight: bold;
995+
}
996+
997+
.bibEntry .year {
998+
-fx-font-size: 101%;
999+
-fx-font-weight: bold;
1000+
}
1001+
1002+
.bibEntry .journal {
1003+
-fx-font-size: 101%;
1004+
}
1005+
1006+
.bibEntry .authors {
1007+
-fx-font-size: 101%;
1008+
}
1009+
1010+
.bibEntry .summary {
1011+
-fx-padding: 1ex 0ex 0ex 0ex;
1012+
}
9791013

9801014
.warning-icon {
9811015
-fx-fill: -jr-warn;

src/main/java/org/jabref/gui/DefaultInjector.java

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.function.Function;
44

5+
import javax.swing.undo.UndoManager;
6+
57
import org.jabref.Globals;
68
import org.jabref.gui.keyboard.KeyBindingRepository;
79
import org.jabref.gui.util.TaskExecutor;
@@ -43,6 +45,8 @@ private static Object createDependency(Class<?> clazz) {
4345
return Globals.protectedTermsLoader;
4446
} else if (clazz == ClipBoardManager.class) {
4547
return Globals.clipboardManager;
48+
} else if (clazz == UndoManager.class) {
49+
return Globals.undoManager;
4650
} else {
4751
try {
4852
return clazz.newInstance();

src/main/java/org/jabref/gui/DuplicateResolverDialog.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
import org.jabref.gui.util.BaseDialog;
1313
import org.jabref.logic.help.HelpFile;
1414
import org.jabref.logic.l10n.Localization;
15+
import org.jabref.model.database.BibDatabaseContext;
1516
import org.jabref.model.entry.BibEntry;
1617

1718
public class DuplicateResolverDialog extends BaseDialog<DuplicateResolverResult> {
1819

20+
private final BibDatabaseContext database;
21+
1922
public enum DuplicateResolverType {
2023
DUPLICATE_SEARCH,
2124
IMPORT_CHECK,
@@ -32,13 +35,12 @@ public enum DuplicateResolverResult {
3235
BREAK
3336
}
3437

35-
private final JabRefFrame frame;
3638
private MergeEntries me;
3739

38-
public DuplicateResolverDialog(JabRefFrame frame, BibEntry one, BibEntry two, DuplicateResolverType type) {
39-
this.frame = frame;
40+
public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType type, BibDatabaseContext database) {
4041
this.setTitle(Localization.lang("Possible duplicate entries"));
4142
init(one, two, type);
43+
this.database = database;
4244
}
4345

4446
private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
@@ -61,14 +63,14 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
6163
first = new ButtonType(Localization.lang("Keep left"), ButtonData.APPLY);
6264
second = new ButtonType(Localization.lang("Keep right"), ButtonData.APPLY);
6365
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
64-
me = new MergeEntries(one, two, frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
66+
me = new MergeEntries(one, two, database.getMode());
6567
break;
6668
case INSPECTION:
6769
first = new ButtonType(Localization.lang("Remove old entry"), ButtonData.APPLY);
6870
second = new ButtonType(Localization.lang("Remove entry from import"), ButtonData.APPLY);
6971
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
7072
me = new MergeEntries(one, two, Localization.lang("Old entry"),
71-
Localization.lang("From import"), frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
73+
Localization.lang("From import"), database.getMode());
7274
break;
7375
case DUPLICATE_SEARCH_WITH_EXACT:
7476
first = new ButtonType(Localization.lang("Keep left"), ButtonData.APPLY);
@@ -77,14 +79,14 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
7779

7880
removeExactVisible = true;
7981

80-
me = new MergeEntries(one, two, frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
82+
me = new MergeEntries(one, two, database.getMode());
8183
break;
8284
default:
8385
first = new ButtonType(Localization.lang("Import and remove old entry"), ButtonData.APPLY);
8486
second = new ButtonType(Localization.lang("Do not import entry"), ButtonData.APPLY);
8587
both = new ButtonType(Localization.lang("Import and keep old entry"), ButtonData.APPLY);
8688
me = new MergeEntries(one, two, Localization.lang("Old entry"),
87-
Localization.lang("From import"), frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
89+
Localization.lang("From import"), database.getMode());
8890
break;
8991
}
9092
if (removeExactVisible) {

src/main/java/org/jabref/gui/DuplicateSearch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private DuplicateSearchResult verifyDuplicates() {
122122
}
123123

124124
private void askResolveStrategy(DuplicateSearchResult result, BibEntry first, BibEntry second, DuplicateResolverType resolverType) {
125-
DuplicateResolverDialog dialog = new DuplicateResolverDialog(frame, first, second, resolverType);
125+
DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentBasePanel().getBibDatabaseContext());
126126

127127
DuplicateResolverResult resolverResult = dialog.showAndWait().orElse(DuplicateResolverResult.BREAK);
128128

src/main/java/org/jabref/gui/EntryTypeViewModel.java

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jabref.gui;
22

3-
import java.util.Arrays;
43
import java.util.Optional;
54

65
import javafx.beans.property.BooleanProperty;
@@ -15,7 +14,6 @@
1514
import javafx.concurrent.Task;
1615
import javafx.concurrent.Worker;
1716

18-
import org.jabref.gui.importer.ImportInspectionDialog;
1917
import org.jabref.logic.bibtex.DuplicateCheck;
2018
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
2119
import org.jabref.logic.importer.FetcherException;
@@ -138,18 +136,30 @@ public void runFetcherWorker() {
138136
fetcherWorker.setOnSucceeded(evt -> {
139137
Optional<BibEntry> result = fetcherWorker.getValue();
140138
if (result.isPresent()) {
141-
final BibEntry bibEntry = result.get();
142-
if ((DuplicateCheck.containsDuplicate(basePanel.getDatabase(), bibEntry, basePanel.getBibDatabaseContext().getMode()).isPresent())) {
143-
//If there are duplicates starts ImportInspectionDialog
144-
ImportInspectionDialog diag = new ImportInspectionDialog(basePanel.frame(), basePanel, Localization.lang("Import"), false);
145-
diag.addEntries(Arrays.asList(bibEntry));
146-
diag.entryListComplete();
147-
diag.setVisible(true);
148-
diag.toFront();
139+
final BibEntry entry = result.get();
140+
Optional<BibEntry> duplicate = DuplicateCheck.containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode());
141+
if ((duplicate.isPresent())) {
142+
DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext());
143+
switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) {
144+
case KEEP_LEFT:
145+
basePanel.getDatabase().removeEntry(duplicate.get());
146+
basePanel.getDatabase().insertEntry(entry);
147+
break;
148+
case KEEP_BOTH:
149+
basePanel.getDatabase().insertEntry(entry);
150+
break;
151+
case KEEP_MERGE:
152+
basePanel.getDatabase().removeEntry(duplicate.get());
153+
basePanel.getDatabase().insertEntry(dialog.getMergedEntry());
154+
break;
155+
default:
156+
// Do nothing
157+
break;
158+
}
149159
} else {
150160
// Regenerate CiteKey of imported BibEntry
151-
new BibtexKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(bibEntry);
152-
basePanel.insertEntry(bibEntry);
161+
new BibtexKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry);
162+
basePanel.insertEntry(entry);
153163
}
154164
searchSuccesfulProperty.set(true);
155165

src/main/java/org/jabref/gui/JabRefFrame.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
import org.jabref.gui.help.AboutAction;
9494
import org.jabref.gui.help.HelpAction;
9595
import org.jabref.gui.importer.ImportCommand;
96-
import org.jabref.gui.importer.ImportInspectionDialog;
96+
import org.jabref.gui.importer.ImportEntriesDialog;
9797
import org.jabref.gui.importer.actions.OpenDatabaseAction;
9898
import org.jabref.gui.integrity.IntegrityCheckAction;
9999
import org.jabref.gui.keyboard.KeyBinding;
@@ -107,6 +107,7 @@
107107
import org.jabref.gui.search.GlobalSearchBar;
108108
import org.jabref.gui.specialfields.SpecialFieldMenuItemFactory;
109109
import org.jabref.gui.undo.CountingUndoManager;
110+
import org.jabref.gui.util.BackgroundTask;
110111
import org.jabref.gui.util.DefaultTaskExecutor;
111112
import org.jabref.logic.autosaveandbackup.AutosaveManager;
112113
import org.jabref.logic.autosaveandbackup.BackupManager;
@@ -179,7 +180,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter {
179180
private SidePaneManager sidePaneManager;
180181
private TabPane tabbedPane;
181182
private PushToApplications pushApplications;
182-
private final CountingUndoManager undoManager = new CountingUndoManager();
183183
private final DialogService dialogService;
184184
private SidePane sidePane;
185185

@@ -785,7 +785,7 @@ private MenuBar createMenu() {
785785
if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) {
786786
boolean menuItemAdded = false;
787787
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
788-
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager));
788+
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, Globals.undoManager));
789789
menuItemAdded = true;
790790
}
791791

@@ -805,12 +805,12 @@ private MenuBar createMenu() {
805805
}
806806

807807
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
808-
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager));
808+
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, Globals.undoManager));
809809
menuItemAdded = true;
810810
}
811811

812812
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
813-
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager));
813+
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, Globals.undoManager));
814814
menuItemAdded = true;
815815
}
816816

@@ -1204,21 +1204,16 @@ private boolean readyForAutosave(BibDatabaseContext context) {
12041204
}
12051205

12061206
/**
1207-
* This method does the job of adding imported entries into the active database, or into a new one. It shows the
1208-
* ImportInspectionDialog if preferences indicate it should be used. Otherwise it imports directly.
1207+
* Opens the import inspection dialog to let the user decide which of the given entries to import.
12091208
*
12101209
* @param panel The BasePanel to add to.
12111210
* @param entries The entries to add.
12121211
*/
12131212
private void addImportedEntries(final BasePanel panel, final List<BibEntry> entries) {
1214-
SwingUtilities.invokeLater(() -> {
1215-
ImportInspectionDialog diag = new ImportInspectionDialog(JabRefFrame.this, panel,
1216-
Localization.lang("Import"), false);
1217-
diag.addEntries(entries);
1218-
diag.entryListComplete();
1219-
diag.setVisible(true);
1220-
diag.toFront();
1221-
});
1213+
BackgroundTask<List<BibEntry>> task = BackgroundTask.wrap(() -> entries);
1214+
ImportEntriesDialog dialog = new ImportEntriesDialog(panel.getBibDatabaseContext(), task);
1215+
dialog.setTitle(Localization.lang("Import"));
1216+
dialog.showAndWait();
12221217
}
12231218

12241219
public FileHistoryMenu getFileHistory() {
@@ -1389,7 +1384,7 @@ public GlobalSearchBar getGlobalSearchBar() {
13891384
}
13901385

13911386
public CountingUndoManager getUndoManager() {
1392-
return undoManager;
1387+
return Globals.undoManager;
13931388
}
13941389

13951390
public DialogService getDialogService() {

src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public FindUnlinkedFilesDialog(JabRefFrame frame) {
9292
Globals.prefs.getImportFormatPreferences(),
9393
Globals.prefs.getUpdateFieldPreferences(),
9494
Globals.getFileUpdateMonitor(),
95-
frame.getUndoManager()
96-
);
95+
frame.getUndoManager(),
96+
Globals.stateManager);
9797

9898
initialize();
9999
}

0 commit comments

Comments
 (0)