1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 23:40:08 -08:00

Add a filter.

This commit is contained in:
Danila Fedorin 2017-08-07 14:12:41 -07:00
parent 4a4d1bc46a
commit 6408ccbb39
2 changed files with 14 additions and 2 deletions

View File

@ -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<String> 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<String> functionList;
/**
* The filtered list displayed to the user.
*/
private FilteredList<String> 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

View File

@ -61,10 +61,11 @@
</GridPane>
</Tab>
<Tab fx:id="functionListTab" text="Functions" closable="false">
<VBox>
<VBox spacing="10">
<padding>
<Insets left="10" right="10" top="10" bottom="10"/>
</padding>
<TextField fx:id="functionListSearchField" maxWidth="Infinity"/>
<ListView maxWidth="Infinity" fx:id="functionListView"/>
</VBox>
</Tab>