diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupDialog.java b/src/main/java/org/jabref/gui/cleanup/CleanupDialog.java index 4ac358e8434..4e672761366 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupDialog.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupDialog.java @@ -1,11 +1,8 @@ package org.jabref.gui.cleanup; -import javax.swing.JScrollPane; - import javafx.scene.control.ButtonType; import org.jabref.gui.util.BaseDialog; -import org.jabref.gui.util.ControlHelper; import org.jabref.logic.cleanup.CleanupPreset; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; @@ -18,9 +15,7 @@ public CleanupDialog(BibDatabaseContext databaseContext, CleanupPreset initialPr getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); CleanupPresetPanel presetPanel = new CleanupPresetPanel(databaseContext, initialPreset); - presetPanel.getScrollPane().setVisible(true); - JScrollPane scrollPane = presetPanel.getScrollPane(); - + getDialogPane().setContent(presetPanel); setResultConverter(button -> { if (button == ButtonType.OK) { return presetPanel.getCleanupPreset(); @@ -28,7 +23,5 @@ public CleanupDialog(BibDatabaseContext databaseContext, CleanupPreset initialPr return null; } }); - - ControlHelper.setSwingContent(getDialogPane(), scrollPane); } } diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index b5127707c6c..4bd64ec1f62 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -6,11 +6,11 @@ import java.util.Optional; import java.util.Set; -import javax.swing.ButtonGroup; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; +import javafx.scene.Group; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; +import javafx.scene.layout.GridPane; import org.jabref.Globals; import org.jabref.logic.cleanup.CleanupPreset; @@ -20,25 +20,20 @@ import org.jabref.model.entry.FieldName; import org.jabref.preferences.JabRefPreferences; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; - -public class CleanupPresetPanel { +public class CleanupPresetPanel extends ScrollPane { private final BibDatabaseContext databaseContext; - private JCheckBox cleanUpDOI; - private JCheckBox cleanUpISSN; - private JCheckBox cleanUpMovePDF; - private JCheckBox cleanUpMakePathsRelative; - private JCheckBox cleanUpRenamePDF; - private JCheckBox cleanUpRenamePDFonlyRelativePaths; - private JCheckBox cleanUpUpgradeExternalLinks; - private JCheckBox cleanUpBiblatex; - private JCheckBox cleanUpBibtex; + private CheckBox cleanUpDOI; + private CheckBox cleanUpISSN; + private CheckBox cleanUpMovePDF; + private CheckBox cleanUpMakePathsRelative; + private CheckBox cleanUpRenamePDF; + private CheckBox cleanUpRenamePDFonlyRelativePaths; + private CheckBox cleanUpUpgradeExternalLinks; + private CheckBox cleanUpBiblatex; + private CheckBox cleanUpBibtex; private FieldFormatterCleanupsPanel cleanUpFormatters; - private JPanel panel; - private JScrollPane scrollPane; private CleanupPreset cleanupPreset; public CleanupPresetPanel(BibDatabaseContext databaseContext, CleanupPreset cleanupPreset) { @@ -48,76 +43,69 @@ public CleanupPresetPanel(BibDatabaseContext databaseContext, CleanupPreset clea } private void init() { - cleanUpDOI = new JCheckBox( + cleanUpDOI = new CheckBox( Localization.lang("Move DOIs from note and URL field to DOI field and remove http prefix")); - cleanUpISSN = new JCheckBox(Localization.lang("Reformat ISSN")); - + cleanUpISSN = new CheckBox(Localization.lang("Reformat ISSN")); Optional firstExistingDir = databaseContext .getFirstExistingFileDir(JabRefPreferences.getInstance().getFilePreferences()); if (firstExistingDir.isPresent()) { - cleanUpMovePDF = new JCheckBox(Localization.lang("Move linked files to default file directory %0", + cleanUpMovePDF = new CheckBox(Localization.lang("Move linked files to default file directory %0", firstExistingDir.get().toString())); } else { - cleanUpMovePDF = new JCheckBox(Localization.lang("Move linked files to default file directory %0", "...")); - cleanUpMovePDF.setEnabled(false); + cleanUpMovePDF = new CheckBox(Localization.lang("Move linked files to default file directory %0", "...")); + cleanUpMovePDF.setDisable(true); // Since the directory does not exist, we cannot move it to there. So, this option is not checked - regardless of the presets stored in the preferences. cleanUpMovePDF.setSelected(false); } - - cleanUpMakePathsRelative = new JCheckBox( + cleanUpMakePathsRelative = new CheckBox( Localization.lang("Make paths of linked files relative (if possible)")); - cleanUpRenamePDF = new JCheckBox(Localization.lang("Rename PDFs to given filename format pattern")); - cleanUpRenamePDF.addChangeListener( - event -> cleanUpRenamePDFonlyRelativePaths.setEnabled(cleanUpRenamePDF.isSelected())); - cleanUpRenamePDFonlyRelativePaths = new JCheckBox(Localization.lang("Rename only PDFs having a relative path")); - cleanUpUpgradeExternalLinks = new JCheckBox( + cleanUpRenamePDF = new CheckBox(Localization.lang("Rename PDFs to given filename format pattern")); + cleanUpRenamePDF.selectedProperty().addListener( + event -> cleanUpRenamePDFonlyRelativePaths.setDisable(!cleanUpRenamePDF.isSelected())); + cleanUpRenamePDFonlyRelativePaths = new CheckBox(Localization.lang("Rename only PDFs having a relative path")); + cleanUpUpgradeExternalLinks = new CheckBox( Localization.lang("Upgrade external PDF/PS links to use the '%0' field.", FieldName.FILE)); - cleanUpBiblatex = new JCheckBox(Localization.lang( + cleanUpBiblatex = new CheckBox(Localization.lang( "Convert to biblatex format (for example, move the value of the 'journal' field to 'journaltitle')")); - cleanUpBibtex = new JCheckBox(Localization.lang( + cleanUpBibtex = new CheckBox(Localization.lang( "Convert to BibTeX format (for example, move the value of the 'journaltitle' field to 'journal')")); - ButtonGroup biblatexConversion = new ButtonGroup(); // Only make "to Biblatex" or "to BibTeX" selectable - biblatexConversion.add(cleanUpBiblatex); - biblatexConversion.add(cleanUpBibtex); + Group biblatexConversion = new Group(); // Only make "to Biblatex" or "to BibTeX" selectable + biblatexConversion.getChildren().add(cleanUpBiblatex); + biblatexConversion.getChildren().add(cleanUpBibtex); cleanUpFormatters = new FieldFormatterCleanupsPanel(Localization.lang("Run field formatter:"), Cleanups.DEFAULT_SAVE_ACTIONS); updateDisplay(cleanupPreset); - FormLayout layout = new FormLayout("left:15dlu, fill:pref:grow", - "pref, pref, pref, pref, pref, fill:pref:grow, pref,pref, pref, pref,190dlu, fill:pref:grow,"); - - FormBuilder builder = FormBuilder.create().layout(layout); - builder.add(cleanUpDOI).xyw(1, 1, 2); - builder.add(cleanUpUpgradeExternalLinks).xyw(1, 2, 2); - builder.add(cleanUpMovePDF).xyw(1, 3, 2); - builder.add(cleanUpMakePathsRelative).xyw(1, 4, 2); - builder.add(cleanUpRenamePDF).xyw(1, 5, 2); + GridPane container = new GridPane(); + container.add(cleanUpDOI, 0, 0); + container.add(cleanUpUpgradeExternalLinks, 0, 1); + container.add(cleanUpMovePDF, 0, 2); + container.add(cleanUpMakePathsRelative, 0, 3); + container.add(cleanUpRenamePDF, 0, 4); String currentPattern = Localization.lang("Filename format pattern").concat(": "); currentPattern = currentPattern.concat(Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN)); - builder.add(new JLabel(currentPattern)).xy(2, 6); - builder.add(cleanUpRenamePDFonlyRelativePaths).xy(2, 7); - builder.add(cleanUpBibtex).xyw(1, 8, 2); - builder.add(cleanUpBiblatex).xyw(1, 9, 2); - builder.add(cleanUpISSN).xyw(1, 10, 2); - builder.add(cleanUpFormatters).xyw(1, 11, 2); - panel = builder.build(); - scrollPane = new JScrollPane(panel); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - scrollPane.setVisible(true); - scrollPane.setBorder(null); + container.add(new Label(currentPattern), 0, 5); + container.add(cleanUpRenamePDFonlyRelativePaths, 0, 6); + container.add(cleanUpBibtex, 0, 7); + container.add(cleanUpBiblatex, 0, 8); + container.add(cleanUpISSN, 0, 9); + container.add(cleanUpFormatters, 0, 10); + + setContent(container); + setVbarPolicy(ScrollBarPolicy.AS_NEEDED); } private void updateDisplay(CleanupPreset preset) { cleanUpDOI.setSelected(preset.isCleanUpDOI()); - if (cleanUpMovePDF.isEnabled()) { + if (!cleanUpMovePDF.isDisabled()) { cleanUpMovePDF.setSelected(preset.isMovePDF()); } cleanUpMakePathsRelative.setSelected(preset.isMakePathsRelative()); cleanUpRenamePDF.setSelected(preset.isRenamePDF()); cleanUpRenamePDFonlyRelativePaths.setSelected(preset.isRenamePdfOnlyRelativePaths()); - cleanUpRenamePDFonlyRelativePaths.setEnabled(cleanUpRenamePDF.isSelected()); + cleanUpRenamePDFonlyRelativePaths.setDisable(!cleanUpRenamePDF.isSelected()); cleanUpUpgradeExternalLinks.setSelected(preset.isCleanUpUpgradeExternalLinks()); cleanUpBiblatex.setSelected(preset.isConvertToBiblatex()); cleanUpBibtex.setSelected(preset.isConvertToBibtex()); @@ -125,10 +113,6 @@ private void updateDisplay(CleanupPreset preset) { cleanUpFormatters.setValues(preset.getFormatterCleanups()); } - public JScrollPane getScrollPane() { - return scrollPane; - } - public CleanupPreset getCleanupPreset() { Set activeJobs = EnumSet.noneOf(CleanupPreset.CleanupStep.class); diff --git a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java index 9f91f376465..b2aaec4108c 100644 --- a/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java +++ b/src/main/java/org/jabref/gui/cleanup/FieldFormatterCleanupsPanel.java @@ -1,32 +1,27 @@ package org.jabref.gui.cleanup; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; - -import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.ListSelectionModel; -import javax.swing.UIManager; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.ListView; +import javafx.scene.control.SelectionMode; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.RowConstraints; import org.jabref.Globals; import org.jabref.JabRefGUI; +import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.cleanup.Cleanups; import org.jabref.logic.formatter.casechanger.ProtectTermsFormatter; import org.jabref.logic.l10n.Localization; @@ -38,30 +33,29 @@ import org.jabref.model.entry.InternalBibtexFields; import org.jabref.model.metadata.MetaData; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; +import org.fxmisc.easybind.EasyBind; -public class FieldFormatterCleanupsPanel extends JPanel { +public class FieldFormatterCleanupsPanel extends GridPane { private static final String DESCRIPTION = Localization.lang("Description") + ": "; - private final JCheckBox cleanupEnabled; + private final CheckBox cleanupEnabled; private FieldFormatterCleanups fieldFormatterCleanups; - private JList actionsList; - private JComboBox formattersCombobox; - private JComboBox selectFieldCombobox; - private JButton addButton; - private JTextArea descriptionAreaText; - private JButton removeButton; - private JButton resetButton; - private JButton recommendButton; + private ListView actionsList; + private ComboBox formattersCombobox; + private ComboBox selectFieldCombobox; + private Button addButton; + private Label descriptionAreaText; + private Button removeButton; + private Button resetButton; + private Button recommendButton; private final FieldFormatterCleanups defaultFormatters; - private List availableFormatters; - + private final List availableFormatters; + private ObservableList actions; public FieldFormatterCleanupsPanel(String description, FieldFormatterCleanups defaultFormatters) { this.defaultFormatters = Objects.requireNonNull(defaultFormatters); - cleanupEnabled = new JCheckBox(description); + cleanupEnabled = new CheckBox(description); availableFormatters = Cleanups.getBuiltInFormatters(); availableFormatters.add(new ProtectTermsFormatter(Globals.protectedTermsLoader)); } @@ -76,127 +70,84 @@ public void setValues(FieldFormatterCleanups formatterCleanups) { fieldFormatterCleanups = formatterCleanups; // first clear existing content - this.removeAll(); + this.getChildren().clear(); List configuredActions = fieldFormatterCleanups.getConfiguredActions(); - //The copy is necessary because the original List is unmodifiable - List actionsToDisplay = new ArrayList<>(configuredActions); - buildLayout(actionsToDisplay); - + actions = FXCollections.observableArrayList(configuredActions); + buildLayout(); } - private void buildLayout(List actionsToDisplay) { - FormBuilder builder = FormBuilder.create().layout(new FormLayout( - "left:pref, 13dlu, left:pref:grow, 4dlu, pref, 4dlu, pref", - "pref, 2dlu, pref, 2dlu, pref, 4dlu, pref, 2dlu, fill:pref:grow, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu")); - builder.add(cleanupEnabled).xyw(1, 1, 7); - - actionsList = new JList<>(new CleanupActionsListModel(actionsToDisplay)); - actionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - actionsList.addMouseMotionListener(new MouseMotionAdapter() { - - @Override - public void mouseMoved(MouseEvent e) { - super.mouseMoved(e); - CleanupActionsListModel m = (CleanupActionsListModel) actionsList.getModel(); - int index = actionsList.locationToIndex(e.getPoint()); - if (index > -1) { - actionsList.setToolTipText(m.getElementAt(index).getFormatter().getDescription()); - } - } - }); - - actionsList.getModel().addListDataListener(new ListDataListener() { - - @Override - public void intervalRemoved(ListDataEvent e) { - //index0 is sufficient, because of SingleSelection - if (e.getIndex0() == 0) { - //when an item gets deleted, the next one becomes the new 0 - actionsList.setSelectedIndex(e.getIndex0()); - } - if (e.getIndex0() > 0) { - actionsList.setSelectedIndex(e.getIndex0() - 1); - } - - } - - @Override - public void intervalAdded(ListDataEvent e) { - //empty, not needed - - } - - @Override - public void contentsChanged(ListDataEvent e) { - //empty, not needed - - } - }); - - builder.add(actionsList).xyw(3, 5, 5); - - resetButton = new JButton(Localization.lang("Reset")); - resetButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).reset(defaultFormatters)); + private void buildLayout() { + ColumnConstraints first = new ColumnConstraints(); + first.setPrefWidth(25); + ColumnConstraints second = new ColumnConstraints(); + second.setPrefWidth(175); + ColumnConstraints third = new ColumnConstraints(); + third.setPrefWidth(200); + ColumnConstraints fourth = new ColumnConstraints(); + fourth.setPrefWidth(200); + getColumnConstraints().addAll(first, second, third, fourth); + RowConstraints firstR = new RowConstraints(); + firstR.setPrefHeight(25); + RowConstraints secondR = new RowConstraints(); + secondR.setPrefHeight(100); + RowConstraints thirdR = new RowConstraints(); + thirdR.setPrefHeight(50); + RowConstraints fourthR = new RowConstraints(); + fourthR.setPrefHeight(50); + RowConstraints fifthR = new RowConstraints(); + fifthR.setPrefHeight(50); + getRowConstraints().addAll(firstR, secondR, thirdR, fourthR, fifthR); + add(cleanupEnabled, 0, 0, 4, 1); + + actionsList = new ListView<>(actions); + actionsList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); + new ViewModelListCellFactory() + .withText(action -> action.getFormatter().getName()) + .withTooltip(action -> action.getFormatter().getDescription()) + .install(actionsList); + add(actionsList, 1, 1, 3, 1); + + resetButton = new Button(Localization.lang("Reset")); + resetButton.setOnAction(e -> actions.setAll(defaultFormatters.getConfiguredActions())); BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(); - recommendButton = new JButton(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName())); + recommendButton = new Button(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName())); boolean isBiblatex = databaseContext.isBiblatexMode(); - recommendButton.addActionListener(e -> { + recommendButton.setOnAction(e -> { if (isBiblatex) { - ((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBLATEX_ACTIONS); + actions.setAll(Cleanups.RECOMMEND_BIBLATEX_ACTIONS.getConfiguredActions()); } else { - ((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBTEX_ACTIONS); + actions.setAll(Cleanups.RECOMMEND_BIBTEX_ACTIONS.getConfiguredActions()); } }); - removeButton = new JButton(Localization.lang("Remove selected")); - removeButton.addActionListener( - e -> ((CleanupActionsListModel) actionsList.getModel()).removeAtIndex(actionsList.getSelectedIndex())); + removeButton = new Button(Localization.lang("Remove selected")); + removeButton.setOnAction(e -> actions.remove(actionsList.getSelectionModel().getSelectedItem())); + descriptionAreaText = new Label(DESCRIPTION); + descriptionAreaText.setWrapText(true); - builder.add(removeButton).xy(7, 11); - builder.add(resetButton).xy(3, 11); - builder.add(recommendButton).xy(5, 11); - builder.add(getSelectorPanel()).xyw(3, 15, 5); - - makeDescriptionTextAreaLikeJLabel(); - builder.add(descriptionAreaText).xyw(3, 17, 5); - this.setLayout(new BorderLayout()); - this.add(builder.getPanel(), BorderLayout.WEST); + add(removeButton, 3, 2, 1, 1); + add(resetButton, 1, 2, 1, 1); + add(recommendButton, 2, 2, 1, 1); + add(getSelectorPanel(), 1, 3, 3, 1); + add(descriptionAreaText, 1, 4, 3, 1); updateDescription(); // make sure the layout is set according to the checkbox - cleanupEnabled.addActionListener(new EnablementStatusListener(fieldFormatterCleanups.isEnabled())); + cleanupEnabled.selectedProperty().addListener(new EnablementStatusListener<>(fieldFormatterCleanups.isEnabled())); cleanupEnabled.setSelected(fieldFormatterCleanups.isEnabled()); - - } - - /** - * Create a TextArea that looks and behaves like a JLabel. Has the advantage of supporting multine and wordwrap - */ - private void makeDescriptionTextAreaLikeJLabel() { - - descriptionAreaText = new JTextArea(DESCRIPTION); - descriptionAreaText.setLineWrap(true); - descriptionAreaText.setWrapStyleWord(true); - descriptionAreaText.setColumns(6); - descriptionAreaText.setEditable(false); - descriptionAreaText.setOpaque(false); - descriptionAreaText.setFocusable(false); - descriptionAreaText.setCursor(null); - descriptionAreaText.setFont(UIManager.getFont("Label.font")); - } private void updateDescription() { FieldFormatterCleanup formatterCleanup = getFieldFormatterCleanup(); - if (formatterCleanup != null) { + if (formatterCleanup.getFormatter() != null) { descriptionAreaText.setText(DESCRIPTION + formatterCleanup.getFormatter().getDescription()); } else { - Formatter selectedFormatter = getFieldFormatter(); + Formatter selectedFormatter = formattersCombobox.getValue(); if (selectedFormatter != null) { descriptionAreaText.setText(DESCRIPTION + selectedFormatter.getDescription()); } else { @@ -207,55 +158,35 @@ private void updateDescription() { /** * This panel contains the two comboboxes and the Add button - * @return Returns the created JPanel */ - private JPanel getSelectorPanel() { - FormBuilder builder = FormBuilder.create() - .layout(new FormLayout("left:pref:grow, 4dlu, left:pref:grow, 4dlu, fill:pref:grow, 4dlu, right:pref", - "fill:pref:grow, 2dlu, pref, 2dlu")); - + private GridPane getSelectorPanel() { + GridPane builder = new GridPane(); List fieldNames = InternalBibtexFields.getAllPublicAndInternalFieldNames(); fieldNames.add(BibEntry.KEY_FIELD); Collections.sort(fieldNames); - String[] allPlusKey = fieldNames.toArray(new String[fieldNames.size()]); - - selectFieldCombobox = new JComboBox<>(allPlusKey); + selectFieldCombobox = new ComboBox<>(FXCollections.observableArrayList(fieldNames)); selectFieldCombobox.setEditable(true); - builder.add(selectFieldCombobox).xy(1, 1); - - List formatterNames = availableFormatters.stream() - .map(Formatter::getName).collect(Collectors.toList()); - List formatterDescriptions = availableFormatters.stream() - .map(Formatter::getDescription).collect(Collectors.toList()); - formattersCombobox = new JComboBox<>(formatterNames.toArray()); - formattersCombobox.setRenderer(new DefaultListCellRenderer() { - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, - boolean cellHasFocus) { - if ((-1 < index) && (index < formatterDescriptions.size()) && (value != null)) { - setToolTipText(formatterDescriptions.get(index)); - - } - return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - } - }); - formattersCombobox.addItemListener(e -> updateDescription()); - builder.add(formattersCombobox).xy(3, 1); - - addButton = new JButton(Localization.lang("Add")); - addButton.addActionListener(e -> { + builder.add(selectFieldCombobox, 1, 1); + + formattersCombobox = new ComboBox<>(FXCollections.observableArrayList(availableFormatters)); + new ViewModelListCellFactory() + .withText(Formatter::getName) + .withTooltip(Formatter::getDescription) + .install(formattersCombobox); + EasyBind.subscribe(formattersCombobox.valueProperty(), e -> updateDescription()); + builder.add(formattersCombobox, 3, 1); + + addButton = new Button(Localization.lang("Add")); + addButton.setOnAction(e -> { FieldFormatterCleanup newAction = getFieldFormatterCleanup(); - if (newAction == null) { - return; - } - - ((CleanupActionsListModel) actionsList.getModel()).addCleanupAction(newAction); + if (!actions.contains(newAction)) { + actions.add(newAction); + } }); - builder.add(addButton).xy(5, 1); + builder.add(addButton, 5, 1); - return builder.getPanel(); + return builder; } public void storeSettings(MetaData metaData) { @@ -273,7 +204,6 @@ public void storeSettings(MetaData metaData) { } public FieldFormatterCleanups getFormatterCleanups() { - List actions = ((CleanupActionsListModel) actionsList.getModel()).getAllActions(); return new FieldFormatterCleanups(cleanupEnabled.isSelected(), actions); } @@ -286,47 +216,30 @@ public boolean isDefaultSaveActions() { } private FieldFormatterCleanup getFieldFormatterCleanup() { - Formatter selectedFormatter = getFieldFormatter(); - - String fieldKey = selectFieldCombobox.getSelectedItem().toString(); + Formatter selectedFormatter = formattersCombobox.getValue(); + String fieldKey = selectFieldCombobox.getValue(); return new FieldFormatterCleanup(fieldKey, selectedFormatter); - - } - - private Formatter getFieldFormatter() { - Formatter selectedFormatter = null; - String selectedFormatterName = formattersCombobox.getSelectedItem().toString(); - for (Formatter formatter : availableFormatters) { - if (formatter.getName().equals(selectedFormatterName)) { - selectedFormatter = formatter; - break; - } - } - return selectedFormatter; } - class EnablementStatusListener implements ActionListener { + class EnablementStatusListener implements ChangeListener { public EnablementStatusListener(boolean initialStatus) { setStatus(initialStatus); } - @Override - public void actionPerformed(ActionEvent e) { - boolean enablementStatus = cleanupEnabled.isSelected(); - setStatus(enablementStatus); - - } - private void setStatus(boolean status) { - actionsList.setEnabled(status); - selectFieldCombobox.setEnabled(status); - formattersCombobox.setEnabled(status); - addButton.setEnabled(status); - removeButton.setEnabled(status); - resetButton.setEnabled(status); - recommendButton.setEnabled(status); + actionsList.setDisable(!status); + selectFieldCombobox.setDisable(!status); + formattersCombobox.setDisable(!status); + addButton.setDisable(!status); + removeButton.setDisable(!status); + resetButton.setDisable(!status); + recommendButton.setDisable(!status); + } + @Override + public void changed(ObservableValue observable, T oldValue, T newValue) { + setStatus(cleanupEnabled.isSelected()); } } diff --git a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java b/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java index 1a908f2814b..f1a58b0be7c 100644 --- a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java +++ b/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java @@ -141,7 +141,7 @@ private void init() { fieldFormatterCleanupsPanel = new FieldFormatterCleanupsPanel(Localization.lang("Enable save actions"), Cleanups.DEFAULT_SAVE_ACTIONS); builder.addSeparator(Localization.lang("Save actions")).xyw(1, 27, 5); - builder.add(fieldFormatterCleanupsPanel).xyw(1, 29, 5); + builder.add(CustomJFXPanel.wrap(new Scene(fieldFormatterCleanupsPanel))).xyw(1, 29, 5); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); diff --git a/src/main/java/org/jabref/gui/util/ControlHelper.java b/src/main/java/org/jabref/gui/util/ControlHelper.java index 88d03df9bdb..b5d139b338a 100644 --- a/src/main/java/org/jabref/gui/util/ControlHelper.java +++ b/src/main/java/org/jabref/gui/util/ControlHelper.java @@ -28,7 +28,6 @@ public static void setSwingContent(DialogPane dialogPane, JComponent content) { SwingNode node = new SwingNode(); node.setContent(content); node.setVisible(true); - dialogPane.setContent(node); }