mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Table: better focus and duplicate/delete/swap
This commit is contained in:
parent
b557ec9374
commit
51779fb868
2 changed files with 19 additions and 8 deletions
|
@ -11,6 +11,7 @@ import javafx.fxml.Initializable;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.SelectionMode;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
|
@ -34,13 +35,18 @@ public class TableController implements Initializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
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());
|
||||||
// editButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
bindButtons();
|
||||||
// swapButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
}
|
||||||
// deleteButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
|
||||||
// duplicateButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
private void bindButtons() {
|
||||||
// testSelectionButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
editButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
||||||
|
swapButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
||||||
|
deleteButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
||||||
|
duplicateButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
||||||
|
testSelectionButton.disableProperty().bind(table.getSelectionModel().selectedIndexProperty().lessThan(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setData(List<TestItem> list, Controller controller) {
|
void setData(List<TestItem> list, Controller controller) {
|
||||||
|
@ -97,16 +103,21 @@ public class TableController implements Initializable {
|
||||||
item.questionProperty().set(item.getAnswer());
|
item.questionProperty().set(item.getAnswer());
|
||||||
item.answerProperty().set(question);
|
item.answerProperty().set(question);
|
||||||
}
|
}
|
||||||
|
table.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onDuplicateAction(ActionEvent event) {
|
private void onDuplicateAction(ActionEvent event) {
|
||||||
table.getItems().addAll(table.getSelectionModel().getSelectedItems());
|
for (int i : table.getSelectionModel().getSelectedIndices())
|
||||||
|
table.getItems().add(new TestItem(table.getItems().get(i)));
|
||||||
|
table.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onDeleteAction(ActionEvent event) {
|
private void onDeleteAction(ActionEvent event) {
|
||||||
table.getItems().removeAll(table.getSelectionModel().getSelectedItems());
|
for (int i : table.getSelectionModel().getSelectedIndices())
|
||||||
|
table.getItems().remove(i);
|
||||||
|
table.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class TestItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestItem(String question, String answer) {
|
public TestItem(String question, String answer) {
|
||||||
this(new SimpleStringProperty(question), new SimpleStringProperty(answer));
|
this(new SimpleStringProperty(new String(question)), new SimpleStringProperty(new String(answer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQuestion() {
|
public String getQuestion() {
|
||||||
|
|
Loading…
Reference in a new issue