mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Table: disable buttons when appropriate
This commit is contained in:
parent
50cefbfd53
commit
f67c9a9d19
3 changed files with 25 additions and 20 deletions
|
@ -20,11 +20,6 @@ public class Main extends Application {
|
|||
primaryStage.setOnHiding(event -> AppPrefs.save());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
super.stop();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TableController implements Initializable {
|
|||
@FXML
|
||||
private TextField newQuestionField, newAnswerField, searchField;
|
||||
@FXML
|
||||
private Button addButton;
|
||||
private Button addButton, testButton;
|
||||
@FXML
|
||||
private TableColumn<TestItem, String> answerCol, questionCol;
|
||||
|
||||
|
@ -50,23 +50,30 @@ public class TableController implements Initializable {
|
|||
.then("Add an entry to the table")
|
||||
.otherwise("Save changes in the selected entry"));
|
||||
// Add context menu to Table
|
||||
MenuItem menuEdit = new MenuItem("_Edit");
|
||||
menuEdit.setOnAction(this::onEditAction);
|
||||
MenuItem menuDelete = new MenuItem("_Delete");
|
||||
menuDelete.setOnAction(this::onDeleteAction);
|
||||
MenuItem menuDup = new MenuItem("D_uplicate");
|
||||
menuDup.setOnAction(this::onDuplicateAction);
|
||||
MenuItem menuSwap = new MenuItem("_Swap");
|
||||
menuSwap.setOnAction(this::onSwapAction);
|
||||
MenuItem menuTest = new MenuItem("_Test selected");
|
||||
menuTest.setOnAction(this::onTestSelectionAction);
|
||||
table.setContextMenu(new ContextMenu(menuEdit, menuDelete, menuDup, menuSwap, new SeparatorMenuItem(), menuTest));
|
||||
MenuItem mEdit = new MenuItem("_Edit");
|
||||
mEdit.setOnAction(this::onEditAction);
|
||||
MenuItem mDel = new MenuItem("_Delete");
|
||||
mDel.setOnAction(this::onDeleteAction);
|
||||
MenuItem mDup = new MenuItem("D_uplicate");
|
||||
mDup.setOnAction(this::onDuplicateAction);
|
||||
mDup.disableProperty().bind(mDel.disableProperty());
|
||||
MenuItem mSwap = new MenuItem("_Swap");
|
||||
mSwap.setOnAction(this::onSwapAction);
|
||||
mSwap.disableProperty().bind(mDup.disableProperty());
|
||||
MenuItem mTest = new MenuItem("_Test selected");
|
||||
mTest.setOnAction(this::onTestSelectionAction);
|
||||
mTest.disableProperty().bind(mSwap.disableProperty());
|
||||
mEdit.setDisable(true);
|
||||
mDel.setDisable(true);
|
||||
table.setContextMenu(new ContextMenu(mEdit, mDel, mDup, mSwap, new SeparatorMenuItem(), mTest));
|
||||
|
||||
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
answerCol.setCellValueFactory(e -> e.getValue().answerProperty());
|
||||
questionCol.setCellValueFactory(e -> e.getValue().questionProperty());
|
||||
table.getSelectionModel().getSelectedIndices().addListener(
|
||||
(ListChangeListener<? super Integer>) obs -> menuEdit.setDisable(obs.getList().size() != 1));
|
||||
table.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<? super Integer>) obs -> {
|
||||
mEdit.setDisable(obs.getList().size() != 1);
|
||||
mDel.setDisable(obs.getList().size() == 0);
|
||||
});
|
||||
searchField.textProperty().addListener((obj, o, n) ->
|
||||
filtered.setPredicate((item) -> item.getQuestion().contains(n) || item.getAnswer().contains(n)));
|
||||
newQuestionField.textProperty().addListener((obj, o, n) -> {
|
||||
|
@ -88,6 +95,9 @@ public class TableController implements Initializable {
|
|||
this.parent = controller;
|
||||
table.setRowFactory(new DraggableRowFactory<>(data)::generator);
|
||||
table.setItems(filtered);
|
||||
filtered.addListener((ListChangeListener<TestItem>) c ->
|
||||
testButton.setDisable(filtered.size() == 0));
|
||||
testButton.setDisable(filtered.size() == 0);
|
||||
this.file = file;
|
||||
saved.set(file != null);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
</Button>
|
||||
<Separator orientation="VERTICAL" />
|
||||
<TextField fx:id="searchField" maxWidth="1.7976931348623157E308" promptText="Search..." HBox.hgrow="ALWAYS" />
|
||||
<Button onAction="#onTestAction" text="Start _test">
|
||||
<Button onAction="#onTestAction" fx:id="testButton" text="Start _test">
|
||||
<tooltip>
|
||||
<Tooltip text="Begin a test for the whole table" />
|
||||
</tooltip>
|
||||
|
|
Loading…
Reference in a new issue