From 6408ccbb399811c34a9858c831d89938f76e25de Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 7 Aug 2017 14:12:41 -0700 Subject: [PATCH] Add a filter. --- .../java/org/nwapw/abacus/fx/AbacusController.java | 13 ++++++++++++- src/main/resources/abacus.fxml | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index f513529..976f8c7 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -5,6 +5,7 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxListCell; @@ -97,6 +98,8 @@ public class AbacusController implements PluginListener { private TextField computationLimitField; @FXML private ListView functionListView; + @FXML + private TextField functionListSearchField; /** * The list of history entries, created by the users. @@ -118,6 +121,10 @@ public class AbacusController implements PluginListener { * The list of functions that are registered in the calculator. */ private ObservableList functionList; + /** + * The filtered list displayed to the user. + */ + private FilteredList functionFilter; /** * The abacus instance used for changing the plugin configuration. @@ -222,7 +229,10 @@ public class AbacusController implements PluginListener { }); functionList = FXCollections.observableArrayList(); - functionListView.setItems(functionList); + functionFilter = new FilteredList<>(functionList, (s) -> true); + functionListView.setItems(functionFilter); + functionListSearchField.textProperty().addListener((observable, oldValue, newValue) -> + functionFilter.setPredicate((newValue.length() == 0) ? ((s) -> true) : ((s) -> s.contains(newValue)))); historyData = FXCollections.observableArrayList(); historyTable.setItems(historyData); numberImplementationOptions = FXCollections.observableArrayList(); @@ -338,6 +348,7 @@ public class AbacusController implements PluginListener { enabledPlugins.add(plugin); } functionList.addAll(manager.getAllFunctions()); + functionList.sort(String::compareTo); } @Override diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 547e485..63b144a 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -61,10 +61,11 @@ - + +