diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.fxml b/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.fxml index 399e2c9fc27..e69a587836e 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.fxml +++ b/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.fxml @@ -7,21 +7,30 @@ + + - - - + + + + + + + + + +
diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.java b/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.java index 09d01ec3510..54b5e34c1f3 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.java @@ -1,16 +1,20 @@ package org.jabref.gui.preferences; +import java.util.Locale; import java.util.Objects; +import javafx.beans.binding.Bindings; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.property.ReadOnlyStringWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.control.TextField; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; @@ -22,6 +26,7 @@ public class PreferencesFilterDialog extends BaseDialog { private final JabRefPreferencesFilter preferencesFilter; private final ObservableList preferenceOptions; + private final FilteredList filteredOptions; @FXML private TableView table; @FXML private TableColumn columnType; @@ -30,10 +35,12 @@ public class PreferencesFilterDialog extends BaseDialog { @FXML private TableColumn columnDefaultValue; @FXML private CheckBox showOnlyDeviatingPreferenceOptions; @FXML private Label count; + @FXML private TextField searchField; public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { this.preferencesFilter = Objects.requireNonNull(preferencesFilter); this.preferenceOptions = FXCollections.observableArrayList(); + this.filteredOptions = new FilteredList<>(this.preferenceOptions); ViewLoader.view(this) .load() @@ -45,11 +52,20 @@ public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { @FXML private void initialize() { showOnlyDeviatingPreferenceOptions.setOnAction(event -> updateModel()); + filteredOptions.predicateProperty().bind(Bindings.createObjectBinding(() -> { + String searchText = searchField.getText(); + if ((searchText == null) || searchText.isEmpty()) { + return null; + } + String lowerCaseSearchText = searchText.toLowerCase(Locale.ROOT); + return (option) -> option.getKey().toLowerCase(Locale.ROOT).contains(lowerCaseSearchText); + }, searchField.textProperty())); columnType.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getType())); columnKey.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getKey())); columnValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getValue())); columnDefaultValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getDefaultValue().orElse(""))); - table.setItems(preferenceOptions); + table.setItems(filteredOptions); + count.textProperty().bind(Bindings.size(table.getItems()).asString("(%d)")); updateModel(); } @@ -59,6 +75,6 @@ private void updateModel() { } else { preferenceOptions.setAll(preferencesFilter.getPreferenceOptions()); } - count.setText(String.format("(%d)", preferenceOptions.size())); } + }