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());
|
primaryStage.setOnHiding(event -> AppPrefs.save());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stop() throws Exception {
|
|
||||||
super.stop();
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class TableController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField newQuestionField, newAnswerField, searchField;
|
private TextField newQuestionField, newAnswerField, searchField;
|
||||||
@FXML
|
@FXML
|
||||||
private Button addButton;
|
private Button addButton, testButton;
|
||||||
@FXML
|
@FXML
|
||||||
private TableColumn<TestItem, String> answerCol, questionCol;
|
private TableColumn<TestItem, String> answerCol, questionCol;
|
||||||
|
|
||||||
|
@ -50,23 +50,30 @@ public class TableController implements Initializable {
|
||||||
.then("Add an entry to the table")
|
.then("Add an entry to the table")
|
||||||
.otherwise("Save changes in the selected entry"));
|
.otherwise("Save changes in the selected entry"));
|
||||||
// Add context menu to Table
|
// Add context menu to Table
|
||||||
MenuItem menuEdit = new MenuItem("_Edit");
|
MenuItem mEdit = new MenuItem("_Edit");
|
||||||
menuEdit.setOnAction(this::onEditAction);
|
mEdit.setOnAction(this::onEditAction);
|
||||||
MenuItem menuDelete = new MenuItem("_Delete");
|
MenuItem mDel = new MenuItem("_Delete");
|
||||||
menuDelete.setOnAction(this::onDeleteAction);
|
mDel.setOnAction(this::onDeleteAction);
|
||||||
MenuItem menuDup = new MenuItem("D_uplicate");
|
MenuItem mDup = new MenuItem("D_uplicate");
|
||||||
menuDup.setOnAction(this::onDuplicateAction);
|
mDup.setOnAction(this::onDuplicateAction);
|
||||||
MenuItem menuSwap = new MenuItem("_Swap");
|
mDup.disableProperty().bind(mDel.disableProperty());
|
||||||
menuSwap.setOnAction(this::onSwapAction);
|
MenuItem mSwap = new MenuItem("_Swap");
|
||||||
MenuItem menuTest = new MenuItem("_Test selected");
|
mSwap.setOnAction(this::onSwapAction);
|
||||||
menuTest.setOnAction(this::onTestSelectionAction);
|
mSwap.disableProperty().bind(mDup.disableProperty());
|
||||||
table.setContextMenu(new ContextMenu(menuEdit, menuDelete, menuDup, menuSwap, new SeparatorMenuItem(), menuTest));
|
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);
|
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
answerCol.setCellValueFactory(e -> e.getValue().answerProperty());
|
answerCol.setCellValueFactory(e -> e.getValue().answerProperty());
|
||||||
questionCol.setCellValueFactory(e -> e.getValue().questionProperty());
|
questionCol.setCellValueFactory(e -> e.getValue().questionProperty());
|
||||||
table.getSelectionModel().getSelectedIndices().addListener(
|
table.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<? super Integer>) obs -> {
|
||||||
(ListChangeListener<? super Integer>) obs -> menuEdit.setDisable(obs.getList().size() != 1));
|
mEdit.setDisable(obs.getList().size() != 1);
|
||||||
|
mDel.setDisable(obs.getList().size() == 0);
|
||||||
|
});
|
||||||
searchField.textProperty().addListener((obj, o, n) ->
|
searchField.textProperty().addListener((obj, o, n) ->
|
||||||
filtered.setPredicate((item) -> item.getQuestion().contains(n) || item.getAnswer().contains(n)));
|
filtered.setPredicate((item) -> item.getQuestion().contains(n) || item.getAnswer().contains(n)));
|
||||||
newQuestionField.textProperty().addListener((obj, o, n) -> {
|
newQuestionField.textProperty().addListener((obj, o, n) -> {
|
||||||
|
@ -88,6 +95,9 @@ public class TableController implements Initializable {
|
||||||
this.parent = controller;
|
this.parent = controller;
|
||||||
table.setRowFactory(new DraggableRowFactory<>(data)::generator);
|
table.setRowFactory(new DraggableRowFactory<>(data)::generator);
|
||||||
table.setItems(filtered);
|
table.setItems(filtered);
|
||||||
|
filtered.addListener((ListChangeListener<TestItem>) c ->
|
||||||
|
testButton.setDisable(filtered.size() == 0));
|
||||||
|
testButton.setDisable(filtered.size() == 0);
|
||||||
this.file = file;
|
this.file = file;
|
||||||
saved.set(file != null);
|
saved.set(file != null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</Button>
|
</Button>
|
||||||
<Separator orientation="VERTICAL" />
|
<Separator orientation="VERTICAL" />
|
||||||
<TextField fx:id="searchField" maxWidth="1.7976931348623157E308" promptText="Search..." HBox.hgrow="ALWAYS" />
|
<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>
|
||||||
<Tooltip text="Begin a test for the whole table" />
|
<Tooltip text="Begin a test for the whole table" />
|
||||||
</tooltip>
|
</tooltip>
|
||||||
|
|
Loading…
Reference in a new issue