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

Rework import inspection dialog in JavaFX #4692

Merged
merged 4 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class Globals {

public static StateManager stateManager = new StateManager();
public static ExporterFactory exportFactory;
public static CountingUndoManager undoManager = new CountingUndoManager();
// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
private static DefaultFileUpdateMonitor fileUpdateMonitor;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@
-fx-fill: white;
}

.toggle-button:selected.icon-button:selected {
-fx-background-color: transparent;
-fx-fill: -jr-selected;
}

.icon-buttonNoSpaceBottom {
-fx-padding: 0.5em 0.5em -0.1em 0.5em;
}
Expand Down Expand Up @@ -976,6 +981,35 @@ We want to have a look that matches our icons in the tool-bar */
-fx-border-width: 0px;
}

.bibEntry {

}

.bibEntry .type {
-fx-font-size: 110%;
}

.bibEntry .title {
-fx-font-size: 110%;
-fx-font-weight: bold;
}

.bibEntry .year {
-fx-font-size: 101%;
-fx-font-weight: bold;
}

.bibEntry .journal {
-fx-font-size: 101%;
}

.bibEntry .authors {
-fx-font-size: 101%;
}

.bibEntry .summary {
-fx-padding: 1ex 0ex 0ex 0ex;
}

.warning-icon {
-fx-fill: -jr-warn;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.function.Function;

import javax.swing.undo.UndoManager;

import org.jabref.Globals;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
Expand Down Expand Up @@ -43,6 +45,8 @@ private static Object createDependency(Class<?> clazz) {
return Globals.protectedTermsLoader;
} else if (clazz == ClipBoardManager.class) {
return Globals.clipboardManager;
} else if (clazz == UndoManager.class) {
return Globals.undoManager;
} else {
try {
return clazz.newInstance();
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/jabref/gui/DuplicateResolverDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

public class DuplicateResolverDialog extends BaseDialog<DuplicateResolverResult> {

private final BibDatabaseContext database;

public enum DuplicateResolverType {
DUPLICATE_SEARCH,
IMPORT_CHECK,
Expand All @@ -32,13 +35,12 @@ public enum DuplicateResolverResult {
BREAK
}

private final JabRefFrame frame;
private MergeEntries me;

public DuplicateResolverDialog(JabRefFrame frame, BibEntry one, BibEntry two, DuplicateResolverType type) {
this.frame = frame;
public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType type, BibDatabaseContext database) {
this.setTitle(Localization.lang("Possible duplicate entries"));
init(one, two, type);
this.database = database;
}

private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
Expand All @@ -61,14 +63,14 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {
first = new ButtonType(Localization.lang("Keep left"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Keep right"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
me = new MergeEntries(one, two, frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
me = new MergeEntries(one, two, database.getMode());
break;
case INSPECTION:
first = new ButtonType(Localization.lang("Remove old entry"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Remove entry from import"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Keep both"), ButtonData.APPLY);
me = new MergeEntries(one, two, Localization.lang("Old entry"),
Localization.lang("From import"), frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
Localization.lang("From import"), database.getMode());
break;
case DUPLICATE_SEARCH_WITH_EXACT:
first = new ButtonType(Localization.lang("Keep left"), ButtonData.APPLY);
Expand All @@ -77,14 +79,14 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) {

removeExactVisible = true;

me = new MergeEntries(one, two, frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
me = new MergeEntries(one, two, database.getMode());
break;
default:
first = new ButtonType(Localization.lang("Import and remove old entry"), ButtonData.APPLY);
second = new ButtonType(Localization.lang("Do not import entry"), ButtonData.APPLY);
both = new ButtonType(Localization.lang("Import and keep old entry"), ButtonData.APPLY);
me = new MergeEntries(one, two, Localization.lang("Old entry"),
Localization.lang("From import"), frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
Localization.lang("From import"), database.getMode());
break;
}
if (removeExactVisible) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/DuplicateSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private DuplicateSearchResult verifyDuplicates() {
}

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

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

Expand Down
34 changes: 22 additions & 12 deletions src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui;

import java.util.Arrays;
import java.util.Optional;

import javafx.beans.property.BooleanProperty;
Expand All @@ -15,7 +14,6 @@
import javafx.concurrent.Task;
import javafx.concurrent.Worker;

import org.jabref.gui.importer.ImportInspectionDialog;
import org.jabref.logic.bibtex.DuplicateCheck;
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
import org.jabref.logic.importer.FetcherException;
Expand Down Expand Up @@ -138,18 +136,30 @@ public void runFetcherWorker() {
fetcherWorker.setOnSucceeded(evt -> {
Optional<BibEntry> result = fetcherWorker.getValue();
if (result.isPresent()) {
final BibEntry bibEntry = result.get();
if ((DuplicateCheck.containsDuplicate(basePanel.getDatabase(), bibEntry, basePanel.getBibDatabaseContext().getMode()).isPresent())) {
//If there are duplicates starts ImportInspectionDialog
ImportInspectionDialog diag = new ImportInspectionDialog(basePanel.frame(), basePanel, Localization.lang("Import"), false);
diag.addEntries(Arrays.asList(bibEntry));
diag.entryListComplete();
diag.setVisible(true);
diag.toFront();
final BibEntry entry = result.get();
Optional<BibEntry> duplicate = DuplicateCheck.containsDuplicate(basePanel.getDatabase(), entry, basePanel.getBibDatabaseContext().getMode());
if ((duplicate.isPresent())) {
DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, basePanel.getBibDatabaseContext());
switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) {
case KEEP_LEFT:
basePanel.getDatabase().removeEntry(duplicate.get());
basePanel.getDatabase().insertEntry(entry);
break;
case KEEP_BOTH:
basePanel.getDatabase().insertEntry(entry);
break;
case KEEP_MERGE:
basePanel.getDatabase().removeEntry(duplicate.get());
basePanel.getDatabase().insertEntry(dialog.getMergedEntry());
break;
default:
// Do nothing
break;
}
} else {
// Regenerate CiteKey of imported BibEntry
new BibtexKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(bibEntry);
basePanel.insertEntry(bibEntry);
new BibtexKeyGenerator(basePanel.getBibDatabaseContext(), prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(entry);
basePanel.insertEntry(entry);
}
searchSuccesfulProperty.set(true);

Expand Down
27 changes: 11 additions & 16 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import org.jabref.gui.help.AboutAction;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.importer.ImportCommand;
import org.jabref.gui.importer.ImportInspectionDialog;
import org.jabref.gui.importer.ImportEntriesDialog;
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.integrity.IntegrityCheckAction;
import org.jabref.gui.keyboard.KeyBinding;
Expand All @@ -107,6 +107,7 @@
import org.jabref.gui.search.GlobalSearchBar;
import org.jabref.gui.specialfields.SpecialFieldMenuItemFactory;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.autosaveandbackup.AutosaveManager;
import org.jabref.logic.autosaveandbackup.BackupManager;
Expand Down Expand Up @@ -179,7 +180,6 @@ public class JabRefFrame extends BorderPane implements OutputPrinter {
private SidePaneManager sidePaneManager;
private TabPane tabbedPane;
private PushToApplications pushApplications;
private final CountingUndoManager undoManager = new CountingUndoManager();
private final DialogService dialogService;
private SidePane sidePane;

Expand Down Expand Up @@ -785,7 +785,7 @@ private MenuBar createMenu() {
if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) {
boolean menuItemAdded = false;
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager));
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, Globals.undoManager));
menuItemAdded = true;
}

Expand All @@ -805,12 +805,12 @@ private MenuBar createMenu() {
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager));
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, Globals.undoManager));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager));
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, Globals.undoManager));
menuItemAdded = true;
}

Expand Down Expand Up @@ -1204,21 +1204,16 @@ private boolean readyForAutosave(BibDatabaseContext context) {
}

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

public FileHistoryMenu getFileHistory() {
Expand Down Expand Up @@ -1389,7 +1384,7 @@ public GlobalSearchBar getGlobalSearchBar() {
}

public CountingUndoManager getUndoManager() {
return undoManager;
return Globals.undoManager;
}

public DialogService getDialogService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public FindUnlinkedFilesDialog(JabRefFrame frame) {
Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getUpdateFieldPreferences(),
Globals.getFileUpdateMonitor(),
frame.getUndoManager()
);
frame.getUndoManager(),
Globals.stateManager);

initialize();
}
Expand Down
Loading