1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Add a check box list cell generator.

This commit is contained in:
Danila Fedorin 2017-08-02 18:48:42 -07:00
parent 88e4a87d81
commit e49f28a850

View File

@ -4,8 +4,10 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxListCell;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.StringConverter;
import org.nwapw.abacus.Abacus; import org.nwapw.abacus.Abacus;
import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.number.NumberInterface;
import org.nwapw.abacus.tree.TreeNode; import org.nwapw.abacus.tree.TreeNode;
@ -43,7 +45,7 @@ public class AbacusController {
@FXML @FXML
private ComboBox<String> numberImplementationBox; private ComboBox<String> numberImplementationBox;
@FXML @FXML
private ListView enabledPluginView; private ListView<ToggleablePlugin> enabledPluginView;
@FXML @FXML
private Button reloadButton; private Button reloadButton;
@ -58,12 +60,30 @@ public class AbacusController {
*/ */
private ObservableList<String> numberImplementationOptions; private ObservableList<String> numberImplementationOptions;
/**
* The list of plugin objects that can be toggled on and off,
* and, when reloaded, get added to the plugin manager's black list.
*/
private ObservableList<ToggleablePlugin> enabledPlugins;
private Abacus abacus; private Abacus abacus;
@FXML @FXML
public void initialize(){ public void initialize(){
Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory = Callback<TableColumn<HistoryModel, String>, TableCell<HistoryModel, String>> cellFactory =
param -> new CopyableCell<>(); param -> new CopyableCell<>();
Callback<ListView<ToggleablePlugin>, ListCell<ToggleablePlugin>> pluginCellFactory =
param -> new CheckBoxListCell<>(ToggleablePlugin::enabledProperty, new StringConverter<ToggleablePlugin>() {
@Override
public String toString(ToggleablePlugin object) {
return object.getClassName().substring(object.getClassName().lastIndexOf('.') + 1);
}
@Override
public ToggleablePlugin fromString(String string) {
return new ToggleablePlugin(true, string);
}
});
historyData = FXCollections.observableArrayList(); historyData = FXCollections.observableArrayList();
historyTable.setItems(historyData); historyTable.setItems(historyData);
@ -75,6 +95,9 @@ public class AbacusController {
abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE); abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE);
}); });
historyTable.getSelectionModel().setCellSelectionEnabled(true); historyTable.getSelectionModel().setCellSelectionEnabled(true);
enabledPlugins = FXCollections.observableArrayList();
enabledPluginView.setItems(enabledPlugins);
enabledPluginView.setCellFactory(pluginCellFactory);
inputColumn.setCellFactory(cellFactory); inputColumn.setCellFactory(cellFactory);
inputColumn.setCellValueFactory(cell -> cell.getValue().inputProperty()); inputColumn.setCellValueFactory(cell -> cell.getValue().inputProperty());
parsedColumn.setCellFactory(cellFactory); parsedColumn.setCellFactory(cellFactory);