diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java
index e94e6fe8697..4f18a03b9e6 100644
--- a/src/main/java/org/jabref/gui/DefaultInjector.java
+++ b/src/main/java/org/jabref/gui/DefaultInjector.java
@@ -6,6 +6,7 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
+import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
@@ -38,6 +39,8 @@ private static Object createDependency(Class> clazz) {
return Globals.stateManager;
} else if (clazz == FileUpdateMonitor.class) {
return Globals.getFileUpdateMonitor();
+ } else if (clazz == ProtectedTermsLoader.class) {
+ return Globals.protectedTermsLoader;
} else if (clazz == ClipBoardManager.class) {
return Globals.clipboardManager;
} else {
diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java
index 8346fe58e7f..3f671c91904 100644
--- a/src/main/java/org/jabref/gui/JabRefFrame.java
+++ b/src/main/java/org/jabref/gui/JabRefFrame.java
@@ -69,7 +69,6 @@
import org.jabref.gui.actions.ManageCustomImportsAction;
import org.jabref.gui.actions.ManageJournalsAction;
import org.jabref.gui.actions.ManageKeywordsAction;
-import org.jabref.gui.actions.ManageProtectedTermsAction;
import org.jabref.gui.actions.NewDatabaseAction;
import org.jabref.gui.actions.NewEntryAction;
import org.jabref.gui.actions.NewEntryFromPlainTextAction;
@@ -101,6 +100,7 @@
import org.jabref.gui.mergeentries.MergeEntriesAction;
import org.jabref.gui.metadata.BibtexStringEditorAction;
import org.jabref.gui.metadata.PreambleEditor;
+import org.jabref.gui.protectedterms.ManageProtectedTermsAction;
import org.jabref.gui.push.PushToApplicationButton;
import org.jabref.gui.push.PushToApplications;
import org.jabref.gui.search.GlobalSearchBar;
@@ -937,7 +937,7 @@ private MenuBar createMenu() {
factory.createMenuItem(StandardActions.MANAGE_EXTERNAL_FILETYPES, new EditExternalFileTypesAction()),
factory.createMenuItem(StandardActions.MANAGE_JOURNALS, new ManageJournalsAction()),
factory.createMenuItem(StandardActions.CUSTOMIZE_KEYBINDING, new CustomizeKeyBindingAction()),
- factory.createMenuItem(StandardActions.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction(this, Globals.protectedTermsLoader)),
+ factory.createMenuItem(StandardActions.MANAGE_PROTECTED_TERMS, new ManageProtectedTermsAction()),
new SeparatorMenuItem(),
diff --git a/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java b/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java
deleted file mode 100644
index c4f05f955cf..00000000000
--- a/src/main/java/org/jabref/gui/actions/ManageProtectedTermsAction.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.jabref.gui.actions;
-
-import org.jabref.gui.JabRefFrame;
-import org.jabref.gui.protectedterms.ProtectedTermsDialog;
-import org.jabref.logic.protectedterms.ProtectedTermsLoader;
-
-public class ManageProtectedTermsAction extends SimpleCommand {
-
- private final JabRefFrame jabRefFrame;
- private final ProtectedTermsLoader termsLoader;
-
- public ManageProtectedTermsAction(JabRefFrame jabRefFrame, ProtectedTermsLoader termsLoader) {
- this.jabRefFrame = jabRefFrame;
- this.termsLoader = termsLoader;
- }
- @Override
- public void execute() {
- ProtectedTermsDialog protectTermsDialog = new ProtectedTermsDialog(jabRefFrame);
- protectTermsDialog.setVisible(true);
-
- }
-
-}
diff --git a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java
index 4af7fec8023..85bd758232d 100644
--- a/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java
+++ b/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ProtectedTermsMenu.java
@@ -3,16 +3,12 @@
import java.util.List;
import java.util.stream.Collectors;
-import javax.swing.SwingUtilities;
-
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextInputControl;
import org.jabref.Globals;
-import org.jabref.JabRefGUI;
-import org.jabref.gui.protectedterms.NewProtectedTermsFileDialog;
import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.protectedterms.ProtectedTermsList;
@@ -65,21 +61,5 @@ private void updateFiles() {
externalFiles.getItems().add(fileItem);
}
externalFiles.getItems().add(new SeparatorMenuItem());
- MenuItem addToNewFileItem = new MenuItem(Localization.lang("New") + "...");
- addToNewFileItem.setOnAction(event -> {
- NewProtectedTermsFileDialog dialog = new NewProtectedTermsFileDialog(JabRefGUI.getMainFrame().getDialogService(),
- loader);
-
- SwingUtilities.invokeLater(() -> {
- dialog.setVisible(true);
-
- if (dialog.isOKPressed()) {
- // Update preferences with new list
- Globals.prefs.setProtectedTermsPreferences(loader);
- this.updateFiles();
- }
- });
- });
- externalFiles.getItems().add(addToNewFileItem);
}
}
diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java
new file mode 100644
index 00000000000..34f4ff3f116
--- /dev/null
+++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java
@@ -0,0 +1,12 @@
+package org.jabref.gui.protectedterms;
+
+import org.jabref.gui.actions.SimpleCommand;
+
+public class ManageProtectedTermsAction extends SimpleCommand {
+
+ @Override
+ public void execute() {
+ ManageProtectedTermsDialog protectTermsDialog = new ManageProtectedTermsDialog();
+ protectTermsDialog.showAndWait();
+ }
+}
diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.fxml b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.fxml
new file mode 100644
index 00000000000..0b23bc0ccaf
--- /dev/null
+++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.fxml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.java
new file mode 100644
index 00000000000..474304d2383
--- /dev/null
+++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsDialog.java
@@ -0,0 +1,128 @@
+package org.jabref.gui.protectedterms;
+
+import javax.inject.Inject;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.cell.CheckBoxTableCell;
+
+import org.jabref.gui.DialogService;
+import org.jabref.gui.icon.IconTheme;
+import org.jabref.gui.util.BaseDialog;
+import org.jabref.gui.util.BindingsHelper;
+import org.jabref.gui.util.ValueTableCellFactory;
+import org.jabref.gui.util.ViewModelTableRowFactory;
+import org.jabref.logic.l10n.Localization;
+import org.jabref.logic.protectedterms.ProtectedTermsList;
+import org.jabref.logic.protectedterms.ProtectedTermsLoader;
+import org.jabref.preferences.PreferencesService;
+
+import com.airhacks.afterburner.views.ViewLoader;
+
+/**
+ * Dialog for managing term list files.
+ */
+public class ManageProtectedTermsDialog extends BaseDialog {
+
+ @FXML private TableView filesTable;
+ @FXML private TableColumn filesTableEnabledColumn;
+ @FXML private TableColumn filesTableDescriptionColumn;
+ @FXML private TableColumn filesTableFileColumn;
+ @FXML private TableColumn filesTableEditColumn;
+ @FXML private TableColumn filesTableDeleteColumn;
+
+ @Inject private ProtectedTermsLoader termsLoader;
+ @Inject private DialogService dialogService;
+ @Inject private PreferencesService preferences;
+ private ManageProtectedTermsViewModel viewModel;
+
+ public ManageProtectedTermsDialog() {
+ this.setTitle(Localization.lang("Manage protected terms files"));
+
+ ViewLoader.view(this)
+ .load()
+ .setAsDialogPane(this);
+
+ setResultConverter(button -> {
+ if (button == ButtonType.APPLY) {
+ viewModel.save();
+ }
+ return null;
+ });
+ }
+
+ @FXML
+ public void initialize() {
+ viewModel = new ManageProtectedTermsViewModel(termsLoader, dialogService, preferences);
+
+ filesTable.setItems(viewModel.getTermsFiles());
+ new ViewModelTableRowFactory()
+ .withContextMenu(this::createContextMenu)
+ .install(filesTable);
+ filesTableEnabledColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().isEnabled()));
+ filesTableEnabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(filesTableEnabledColumn));
+ filesTableDescriptionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getDescription()));
+ filesTableFileColumn.setCellValueFactory(data -> {
+ ProtectedTermsList list = data.getValue();
+ if (list.isInternalList()) {
+ return BindingsHelper.constantOf(Localization.lang("Internal list"));
+ } else {
+ return BindingsHelper.constantOf(data.getValue().getLocation());
+ }
+ });
+ filesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true));
+ filesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true));
+
+ new ValueTableCellFactory()
+ .withGraphic(none -> IconTheme.JabRefIcons.EDIT.getGraphicNode())
+ .withOnMouseClickedEvent((file, none) -> event -> viewModel.edit(file))
+ .install(filesTableEditColumn);
+ new ValueTableCellFactory()
+ .withGraphic(none -> IconTheme.JabRefIcons.REMOVE.getGraphicNode())
+ .withTooltip(none -> Localization.lang("Remove protected terms file"))
+ .withOnMouseClickedEvent((file, none) -> event -> viewModel.removeFile(file))
+ .install(filesTableDeleteColumn);
+ }
+
+ private ContextMenu createContextMenu(ProtectedTermsList file) {
+ MenuItem edit = new MenuItem(Localization.lang("Edit"));
+ edit.setOnAction(event -> viewModel.edit(file));
+ MenuItem show = new MenuItem(Localization.lang("View"));
+ show.setOnAction(event -> viewModel.displayContent(file));
+ MenuItem remove = new MenuItem(Localization.lang("Remove"));
+ remove.setOnAction(event -> viewModel.removeFile(file));
+ MenuItem reload = new MenuItem(Localization.lang("Reload"));
+ reload.setOnAction(event -> viewModel.reloadFile(file));
+
+ // Enable/disable context menu items
+ if (file.isInternalList()) {
+ edit.setDisable(true);
+ show.setDisable(false);
+ remove.setDisable(true);
+ reload.setDisable(true);
+ } else {
+ edit.setDisable(false);
+ show.setDisable(false);
+ remove.setDisable(false);
+ reload.setDisable(false);
+ }
+
+ final ContextMenu contextMenu = new ContextMenu();
+ contextMenu.getItems().addAll(edit, show, remove, reload);
+ return contextMenu;
+ }
+
+ @FXML
+ private void addFile() {
+ viewModel.addFile();
+ }
+
+ @FXML
+ private void createNewFile() {
+ viewModel.createNewFile();
+ }
+}
diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java
new file mode 100644
index 00000000000..3fca8b6e63b
--- /dev/null
+++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java
@@ -0,0 +1,99 @@
+package org.jabref.gui.protectedterms;
+
+import java.io.IOException;
+import java.util.Optional;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+
+import org.jabref.gui.DialogService;
+import org.jabref.gui.desktop.JabRefDesktop;
+import org.jabref.gui.externalfiletype.ExternalFileType;
+import org.jabref.gui.externalfiletype.ExternalFileTypes;
+import org.jabref.gui.util.FileDialogConfiguration;
+import org.jabref.logic.l10n.Localization;
+import org.jabref.logic.protectedterms.ProtectedTermsList;
+import org.jabref.logic.protectedterms.ProtectedTermsLoader;
+import org.jabref.logic.util.StandardFileType;
+import org.jabref.model.database.BibDatabaseContext;
+import org.jabref.model.util.OptionalUtil;
+import org.jabref.preferences.PreferencesService;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ManageProtectedTermsViewModel {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ManageProtectedTermsViewModel.class);
+
+ private final ProtectedTermsLoader termsLoader;
+ private final ObservableList termsFiles;
+ private final PreferencesService preferences;
+ private final DialogService dialogService;
+
+ public ManageProtectedTermsViewModel(ProtectedTermsLoader termsLoader, DialogService dialogService, PreferencesService preferences) {
+ this.termsLoader = termsLoader;
+ this.dialogService = dialogService;
+ this.termsFiles = FXCollections.observableArrayList(termsLoader.getProtectedTermsLists());
+ this.preferences = preferences;
+ }
+
+ public ObservableList getTermsFiles() {
+ return termsFiles;
+ }
+
+ public void save() {
+ preferences.setProtectedTermsPreferences(termsLoader);
+ }
+
+ public void addFile() {
+ FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
+ .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS)
+ .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS)
+ .withInitialDirectory(preferences.getWorkingDir())
+ .build();
+
+ dialogService.showFileOpenDialog(fileDialogConfiguration)
+ .ifPresent(file -> termsLoader.addProtectedTermsListFromFile(file.toAbsolutePath().toString(), true));
+ }
+
+ public void removeFile(ProtectedTermsList list) {
+ if (!list.isInternalList() && dialogService.showConfirmationDialogAndWait(Localization.lang("Remove protected terms file"),
+ Localization.lang("Are you sure you want to remove the protected terms file?"),
+ Localization.lang("Remove protected terms file"),
+ Localization.lang("Cancel"))) {
+ if (!termsLoader.removeProtectedTermsList(list)) {
+ LOGGER.info("Problem removing protected terms file");
+ }
+ }
+ }
+
+ public void createNewFile() {
+ NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(termsLoader, dialogService);
+ newDialog.showAndWait();
+ }
+
+ public void edit(ProtectedTermsList file) {
+ Optional termsFileType = OptionalUtil.orElse(
+ ExternalFileTypes.getInstance().getExternalFileTypeByExt("terms"),
+ ExternalFileTypes.getInstance().getExternalFileTypeByExt("txt")
+ );
+
+ String fileName = file.getLocation();
+ try {
+ JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, termsFileType);
+ } catch (IOException e) {
+ LOGGER.warn("Problem open protected terms file editor", e);
+ }
+ }
+
+ public void displayContent(ProtectedTermsList list) {
+ dialogService.showInformationDialogAndWait(
+ list.getDescription() + " - " + list.getLocation(),
+ list.getTermListing()
+ );
+ }
+
+ public void reloadFile(ProtectedTermsList file) {
+ termsLoader.reloadProtectedTermsList(file);
+ }
+}
diff --git a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java
index b0bd76d7276..d97e6ccc9fb 100644
--- a/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java
+++ b/src/main/java/org/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java
@@ -1,61 +1,30 @@
package org.jabref.gui.protectedterms;
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.nio.file.Path;
-import java.util.Optional;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JDialog;
-import javax.swing.JTextField;
+import javafx.scene.control.Button;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.VBox;
import org.jabref.Globals;
import org.jabref.gui.DialogService;
-import org.jabref.gui.JabRefDialog;
-import org.jabref.gui.keyboard.KeyBinding;
-import org.jabref.gui.util.DefaultTaskExecutor;
+import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.util.StandardFileType;
import org.jabref.preferences.JabRefPreferences;
-import com.jgoodies.forms.builder.ButtonBarBuilder;
-import com.jgoodies.forms.builder.FormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
-public class NewProtectedTermsFileDialog extends JabRefDialog {
+public class NewProtectedTermsFileDialog extends BaseDialog {
- private final JTextField newFile = new JTextField();
- private final JTextField newDescription = new JTextField();
- private final JCheckBox enabled = new JCheckBox(Localization.lang("Enabled"));
- private boolean addOKPressed;
- private final ProtectedTermsLoader loader;
+ private final TextField newFile = new TextField();
private final DialogService dialogService;
- public NewProtectedTermsFileDialog(JDialog parent, ProtectedTermsLoader loader, DialogService dialogService) {
- super(parent, Localization.lang("New protected terms file"), true, NewProtectedTermsFileDialog.class);
- this.loader = loader;
- this.dialogService = dialogService;
-
- setupDialog();
- setLocationRelativeTo(parent);
- }
-
- public NewProtectedTermsFileDialog(DialogService dialogService, ProtectedTermsLoader loader) {
- super(Localization.lang("New protected terms file"), true, NewProtectedTermsFileDialog.class);
- this.loader = loader;
+ public NewProtectedTermsFileDialog(ProtectedTermsLoader termsLoader, DialogService dialogService) {
this.dialogService = dialogService;
- setupDialog();
- }
- private void setupDialog() {
- JButton browse = new JButton(Localization.lang("Browse"));
+ this.setTitle(Localization.lang("New protected terms file"));
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS)
@@ -63,61 +32,29 @@ private void setupDialog() {
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
.build();
- browse.addActionListener(e -> {
- Optional file = DefaultTaskExecutor
- .runInJavaFXThread(() -> dialogService.showFileSaveDialog(fileDialogConfiguration));
- file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString()));
- });
-
- // Build content panel
- FormBuilder builder = FormBuilder.create();
- builder.layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow, 4dlu, pref", "p, 4dlu, p, 4dlu, p"));
- builder.add(Localization.lang("Description")).xy(1, 1);
- builder.add(newDescription).xyw(3, 1, 3);
- builder.add(Localization.lang("File")).xy(1, 3);
- builder.add(newFile).xy(3, 3);
- builder.add(browse).xy(5, 3);
- builder.add(enabled).xyw(1, 5, 5);
- enabled.setSelected(true);
- builder.padding("10dlu, 10dlu, 10dlu, 10dlu");
- getContentPane().add(builder.build(), BorderLayout.CENTER);
-
- // Buttons
- ButtonBarBuilder bb = new ButtonBarBuilder();
- JButton addOKButton = new JButton(Localization.lang("OK"));
- JButton addCancelButton = new JButton(Localization.lang("Cancel"));
- bb.addGlue();
- bb.addButton(addOKButton);
- bb.addButton(addCancelButton);
- bb.addGlue();
- bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
- addOKButton.addActionListener(e -> {
- addOKPressed = true;
- loader.addNewProtectedTermsList(newDescription.getText(), newFile.getText(),
- enabled.isSelected());
- dispose();
+ Button browse = new Button(Localization.lang("Browse"));
+ browse.setOnAction(event -> {
+ this.dialogService.showFileSaveDialog(fileDialogConfiguration)
+ .ifPresent(file -> newFile.setText(file.toAbsolutePath().toString()));
});
- Action cancelAction = new AbstractAction() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- addOKPressed = false;
- dispose();
+ TextField newDescription = new TextField();
+ VBox container = new VBox(10,
+ new VBox(5, new Label(Localization.lang("Description")), newDescription),
+ new VBox(5, new Label(Localization.lang("File")), new HBox(10, newFile, browse))
+ );
+ getDialogPane().setContent(container);
+
+ getDialogPane().getButtonTypes().setAll(
+ ButtonType.OK,
+ ButtonType.CANCEL
+ );
+
+ setResultConverter(button -> {
+ if (button == ButtonType.OK) {
+ termsLoader.addNewProtectedTermsList(newDescription.getText(), newFile.getText(), true);
}
- };
- addCancelButton.addActionListener(cancelAction);
-
- // Key bindings:
- bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
- .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
- bb.getPanel().getActionMap().put("close", cancelAction);
- pack();
- }
-
- public boolean isOKPressed() {
- return addOKPressed;
+ return null;
+ });
}
-
}
diff --git a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java
deleted file mode 100644
index cef0db50b0d..00000000000
--- a/src/main/java/org/jabref/gui/protectedterms/ProtectedTermsDialog.java
+++ /dev/null
@@ -1,489 +0,0 @@
-package org.jabref.gui.protectedterms;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Objects;
-import java.util.Optional;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.ActionMap;
-import javax.swing.BorderFactory;
-import javax.swing.InputMap;
-import javax.swing.JButton;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.KeyStroke;
-import javax.swing.ListSelectionModel;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import javax.swing.table.DefaultTableModel;
-import javax.swing.table.TableColumnModel;
-
-import org.jabref.Globals;
-import org.jabref.gui.JabRefDialog;
-import org.jabref.gui.JabRefFrame;
-import org.jabref.gui.desktop.JabRefDesktop;
-import org.jabref.gui.externalfiletype.ExternalFileType;
-import org.jabref.gui.externalfiletype.ExternalFileTypes;
-import org.jabref.gui.icon.IconTheme;
-import org.jabref.gui.keyboard.KeyBinding;
-import org.jabref.gui.util.DefaultTaskExecutor;
-import org.jabref.gui.util.FileDialogConfiguration;
-import org.jabref.gui.util.WindowLocation;
-import org.jabref.logic.l10n.Localization;
-import org.jabref.logic.protectedterms.ProtectedTermsList;
-import org.jabref.logic.protectedterms.ProtectedTermsLoader;
-import org.jabref.logic.util.StandardFileType;
-import org.jabref.model.database.BibDatabaseContext;
-import org.jabref.preferences.JabRefPreferences;
-
-import com.jgoodies.forms.builder.ButtonBarBuilder;
-import com.jgoodies.forms.builder.FormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class produces a dialog box for managing term list files.
- */
-public class ProtectedTermsDialog {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ProtectedTermsDialog.class);
-
- private final JabRefFrame frame;
- private JDialog diag;
- private JTable table;
- private DefaultTableModel tableModel;
- private final JPopupMenu popup = new JPopupMenu();
- private final JMenuItem edit = new JMenuItem(Localization.lang("Edit"));
- private final JMenuItem show = new JMenuItem(Localization.lang("View"));
- private final JMenuItem remove = new JMenuItem(Localization.lang("Remove"));
- private final JMenuItem reload = new JMenuItem(Localization.lang("Reload"));
- private final JMenuItem enabled = new JCheckBoxMenuItem(Localization.lang("Enabled"));
- private final JButton loadButton = new JButton(IconTheme.JabRefIcons.OPEN.getIcon());
- private final JButton removeButton = new JButton(IconTheme.JabRefIcons.DELETE_ENTRY.getIcon());
- private final JButton newButton = new JButton(IconTheme.JabRefIcons.NEW.getIcon());
- private ActionListener removeAction;
-
- private final JButton ok = new JButton(Localization.lang("OK"));
- private final JButton cancel = new JButton(Localization.lang("Cancel"));
-
- private boolean okPressed;
- private final ProtectedTermsLoader loader;
-
- public ProtectedTermsDialog(JabRefFrame frame) {
-
- this.frame = Objects.requireNonNull(frame);
- this.loader = Globals.protectedTermsLoader;
- init();
-
- }
-
- private void init() {
- setupPopupMenu();
-
- loadButton.addActionListener(actionEvent -> {
- AddFileDialog addDialog = new AddFileDialog();
- addDialog.setVisible(true);
- addDialog.getFileName().ifPresent(fileName -> loader.addProtectedTermsListFromFile(fileName, true));
- tableModel.fireTableDataChanged();
- });
- loadButton.setToolTipText(Localization.lang("Add protected terms file"));
-
- removeButton.addActionListener(removeAction);
- removeButton.setToolTipText(Localization.lang("Remove protected terms file"));
-
- newButton.addActionListener(actionEvent -> {
- NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(diag, loader, frame.getDialogService());
- newDialog.setVisible(true);
- tableModel.fireTableDataChanged();
- });
- newButton.setToolTipText(Localization.lang("New protected terms file"));
-
- setupTable();
-
- // Build dialog
- diag = new JDialog((JFrame) null, Localization.lang("Manage protected terms files"), true);
-
- FormBuilder builder = FormBuilder.create();
- builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref, 4dlu, left:pref",
- "100dlu:grow, 4dlu, pref"));
- builder.add(new JScrollPane(table)).xyw(1, 1, 7);
- builder.add(newButton).xy(3, 3);
- builder.add(loadButton).xy(5, 3);
- builder.add(removeButton).xy(7, 3);
- builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
-
- diag.add(builder.getPanel(), BorderLayout.CENTER);
-
- AbstractAction okListener = new AbstractAction() {
-
- @Override
- public void actionPerformed(ActionEvent event) {
- // Write changes to preferences
- storePreferences();
- diag.dispose();
- }
- };
- ok.addActionListener(okListener);
-
- Action cancelListener = new AbstractAction() {
-
- @Override
- public void actionPerformed(ActionEvent event) {
- // Restore from preferences
- loader.update(Globals.prefs.getProtectedTermsPreferences());
- diag.dispose();
- }
- };
- cancel.addActionListener(cancelListener);
-
- ButtonBarBuilder bb = new ButtonBarBuilder();
- bb.addGlue();
- bb.addButton(ok);
- bb.addButton(cancel);
- bb.addGlue();
- bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- diag.add(bb.getPanel(), BorderLayout.SOUTH);
-
- ActionMap am = bb.getPanel().getActionMap();
- InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
- im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
- am.put("close", cancelListener);
- im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk");
- am.put("enterOk", okListener);
-
- diag.pack();
-
- WindowLocation pw = new WindowLocation(diag, JabRefPreferences.TERMS_POS_X, JabRefPreferences.TERMS_POS_Y,
- JabRefPreferences.TERMS_SIZE_X, JabRefPreferences.TERMS_SIZE_Y);
- pw.displayWindowAtStoredLocation();
- }
-
- private void setupTable() {
- tableModel = new TermTableModel();
- table = new JTable(tableModel);
- TableColumnModel cm = table.getColumnModel();
- cm.getColumn(0).setMinWidth((cm.getColumn(0).getPreferredWidth() * 11) / 10);
- cm.getColumn(0).setMaxWidth((cm.getColumn(0).getPreferredWidth() * 11) / 10);
- cm.getColumn(1).setPreferredWidth(100);
- cm.getColumn(2).setPreferredWidth(100);
-
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- table.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mousePressed(MouseEvent mouseEvent) {
- if (mouseEvent.isPopupTrigger()) {
- tablePopup(mouseEvent);
- }
- }
-
- @Override
- public void mouseReleased(MouseEvent mouseEvent) {
- if (mouseEvent.isPopupTrigger()) {
- tablePopup(mouseEvent);
- }
- }
-
- @Override
- public void mouseClicked(MouseEvent mouseEvent) {
- if (mouseEvent.getClickCount() == 2) {
- getSelectedTermsList().ifPresent(list -> list.setEnabled(!list.isEnabled()));
- tableModel.fireTableDataChanged();
- }
- }
- });
-
- table.getSelectionModel().addListSelectionListener(new EntrySelectionListener());
- }
-
- private void setupPopupMenu() {
- popup.add(edit);
- popup.add(show);
- popup.add(remove);
- popup.add(reload);
- popup.addSeparator();
- popup.add(enabled);
-
- // Add action listener to "Edit" menu item, which is supposed to open the term file in an external editor:
- edit.addActionListener(actionEvent -> getSelectedTermsList().ifPresent(term -> {
- Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("terms");
- String fileName = term.getLocation();
- try {
- if (type.isPresent()) {
- JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, type);
- } else {
- // Fall back to ".txt"
- Optional txtType = ExternalFileTypes.getInstance()
- .getExternalFileTypeByExt("txt");
- JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), fileName, type);
-
- }
- } catch (IOException e) {
- LOGGER.warn("Problem open protected terms file editor", e);
- }
- }));
-
- // Add action listener to "Show" menu item, which is supposed to open the term file in a dialog:
- show.addActionListener(actionEvent -> getSelectedTermsList().ifPresent(this::displayTerms));
-
- // Create action listener for removing a term file, also used for the remove button
- removeAction = actionEvent -> getSelectedTermsList().ifPresent(list -> {
-
- if (!list.isInternalList() && frame.getDialogService().showConfirmationDialogAndWait(Localization.lang("Remove protected terms file"),
- Localization.lang("Are you sure you want to remove the protected terms file?"),
- Localization.lang("Remove protected terms file"),
- Localization.lang("Cancel"))) {
- if (!loader.removeProtectedTermsList(list)) {
- LOGGER.info("Problem removing protected terms file");
- }
- tableModel.fireTableDataChanged();
- }
- });
- // Add it to the remove menu item
- remove.addActionListener(removeAction);
-
- // Add action listener to the "Reload" menu item, which is supposed to reload an external term file
- reload.addActionListener(actionEvent -> {
- getSelectedTermsList().ifPresent(loader::reloadProtectedTermsList);
- });
-
- enabled.addActionListener(actionEvent -> getSelectedTermsList().ifPresent(list -> {
- list.setEnabled(enabled.isSelected());
- }));
-
- }
-
- public void setVisible(boolean visible) {
- okPressed = false;
- diag.setVisible(visible);
- }
-
- /**
- * Get the currently selected term list.
- * @return the selected term list, or empty if no term list is selected.
- */
- private Optional getSelectedTermsList() {
- if (table.getSelectedRow() != -1) {
- return Optional.of(loader.getProtectedTermsLists().get(table.getSelectedRow()));
- }
- return Optional.empty();
- }
-
- class TermTableModel extends DefaultTableModel {
-
- @Override
- public int getColumnCount() {
- return 3;
- }
-
- @Override
- public int getRowCount() {
- return loader.getProtectedTermsLists().size();
- }
-
- @Override
- public String getColumnName(int i) {
- switch (i) {
- case 0:
- return Localization.lang("Enabled");
- case 1:
- return Localization.lang("Description");
- case 2:
- return Localization.lang("File");
- default:
- return "";
- }
- }
-
- @Override
- public Object getValueAt(int row, int column) {
- switch (column) {
- case 0:
- return loader.getProtectedTermsLists().get(row).isEnabled();
- case 1:
- return loader.getProtectedTermsLists().get(row).getDescription();
- case 2:
- ProtectedTermsList list = loader.getProtectedTermsLists().get(row);
- return list.isInternalList() ? Localization.lang("Internal list") + " - " + list.getLocation() : list
- .getLocation();
- default:
- return "";
- }
- }
-
- @Override
- public boolean isCellEditable(int row, int column) {
- return column == 0;
- }
-
- @Override
- public Class> getColumnClass(int column) {
- switch (column) {
- case 0:
- return Boolean.class;
- case 1:
- return String.class;
- case 2:
- return String.class;
- default:
- return String.class;
- }
- }
-
- @Override
- public void setValueAt(Object cell, int row, int column) {
- if (column == 0) {
- ProtectedTermsList list = loader.getProtectedTermsLists().get(row);
- list.setEnabled(!list.isEnabled());
- this.fireTableCellUpdated(row, column);
- }
- }
-
- }
-
- public boolean isOkPressed() {
- return okPressed;
- }
-
- private void tablePopup(MouseEvent e) {
- popup.show(e.getComponent(), e.getX(), e.getY());
- }
-
- private void displayTerms(ProtectedTermsList list) {
- // Make a dialog box to display the contents:
- final JDialog dd = new JDialog(diag, list.getDescription() + " - " + list.getLocation(), true);
-
- JTextArea ta = new JTextArea(list.getTermListing());
- ta.setEditable(false);
- JScrollPane sp = new JScrollPane(ta);
- sp.setPreferredSize(new Dimension(700, 500));
- dd.getContentPane().add(sp, BorderLayout.CENTER);
- JButton okButton = new JButton(Localization.lang("OK"));
- ButtonBarBuilder bb = new ButtonBarBuilder();
- bb.addGlue();
- bb.addButton(okButton);
- bb.addGlue();
- bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- dd.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
- okButton.addActionListener(actionEvent -> dd.dispose());
- dd.pack();
- dd.setLocationRelativeTo(diag);
- dd.setVisible(true);
- }
-
- /**
- * The listener for the table monitoring the current selection.
- */
- private class EntrySelectionListener implements ListSelectionListener {
-
- @Override
- public void valueChanged(ListSelectionEvent listEvent) {
- getSelectedTermsList().ifPresent(list -> {
- // Enable/disable popup menu items and buttons
- if (list.isInternalList()) {
- remove.setEnabled(false);
- edit.setEnabled(false);
- reload.setEnabled(false);
- removeButton.setEnabled(false);
- } else {
- remove.setEnabled(true);
- edit.setEnabled(true);
- reload.setEnabled(true);
- removeButton.setEnabled(true);
- }
- enabled.setSelected(list.isEnabled());
- });
- }
- }
-
- private class AddFileDialog extends JabRefDialog {
-
- private final JTextField newFile = new JTextField();
- private boolean addOKPressed;
-
- public AddFileDialog() {
- super(diag, Localization.lang("Add protected terms file"), true, AddFileDialog.class);
-
- JButton browse = new JButton(Localization.lang("Browse"));
- FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
- .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS)
- .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS)
- .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
-
- browse.addActionListener(e -> {
- Optional file = DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().showFileOpenDialog(fileDialogConfiguration));
- file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString()));
- });
-
- // Build content panel
- FormBuilder builder = FormBuilder.create();
- builder.layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow, 4dlu, pref", "p"));
- builder.add(Localization.lang("File")).xy(1, 1);
- builder.add(newFile).xy(3, 1);
- builder.add(browse).xy(5, 1);
- builder.padding("10dlu, 10dlu, 10dlu, 10dlu");
- getContentPane().add(builder.build(), BorderLayout.CENTER);
-
- // Buttons
- ButtonBarBuilder bb = new ButtonBarBuilder();
- JButton addOKButton = new JButton(Localization.lang("OK"));
- JButton addCancelButton = new JButton(Localization.lang("Cancel"));
- bb.addGlue();
- bb.addButton(addOKButton);
- bb.addButton(addCancelButton);
- bb.addGlue();
- bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
- addOKButton.addActionListener(e -> {
- addOKPressed = true;
- dispose();
- });
-
- Action cancelAction = new AbstractAction() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- addOKPressed = false;
- dispose();
- }
- };
- addCancelButton.addActionListener(cancelAction);
-
- // Key bindings:
- bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
- .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
- bb.getPanel().getActionMap().put("close", cancelAction);
- pack();
- setLocationRelativeTo(diag);
- }
-
- public Optional getFileName() {
- if (addOKPressed && (newFile.getText() != null) && !newFile.getText().isEmpty()) {
- return Optional.of(newFile.getText());
- }
- return Optional.empty();
- }
-
- }
-
- private void storePreferences() {
- Globals.prefs.setProtectedTermsPreferences(loader);
- }
-}
diff --git a/src/main/java/org/jabref/gui/util/BindingsHelper.java b/src/main/java/org/jabref/gui/util/BindingsHelper.java
index 162fb210065..af0fafd441b 100644
--- a/src/main/java/org/jabref/gui/util/BindingsHelper.java
+++ b/src/main/java/org/jabref/gui/util/BindingsHelper.java
@@ -8,6 +8,7 @@
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
+import javafx.beans.binding.ObjectBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.ListProperty;
import javafx.beans.property.Property;
@@ -148,7 +149,16 @@ public static void bindContentBidirectional(ObservableMap proper
updateB);
}
- public static ObservableValue extends Boolean> constantOf(boolean value) {
+ public static ObservableValue constantOf(T value) {
+ return new ObjectBinding() {
+ @Override
+ protected T computeValue() {
+ return value;
+ }
+ };
+ }
+
+ public static ObservableValue constantOf(boolean value) {
return new BooleanBinding() {
@Override
protected boolean computeValue() {
diff --git a/src/main/java/org/jabref/model/util/OptionalUtil.java b/src/main/java/org/jabref/model/util/OptionalUtil.java
index 525477f415e..6d127c4e5ce 100644
--- a/src/main/java/org/jabref/model/util/OptionalUtil.java
+++ b/src/main/java/org/jabref/model/util/OptionalUtil.java
@@ -59,4 +59,12 @@ public static Optional combine(Optional valueOne, Optional va
return Optional.empty();
}
}
+
+ public static Optional orElse(Optional valueOne, Optional valueTwo) {
+ if (valueOne.isPresent()) {
+ return valueOne;
+ } else {
+ return valueTwo;
+ }
+ }
}
diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java
index c3070474954..39ef552b6f0 100644
--- a/src/main/java/org/jabref/preferences/JabRefPreferences.java
+++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java
@@ -183,10 +183,6 @@ public class JabRefPreferences implements PreferencesService {
public static final String PREAMBLE_SIZE_X = "preambleSizeX";
public static final String PREAMBLE_POS_Y = "preamblePosY";
public static final String PREAMBLE_POS_X = "preamblePosX";
- public static final String TERMS_SIZE_Y = "termsSizeY";
- public static final String TERMS_SIZE_X = "termsSizeX";
- public static final String TERMS_POS_Y = "termsPosY";
- public static final String TERMS_POS_X = "termsPosX";
public static final String SEARCH_DIALOG_HEIGHT = "searchDialogHeight";
public static final String SEARCH_DIALOG_WIDTH = "searchDialogWidth";
public static final String IMPORT_INSPECTION_DIALOG_HEIGHT = "importInspectionDialogHeight";
@@ -563,10 +559,6 @@ private JabRefPreferences() {
defaults.put(PREAMBLE_POS_Y, 0);
defaults.put(PREAMBLE_SIZE_X, 600);
defaults.put(PREAMBLE_SIZE_Y, 400);
- defaults.put(TERMS_POS_X, 0);
- defaults.put(TERMS_POS_Y, 0);
- defaults.put(TERMS_SIZE_X, 500);
- defaults.put(TERMS_SIZE_Y, 500);
defaults.put(DEFAULT_SHOW_SOURCE, Boolean.FALSE);
defaults.put(DEFAULT_AUTO_SORT, Boolean.FALSE);
@@ -1631,6 +1623,7 @@ public ProtectedTermsPreferences getProtectedTermsPreferences() {
getStringList(PROTECTED_TERMS_DISABLED_EXTERNAL));
}
+ @Override
public void setProtectedTermsPreferences(ProtectedTermsLoader loader) {
List enabledExternalList = new ArrayList<>();
List disabledExternalList = new ArrayList<>();
@@ -1657,7 +1650,6 @@ public void setProtectedTermsPreferences(ProtectedTermsLoader loader) {
putStringList(PROTECTED_TERMS_DISABLED_EXTERNAL, disabledExternalList);
putStringList(PROTECTED_TERMS_ENABLED_INTERNAL, enabledInternalList);
putStringList(PROTECTED_TERMS_DISABLED_INTERNAL, disabledInternalList);
-
}
@Override
diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java
index 47ec943c9c4..24a33ba283c 100644
--- a/src/main/java/org/jabref/preferences/PreferencesService.java
+++ b/src/main/java/org/jabref/preferences/PreferencesService.java
@@ -11,10 +11,13 @@
import org.jabref.logic.journals.JournalAbbreviationPreferences;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.openoffice.OpenOfficePreferences;
+import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.metadata.FilePreferences;
public interface PreferencesService {
+ void setProtectedTermsPreferences(ProtectedTermsLoader loader);
+
JournalAbbreviationPreferences getJournalAbbreviationPreferences();
void storeKeyBindingRepository(KeyBindingRepository keyBindingRepository);
diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties
index e38d7c151da..b5233752d16 100644
--- a/src/main/resources/l10n/JabRef_en.properties
+++ b/src/main/resources/l10n/JabRef_en.properties
@@ -637,9 +637,6 @@ Name\ formatter=Name formatter
Natbib\ style=Natbib style
nested\ AUX\ files=nested AUX files
-
-New=New
-
new=new
New\ BibTeX\ sublibrary=New BibTeX sublibrary