|
1 | 1 | package org.jabref.gui.preferences; |
2 | 2 |
|
3 | | -import java.awt.BorderLayout; |
4 | | -import java.awt.Dimension; |
5 | | -import java.awt.FlowLayout; |
6 | | -import java.util.List; |
7 | 3 | import java.util.Objects; |
8 | 4 |
|
9 | | -import javax.swing.JCheckBox; |
10 | | -import javax.swing.JLabel; |
11 | | -import javax.swing.JPanel; |
12 | | -import javax.swing.JScrollPane; |
13 | | -import javax.swing.JTable; |
14 | | -import javax.swing.table.AbstractTableModel; |
15 | | - |
16 | | -import org.jabref.gui.JabRefDialog; |
17 | | -import org.jabref.gui.WrapLayout; |
| 5 | +import javafx.beans.property.ReadOnlyObjectWrapper; |
| 6 | +import javafx.beans.property.ReadOnlyStringWrapper; |
| 7 | +import javafx.collections.FXCollections; |
| 8 | +import javafx.collections.ObservableList; |
| 9 | +import javafx.fxml.FXML; |
| 10 | +import javafx.scene.control.CheckBox; |
| 11 | +import javafx.scene.control.Label; |
| 12 | +import javafx.scene.control.TableColumn; |
| 13 | +import javafx.scene.control.TableView; |
| 14 | + |
| 15 | +import org.jabref.gui.util.BaseDialog; |
18 | 16 | import org.jabref.logic.l10n.Localization; |
19 | 17 | import org.jabref.preferences.JabRefPreferencesFilter; |
20 | 18 |
|
21 | | -class PreferencesFilterDialog extends JabRefDialog { |
| 19 | +import com.airhacks.afterburner.views.ViewLoader; |
| 20 | + |
| 21 | +public class PreferencesFilterDialog extends BaseDialog<Void> { |
22 | 22 |
|
23 | 23 | private final JabRefPreferencesFilter preferencesFilter; |
| 24 | + private final ObservableList<JabRefPreferencesFilter.PreferenceOption> preferenceOptions; |
24 | 25 |
|
25 | | - private final JTable table; |
26 | | - private final JCheckBox showOnlyDeviatingPreferenceOptions; |
27 | | - private final JLabel count; |
| 26 | + @FXML private TableView<JabRefPreferencesFilter.PreferenceOption> table; |
| 27 | + @FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, JabRefPreferencesFilter.PreferenceType> columnType; |
| 28 | + @FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, String> columnKey; |
| 29 | + @FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, Object> columnValue; |
| 30 | + @FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, Object> columnDefaultValue; |
| 31 | + @FXML private CheckBox showOnlyDeviatingPreferenceOptions; |
| 32 | + @FXML private Label count; |
28 | 33 |
|
29 | 34 | public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { |
30 | | - super(true, PreferencesFilterDialog.class); |
31 | | - |
32 | 35 | this.preferencesFilter = Objects.requireNonNull(preferencesFilter); |
| 36 | + this.preferenceOptions = FXCollections.observableArrayList(); |
33 | 37 |
|
34 | | - this.setTitle(Localization.lang("Preferences")); |
35 | | - this.setSize(new Dimension(800, 600)); |
| 38 | + ViewLoader.view(this) |
| 39 | + .load() |
| 40 | + .setAsDialogPane(this); |
36 | 41 |
|
37 | | - JPanel panel = new JPanel(); |
38 | | - panel.setLayout(new BorderLayout()); |
39 | | - |
40 | | - JPanel northPanel = new JPanel(); |
41 | | - northPanel.setLayout(new WrapLayout(FlowLayout.LEFT)); |
42 | | - showOnlyDeviatingPreferenceOptions = new JCheckBox(Localization.lang("Show only preferences deviating from their default value"), false); |
43 | | - showOnlyDeviatingPreferenceOptions.addChangeListener(x -> updateModel()); |
44 | | - northPanel.add(showOnlyDeviatingPreferenceOptions); |
45 | | - count = new JLabel(); |
46 | | - northPanel.add(count); |
47 | | - panel.add(northPanel, BorderLayout.NORTH); |
48 | | - |
49 | | - table = new JTable(); |
50 | | - table.setAutoCreateRowSorter(true); |
| 42 | + this.setTitle(Localization.lang("Preferences")); |
| 43 | + } |
51 | 44 |
|
| 45 | + @FXML |
| 46 | + private void initialize() { |
| 47 | + showOnlyDeviatingPreferenceOptions.setOnAction(event -> updateModel()); |
| 48 | + columnType.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getType())); |
| 49 | + columnKey.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getKey())); |
| 50 | + columnValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getValue())); |
| 51 | + columnDefaultValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getDefaultValue().orElse(""))); |
| 52 | + table.setItems(preferenceOptions); |
52 | 53 | updateModel(); |
53 | | - panel.add(new JScrollPane(table), BorderLayout.CENTER); |
54 | | - |
55 | | - this.getContentPane().add(panel); |
56 | 54 | } |
57 | 55 |
|
58 | 56 | private void updateModel() { |
59 | | - List<JabRefPreferencesFilter.PreferenceOption> preferenceOptions; |
60 | | - |
61 | 57 | if (showOnlyDeviatingPreferenceOptions.isSelected()) { |
62 | | - preferenceOptions = preferencesFilter.getDeviatingPreferences(); |
| 58 | + preferenceOptions.setAll(preferencesFilter.getDeviatingPreferences()); |
63 | 59 | } else { |
64 | | - preferenceOptions = preferencesFilter.getPreferenceOptions(); |
| 60 | + preferenceOptions.setAll(preferencesFilter.getPreferenceOptions()); |
65 | 61 | } |
66 | | - |
67 | | - table.setModel(new PreferencesTableModel(preferenceOptions)); |
68 | 62 | count.setText(String.format("(%d)", preferenceOptions.size())); |
69 | 63 | } |
70 | | - |
71 | | - private static class PreferencesTableModel extends AbstractTableModel { |
72 | | - |
73 | | - private final List<JabRefPreferencesFilter.PreferenceOption> preferences; |
74 | | - |
75 | | - public PreferencesTableModel(List<JabRefPreferencesFilter.PreferenceOption> preferences) { |
76 | | - this.preferences = Objects.requireNonNull(preferences); |
77 | | - } |
78 | | - |
79 | | - @Override |
80 | | - public String getColumnName(int column) { |
81 | | - if (column == 0) { |
82 | | - return Localization.lang("type"); |
83 | | - } else if (column == 1) { |
84 | | - return Localization.lang("key"); |
85 | | - } else if (column == 2) { |
86 | | - return Localization.lang("value"); |
87 | | - } else if (column == 3) { |
88 | | - return Localization.lang("default"); |
89 | | - } else { |
90 | | - return "n/a"; |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - @Override |
95 | | - public int getRowCount() { |
96 | | - return preferences.size(); |
97 | | - } |
98 | | - |
99 | | - @Override |
100 | | - public int getColumnCount() { |
101 | | - return 4; |
102 | | - } |
103 | | - |
104 | | - @Override |
105 | | - public Object getValueAt(int rowIndex, int columnIndex) { |
106 | | - if ((rowIndex < 0) || ((rowIndex - 1) > preferences.size())) { |
107 | | - return "n/a"; |
108 | | - } |
109 | | - |
110 | | - JabRefPreferencesFilter.PreferenceOption preferenceOption = preferences.get(rowIndex); |
111 | | - if (columnIndex == 0) { |
112 | | - return preferenceOption.getType(); |
113 | | - } else if (columnIndex == 1) { |
114 | | - return preferenceOption.getKey(); |
115 | | - } else if (columnIndex == 2) { |
116 | | - return preferenceOption.getValue(); |
117 | | - } else if (columnIndex == 3) { |
118 | | - return preferenceOption.getDefaultValue().orElse("NULL"); |
119 | | - } else { |
120 | | - return "n/a"; |
121 | | - } |
122 | | - } |
123 | | - } |
124 | | - |
125 | 64 | } |
0 commit comments