diff --git a/src/main/java/org/jabref/gui/Base.css b/src/main/java/org/jabref/gui/Base.css index 8c6b1dbe2d8..8b2cd80f7b1 100644 --- a/src/main/java/org/jabref/gui/Base.css +++ b/src/main/java/org/jabref/gui/Base.css @@ -1027,3 +1027,8 @@ We want to have a look that matches our icons in the tool-bar */ .tooltip-error { -fx-background-color: -jr-error; } + +.sectionHeader { + -fx-font-size: 1.5em; + -fx-padding: 1em 0em 1em 0em; +} diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 74144a9ab42..ffdeb573738 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -61,9 +61,9 @@ import org.jabref.gui.actions.ConnectToSharedDatabaseCommand; import org.jabref.gui.actions.CopyFilesAction; import org.jabref.gui.actions.CustomizeKeyBindingAction; -import org.jabref.gui.actions.DatabasePropertiesAction; import org.jabref.gui.actions.EditExternalFileTypesAction; import org.jabref.gui.actions.ErrorConsoleAction; +import org.jabref.gui.actions.LibraryPropertiesAction; import org.jabref.gui.actions.LookupIdentifierAction; import org.jabref.gui.actions.ManageContentSelectorAction; import org.jabref.gui.actions.ManageCustomExportsAction; @@ -818,7 +818,7 @@ private MenuBar createMenu() { edit.getItems().add(new SeparatorMenuItem()); } } - + //@formatter:off library.getItems().addAll( factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs)), factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAINTEX, new NewEntryFromPlainTextAction(this, Globals.prefs.getUpdateFieldPreferences(), dialogService, Globals.prefs)), @@ -826,7 +826,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new DatabasePropertiesAction(this)), + factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(this, dialogService)), factory.createMenuItem(StandardActions.EDIT_PREAMBLE, new PreambleEditor(this)), factory.createMenuItem(StandardActions.EDIT_STRINGS, new BibtexStringEditorAction(this)), factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(this)) @@ -838,7 +838,6 @@ private MenuBar createMenu() { lookupIdentifiers.getItems().add(factory.createMenuItem(identifierAction.getAction(), identifierAction)); } - //@formatter:off quality.getItems().addAll( factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(this, dialogService)), factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(this)), diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.fxml b/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.fxml new file mode 100644 index 00000000000..4bee6851ab0 --- /dev/null +++ b/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.fxml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.java b/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.java deleted file mode 100644 index 5103fba8d29..00000000000 --- a/src/main/java/org/jabref/gui/SaveOrderConfigDisplay.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.jabref.gui; - -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Objects; - -import javafx.collections.FXCollections; -import javafx.scene.Node; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.layout.GridPane; -import javafx.scene.text.Font; - -import org.jabref.logic.l10n.Localization; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.InternalBibtexFields; -import org.jabref.model.metadata.SaveOrderConfig; -import org.jabref.model.metadata.SaveOrderConfig.SortCriterion; - -public class SaveOrderConfigDisplay { - - private GridPane panel; - private ComboBox savePriSort; - private ComboBox saveSecSort; - private ComboBox saveTerSort; - private CheckBox savePriDesc; - private CheckBox saveSecDesc; - private CheckBox saveTerDesc; - - - public SaveOrderConfigDisplay() { - init(); - } - - private void init() { - List fieldNames = InternalBibtexFields.getAllPublicFieldNames(); - fieldNames.add(BibEntry.KEY_FIELD); - Collections.sort(fieldNames); - savePriSort = new ComboBox<>(FXCollections.observableArrayList(fieldNames)); - savePriSort.setEditable(true); - saveSecSort = new ComboBox<>(FXCollections.observableArrayList(fieldNames)); - saveSecSort.setEditable(true); - saveTerSort = new ComboBox<>(FXCollections.observableArrayList(fieldNames)); - saveTerSort.setEditable(true); - - savePriDesc = new CheckBox(Localization.lang("Descending")); - saveSecDesc = new CheckBox(Localization.lang("Descending")); - saveTerDesc = new CheckBox(Localization.lang("Descending")); - - Font font = new Font(10); - GridPane builder = new GridPane(); - Label primarySortCriterion = new Label(Localization.lang("Primary sort criterion")); - primarySortCriterion.setFont(font); - builder.add(primarySortCriterion, 1, 1); - builder.add(savePriSort, 2, 1); - builder.add(savePriDesc, 3, 1); - - Label secondarySortCriterion = new Label(Localization.lang("Secondary sort criterion")); - secondarySortCriterion.setFont(font); - builder.add(secondarySortCriterion, 1, 2); - builder.add(saveSecSort, 2, 2); - builder.add(saveSecDesc, 3, 2); - - Label tertiarySortCriterion = new Label(Localization.lang("Tertiary sort criterion")); - tertiarySortCriterion.setFont(font); - builder.add(tertiarySortCriterion, 1, 3); - builder.add(saveTerSort, 2, 3); - builder.add(saveTerDesc, 3, 3); - panel = builder; - } - - public Node getJFXPanel() { - return panel; - } - - public void setEnabled(boolean enabled) { - savePriSort.setDisable(!enabled); - savePriDesc.setDisable(!enabled); - saveSecSort.setDisable(!enabled); - saveSecDesc.setDisable(!enabled); - saveTerSort.setDisable(!enabled); - saveTerDesc.setDisable(!enabled); - } - - public SaveOrderConfig getSaveOrderConfig() { - SaveOrderConfig saveOrderConfig = new SaveOrderConfig(); - SortCriterion primary = new SortCriterion(getSelectedItemAsLowerCaseTrim(savePriSort), savePriDesc.isSelected()); - saveOrderConfig.getSortCriteria().add(primary); - SortCriterion secondary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveSecSort), saveSecDesc.isSelected()); - saveOrderConfig.getSortCriteria().add(secondary); - SortCriterion tertiary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveTerSort), saveTerDesc.isSelected()); - saveOrderConfig.getSortCriteria().add(tertiary); - - return saveOrderConfig; - } - - public void setSaveOrderConfig(SaveOrderConfig saveOrderConfig) { - Objects.requireNonNull(saveOrderConfig); - - savePriSort.setValue(saveOrderConfig.getSortCriteria().get(0).field); - savePriDesc.setSelected(saveOrderConfig.getSortCriteria().get(0).descending); - saveSecSort.setValue(saveOrderConfig.getSortCriteria().get(1).field); - saveSecDesc.setSelected(saveOrderConfig.getSortCriteria().get(1).descending); - saveTerSort.setValue(saveOrderConfig.getSortCriteria().get(2).field); - saveTerDesc.setSelected(saveOrderConfig.getSortCriteria().get(2).descending); - } - - private String getSelectedItemAsLowerCaseTrim(ComboBox sortBox) { - return sortBox.getValue().toLowerCase(Locale.ROOT).trim(); - } -} diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java new file mode 100644 index 00000000000..aeca6f4ddad --- /dev/null +++ b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java @@ -0,0 +1,81 @@ +package org.jabref.gui; + +import javax.inject.Inject; + +import javafx.fxml.FXML; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.RadioButton; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.GridPane; + +import org.jabref.logic.l10n.Localization; +import org.jabref.model.metadata.SaveOrderConfig; +import org.jabref.preferences.PreferencesService; + +import com.airhacks.afterburner.views.ViewLoader; + +public class SaveOrderConfigDisplayView extends GridPane { + + private final SaveOrderConfig config; + + @FXML private ToggleGroup saveOrderToggleGroup; + @FXML private ComboBox savePriSort; + @FXML private ComboBox saveSecSort; + @FXML private ComboBox saveTerSort; + @FXML private RadioButton exportInSpecifiedOrder; + @FXML private RadioButton exportInTableOrder; + @FXML private RadioButton exportInOriginalOrder; + @FXML private CheckBox savePriDesc; + @FXML private CheckBox saveSecDesc; + @FXML private CheckBox saveTerDesc; + @Inject private PreferencesService preferencesService; + + private SaveOrderConfigDisplayViewModel viewModel; + + public SaveOrderConfigDisplayView(SaveOrderConfig config) { + this.config = config; + + ViewLoader.view(this) + .root(this) + .load(); + } + + @FXML + private void initialize() { + + viewModel = new SaveOrderConfigDisplayViewModel(config, preferencesService); + + exportInSpecifiedOrder.selectedProperty().bindBidirectional(viewModel.saveInSpecifiedOrderProperty()); + exportInTableOrder.selectedProperty().bindBidirectional(viewModel.saveInTableOrderProperty()); + exportInOriginalOrder.selectedProperty().bindBidirectional(viewModel.saveInOriginalProperty()); + + savePriSort.itemsProperty().bindBidirectional(viewModel.priSortFieldsProperty()); + saveSecSort.itemsProperty().bindBidirectional(viewModel.secSortFieldsProperty()); + saveTerSort.itemsProperty().bindBidirectional(viewModel.terSortFieldsProperty()); + + savePriSort.valueProperty().bindBidirectional(viewModel.savePriSortSelectedValueProperty()); + saveSecSort.valueProperty().bindBidirectional(viewModel.saveSecSortSelectedValueProperty()); + saveTerSort.valueProperty().bindBidirectional(viewModel.saveTerSortSelectedValueProperty()); + + savePriDesc.selectedProperty().bindBidirectional(viewModel.savePriDescPropertySelected()); + saveSecDesc.selectedProperty().bindBidirectional(viewModel.saveSecDescPropertySelected()); + saveTerDesc.selectedProperty().bindBidirectional(viewModel.saveTerDescPropertySelected()); + + } + + public void changeExportDescriptionToSave() { + exportInOriginalOrder.setText(Localization.lang("Save entries in their original order")); + exportInSpecifiedOrder.setText(Localization.lang("Save entries ordered as specified")); + exportInTableOrder.setText(Localization.lang("Save in current table sort order")); + } + + public void storeConfig() { + viewModel.storeConfigInPrefs(); + } + + public SaveOrderConfig getSaveOrderConfig() { + return viewModel.getSaveOrderConfig(); + } + +} diff --git a/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java new file mode 100644 index 00000000000..0846ee4866c --- /dev/null +++ b/src/main/java/org/jabref/gui/SaveOrderConfigDisplayViewModel.java @@ -0,0 +1,141 @@ +package org.jabref.gui; + +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Objects; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; + +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.InternalBibtexFields; +import org.jabref.model.metadata.SaveOrderConfig; +import org.jabref.model.metadata.SaveOrderConfig.SortCriterion; +import org.jabref.preferences.PreferencesService; + +public class SaveOrderConfigDisplayViewModel { + + private final ListProperty priSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty secSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ListProperty terSortFieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + + private final BooleanProperty savePriDescPropertySelected = new SimpleBooleanProperty(); + private final BooleanProperty saveSecDescPropertySelected = new SimpleBooleanProperty(); + private final BooleanProperty saveTerDescPropertySelected = new SimpleBooleanProperty(); + + private final StringProperty savePriSortSelectedValueProperty = new SimpleStringProperty(""); + private final StringProperty saveSecSortSelectedValueProperty = new SimpleStringProperty(""); + private final StringProperty saveTerSortSelectedValueProperty = new SimpleStringProperty(""); + + private final BooleanProperty saveInOriginalProperty = new SimpleBooleanProperty(); + private final BooleanProperty saveInTableOrderProperty = new SimpleBooleanProperty(); + private final BooleanProperty saveInSpecifiedOrderProperty = new SimpleBooleanProperty(); + + private final PreferencesService prefs; + + public SaveOrderConfigDisplayViewModel(SaveOrderConfig config, PreferencesService prefs) { + this.prefs = prefs; + + List fieldNames = InternalBibtexFields.getAllPublicFieldNames(); + fieldNames.add(BibEntry.KEY_FIELD); + Collections.sort(fieldNames); + + priSortFieldsProperty.addAll(fieldNames); + secSortFieldsProperty.addAll(fieldNames); + terSortFieldsProperty.addAll(fieldNames); + + setSaveOrderConfig(config); + } + + public ListProperty priSortFieldsProperty() { + return priSortFieldsProperty; + } + + public ListProperty secSortFieldsProperty() { + return secSortFieldsProperty; + } + + public ListProperty terSortFieldsProperty() { + return terSortFieldsProperty; + } + + public SaveOrderConfig getSaveOrderConfig() { + SortCriterion primary = new SortCriterion(getSelectedItemAsLowerCaseTrim(savePriSortSelectedValueProperty), savePriDescPropertySelected.getValue()); + SortCriterion secondary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveSecSortSelectedValueProperty), saveSecDescPropertySelected.getValue()); + SortCriterion tertiary = new SortCriterion(getSelectedItemAsLowerCaseTrim(saveTerSortSelectedValueProperty), saveTerDescPropertySelected.getValue()); + + SaveOrderConfig saveOrderConfig = new SaveOrderConfig(saveInOriginalProperty.getValue(), saveInSpecifiedOrderProperty.getValue(), primary, secondary, tertiary); + + return saveOrderConfig; + } + + public void setSaveOrderConfig(SaveOrderConfig saveOrderConfig) { + Objects.requireNonNull(saveOrderConfig); + + savePriSortSelectedValueProperty.setValue(saveOrderConfig.getSortCriteria().get(0).field); + savePriDescPropertySelected.setValue(saveOrderConfig.getSortCriteria().get(0).descending); + saveSecSortSelectedValueProperty.setValue(saveOrderConfig.getSortCriteria().get(1).field); + saveSecDescPropertySelected.setValue(saveOrderConfig.getSortCriteria().get(1).descending); + saveTerSortSelectedValueProperty.setValue(saveOrderConfig.getSortCriteria().get(2).field); + saveTerDescPropertySelected.setValue(saveOrderConfig.getSortCriteria().get(2).descending); + + if (saveOrderConfig.saveInOriginalOrder()) { + saveInOriginalProperty.setValue(true); + } else if (saveOrderConfig.saveInSpecifiedOrder()) { + saveInSpecifiedOrderProperty.setValue(true); + } else { + saveInTableOrderProperty.setValue(true); + } + + } + + private String getSelectedItemAsLowerCaseTrim(StringProperty string) { + return string.getValue().toLowerCase(Locale.ROOT).trim(); + } + + public BooleanProperty savePriDescPropertySelected() { + return savePriDescPropertySelected; + } + + public BooleanProperty saveSecDescPropertySelected() { + return saveSecDescPropertySelected; + } + + public BooleanProperty saveTerDescPropertySelected() { + return saveTerDescPropertySelected; + } + + public StringProperty savePriSortSelectedValueProperty() { + return savePriSortSelectedValueProperty; + } + + public StringProperty saveSecSortSelectedValueProperty() { + return saveSecSortSelectedValueProperty; + } + + public StringProperty saveTerSortSelectedValueProperty() { + return saveTerSortSelectedValueProperty; + } + + public void storeConfigInPrefs() { + prefs.storeExportSaveOrder(this.getSaveOrderConfig()); + } + + public BooleanProperty saveInOriginalProperty() { + return saveInOriginalProperty; + } + + public BooleanProperty saveInTableOrderProperty() { + return saveInTableOrderProperty; + } + + public BooleanProperty saveInSpecifiedOrderProperty() { + return this.saveInSpecifiedOrderProperty; + } +} diff --git a/src/main/java/org/jabref/gui/actions/DatabasePropertiesAction.java b/src/main/java/org/jabref/gui/actions/DatabasePropertiesAction.java deleted file mode 100644 index 564b6c5cc2f..00000000000 --- a/src/main/java/org/jabref/gui/actions/DatabasePropertiesAction.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jabref.gui.actions; - -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.dbproperties.DatabasePropertiesDialog; - -public class DatabasePropertiesAction extends SimpleCommand { - - private final JabRefFrame frame; - - public DatabasePropertiesAction(JabRefFrame frame) { - this.frame = frame; - } - - @Override - public void execute() { - DatabasePropertiesDialog propertiesDialog = new DatabasePropertiesDialog(frame.getCurrentBasePanel()); - propertiesDialog.updateEnableStatus(); - propertiesDialog.setVisible(true); - } - -} diff --git a/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java b/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java new file mode 100644 index 00000000000..1b2299e3f06 --- /dev/null +++ b/src/main/java/org/jabref/gui/actions/LibraryPropertiesAction.java @@ -0,0 +1,24 @@ +package org.jabref.gui.actions; + +import org.jabref.gui.DialogService; +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.libraryproperties.LibraryPropertiesDialogView; + +public class LibraryPropertiesAction extends SimpleCommand { + + private final JabRefFrame frame; + private final DialogService dialogService; + + public LibraryPropertiesAction(JabRefFrame frame, DialogService dialogService) { + this.frame = frame; + this.dialogService = dialogService; + } + + @Override + public void execute() { + LibraryPropertiesDialogView propertiesDialog = new LibraryPropertiesDialogView(frame.getCurrentBasePanel(), dialogService); + propertiesDialog.showAndWait(); + + } + +} diff --git a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java b/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java deleted file mode 100644 index f1a58b0be7c..00000000000 --- a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java +++ /dev/null @@ -1,330 +0,0 @@ -package org.jabref.gui.dbproperties; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.nio.charset.Charset; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.DefaultComboBoxModel; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - -import javafx.embed.swing.JFXPanel; -import javafx.scene.Parent; -import javafx.scene.Scene; - -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.DialogService; -import org.jabref.gui.FXDialogService; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.SaveOrderConfigDisplay; -import org.jabref.gui.cleanup.FieldFormatterCleanupsPanel; -import org.jabref.gui.customjfx.CustomJFXPanel; -import org.jabref.gui.help.HelpAction; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.util.DefaultTaskExecutor; -import org.jabref.gui.util.DirectoryDialogConfiguration; -import org.jabref.logic.cleanup.Cleanups; -import org.jabref.logic.help.HelpFile; -import org.jabref.logic.l10n.Encodings; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.shared.DatabaseLocation; -import org.jabref.model.metadata.MetaData; -import org.jabref.model.metadata.SaveOrderConfig; -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 DatabasePropertiesDialog extends JabRefDialog { - - private final MetaData metaData; - private final BasePanel panel; - private final JComboBox encoding; - private final JButton ok; - private final JButton cancel; - private final JTextField fileDir = new JTextField(40); - private final JTextField fileDirIndv = new JTextField(40); - private String oldFileVal = ""; - private String oldFileIndvVal = ""; - private SaveOrderConfig oldSaveOrderConfig; - - /* The code for "Save sort order" is copied from ExportSortingPrefsTab and slightly updated to fit storing at metadata */ - private JRadioButton saveInOriginalOrder; - - private JRadioButton saveInSpecifiedOrder; - - private final JCheckBox protect = new JCheckBox( - Localization.lang("Refuse to save the library before external changes have been reviewed.")); - private boolean oldProtectVal; - private SaveOrderConfigDisplay saveOrderPanel; - - private FieldFormatterCleanupsPanel fieldFormatterCleanupsPanel; - - public DatabasePropertiesDialog(BasePanel panel) { - super(Localization.lang("Library properties"), true, DatabasePropertiesDialog.class); - encoding = new JComboBox<>(); - encoding.setModel(new DefaultComboBoxModel<>(Encodings.ENCODINGS)); - ok = new JButton(Localization.lang("OK")); - cancel = new JButton(Localization.lang("Cancel")); - this.panel = panel; - this.metaData = panel.getBibDatabaseContext().getMetaData(); - init(); - } - - public void updateEnableStatus() { - DatabaseLocation location = panel.getBibDatabaseContext().getLocation(); - boolean isShared = (location == DatabaseLocation.SHARED); - encoding.setEnabled(!isShared); // the encoding of shared database is always UTF-8 - saveInOriginalOrder.setEnabled(!isShared); - saveInSpecifiedOrder.setEnabled(!isShared); - saveOrderPanel.setEnabled(!isShared); - protect.setEnabled(!isShared); - } - - private void init() { - - DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); - DialogService ds = new FXDialogService(); - - JButton browseFile = new JButton(Localization.lang("Browse")); - JButton browseFileIndv = new JButton(Localization.lang("Browse")); - - browseFile.addActionListener(e -> DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)) - .ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString()))); - browseFileIndv.addActionListener(e -> DefaultTaskExecutor - .runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)) - .ifPresent(f -> fileDirIndv.setText(f.toAbsolutePath().toString()))); - - setupSortOrderConfiguration(); - FormLayout form = new FormLayout("left:pref, 4dlu, pref:grow, 4dlu, pref:grow, 4dlu, pref", - "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, fill:pref:grow, 180dlu, fill:pref:grow,"); - FormBuilder builder = FormBuilder.create().layout(form); - builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - builder.add(Localization.lang("Library encoding")).xy(1, 1); - builder.add(encoding).xy(3, 1); - - builder.addSeparator(Localization.lang("Override default file directories")).xyw(1, 3, 5); - builder.add(Localization.lang("General file directory")).xy(1, 5); - builder.add(fileDir).xy(3, 5); - builder.add(browseFile).xy(5, 5); - builder.add(Localization.lang("User-specific file directory")).xy(1, 7); - builder.add(fileDirIndv).xy(3, 7); - builder.add(browseFileIndv).xy(5, 7); - - builder.addSeparator(Localization.lang("Save sort order")).xyw(1, 13, 5); - builder.add(saveInOriginalOrder).xyw(1, 15, 5); - builder.add(saveInSpecifiedOrder).xyw(1, 17, 5); - - saveOrderPanel = new SaveOrderConfigDisplay(); - JFXPanel panel = CustomJFXPanel.wrap(new Scene((Parent) saveOrderPanel.getJFXPanel())); - builder.add(panel).xyw(1, 21, 5); - - builder.addSeparator(Localization.lang("Library protection")).xyw(1, 23, 5); - builder.add(protect).xyw(1, 25, 5); - - fieldFormatterCleanupsPanel = new FieldFormatterCleanupsPanel(Localization.lang("Enable save actions"), - Cleanups.DEFAULT_SAVE_ACTIONS); - builder.addSeparator(Localization.lang("Save actions")).xyw(1, 27, 5); - builder.add(CustomJFXPanel.wrap(new Scene(fieldFormatterCleanupsPanel))).xyw(1, 29, 5); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - bb.addButton(ok); - bb.addButton(cancel); - bb.addRelatedGap(); - bb.addButton(new HelpAction(HelpFile.DATABASE_PROPERTIES).getHelpButton()); - bb.addGlue(); - bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - getContentPane().add(builder.getPanel(), BorderLayout.CENTER); - getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); - pack(); - - AbstractAction closeAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - dispose(); - } - }; - ActionMap am = builder.getPanel().getActionMap(); - InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - am.put("close", closeAction); - - ok.addActionListener(e -> { - if (propertiesChanged()) { - storeSettings(); - } - dispose(); - }); - - cancel.addActionListener(e -> dispose()); - } - - private boolean propertiesChanged() { - Charset oldEncoding = panel.getBibDatabaseContext().getMetaData().getEncoding() - .orElse(Globals.prefs.getDefaultEncoding()); - Charset newEncoding = (Charset) encoding.getSelectedItem(); - boolean saveActionsChanged = fieldFormatterCleanupsPanel.hasChanged(); - boolean saveOrderConfigChanged = !getNewSaveOrderConfig().equals(oldSaveOrderConfig); - boolean changed = saveOrderConfigChanged || !newEncoding.equals(oldEncoding) - || !oldFileVal.equals(fileDir.getText()) || !oldFileIndvVal.equals(fileDirIndv.getText()) - || (oldProtectVal != protect.isSelected()) || saveActionsChanged; - return changed; - } - - private SaveOrderConfig getNewSaveOrderConfig() { - SaveOrderConfig saveOrderConfig = null; - if (saveInOriginalOrder.isSelected()) { - saveOrderConfig = SaveOrderConfig.getDefaultSaveOrder(); - } else { - saveOrderConfig = saveOrderPanel.getSaveOrderConfig(); - saveOrderConfig.setSaveInSpecifiedOrder(); - } - return saveOrderConfig; - } - - private void setupSortOrderConfiguration() { - saveInOriginalOrder = new JRadioButton(Localization.lang("Save entries in their original order")); - saveInSpecifiedOrder = new JRadioButton(Localization.lang("Save entries ordered as specified")); - - ButtonGroup bg = new ButtonGroup(); - bg.add(saveInOriginalOrder); - bg.add(saveInSpecifiedOrder); - ActionListener listener = e -> { - boolean selected = e.getSource() == saveInSpecifiedOrder; - saveOrderPanel.setEnabled(selected); - }; - - saveInOriginalOrder.addActionListener(listener); - saveInSpecifiedOrder.addActionListener(listener); - } - - @Override - public void setVisible(boolean visible) { - if (visible) { - setValues(); - } - super.setVisible(visible); - } - - private void setValues() { - Optional charset = panel.getBibDatabaseContext().getMetaData().getEncoding(); - encoding.setSelectedItem(charset.orElse(Globals.prefs.getDefaultEncoding())); - - Optional storedSaveOrderConfig = metaData.getSaveOrderConfig(); - boolean selected; - if (!storedSaveOrderConfig.isPresent()) { - saveInOriginalOrder.setSelected(true); - oldSaveOrderConfig = SaveOrderConfig.getDefaultSaveOrder(); - selected = false; - } else { - SaveOrderConfig saveOrderConfig = storedSaveOrderConfig.get(); - oldSaveOrderConfig = saveOrderConfig; - if (saveOrderConfig.saveInOriginalOrder()) { - saveInOriginalOrder.setSelected(true); - selected = false; - } else { - saveInSpecifiedOrder.setSelected(true); - selected = true; - } - saveOrderPanel.setSaveOrderConfig(saveOrderConfig); - } - saveOrderPanel.setEnabled(selected); - - Optional fileD = metaData.getDefaultFileDirectory(); - if (fileD.isPresent()) { - fileDir.setText(fileD.get().trim()); - } else { - fileDir.setText(""); - } - - String fileDI = metaData.getUserFileDirectory(Globals.prefs.getUser()).orElse(""); // File dir setting - fileDirIndv.setText(fileDI); - oldFileIndvVal = fileDirIndv.getText(); - - protect.setSelected(metaData.isProtected()); - - // Store original values to see if they get changed: - oldFileVal = fileDir.getText(); - oldProtectVal = protect.isSelected(); - - //set save actions - fieldFormatterCleanupsPanel.setValues(metaData); - } - - private void storeSettings() { - Charset oldEncoding = panel.getBibDatabaseContext().getMetaData().getEncoding() - .orElse(Globals.prefs.getDefaultEncoding()); - Charset newEncoding = (Charset) encoding.getSelectedItem(); - panel.getBibDatabaseContext().getMetaData().setEncoding(newEncoding); - - String text = fileDir.getText().trim(); - if (text.isEmpty()) { - metaData.clearDefaultFileDirectory(); - } else { - metaData.setDefaultFileDirectory(text); - } - // Repeat for individual file dir - reuse 'text' and 'dir' vars - text = fileDirIndv.getText(); - if (text.isEmpty()) { - metaData.clearUserFileDirectory(Globals.prefs.getUser()); - } else { - metaData.setUserFileDirectory(Globals.prefs.getUser(), text); - } - - if (protect.isSelected()) { - metaData.markAsProtected(); - } else { - metaData.markAsNotProtected(); - } - - SaveOrderConfig newSaveOrderConfig = getNewSaveOrderConfig(); - - boolean saveOrderConfigChanged = !getNewSaveOrderConfig().equals(oldSaveOrderConfig); - - // See if any of the values have been modified: - if (saveOrderConfigChanged) { - if (newSaveOrderConfig.equals(SaveOrderConfig.getDefaultSaveOrder())) { - metaData.clearSaveOrderConfig(); - } else { - metaData.setSaveOrderConfig(newSaveOrderConfig); - } - } - - boolean saveActionsChanged = fieldFormatterCleanupsPanel.hasChanged(); - if (saveActionsChanged) { - if (fieldFormatterCleanupsPanel.isDefaultSaveActions()) { - metaData.clearSaveActions(); - } else { - fieldFormatterCleanupsPanel.storeSettings(metaData); - } - } - - boolean changed = saveOrderConfigChanged || !newEncoding.equals(oldEncoding) - || !oldFileVal.equals(fileDir.getText()) || !oldFileIndvVal.equals(fileDirIndv.getText()) - || (oldProtectVal != protect.isSelected()) || saveActionsChanged; - // ... if so, mark base changed. Prevent the Undo button from removing - // change marking: - if (changed) { - panel.markNonUndoableBaseChanged(); - } - } -} diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialog.fxml b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialog.fxml new file mode 100644 index 00000000000..126d9e959b6 --- /dev/null +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialog.fxml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +