use of eu.tn.model.Database in project TNCY-English-Project by mrngg.
the class DbTestsController method addRules.
public void addRules() {
if (availableRulesListView.getSelectionModel().getSelectedItem() != null && testsListView.getSelectionModel().getSelectedItem() != null) {
for (Tests t : tests) {
if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
boolean b = false;
for (Rules r : t.getRules()) {
if (r.getName().equals(availableRulesListView.getSelectionModel().getSelectedItem().toString())) {
b = true;
}
}
for (Rules r : rules) {
if (b == false && r.getName().equals(availableRulesListView.getSelectionModel().getSelectedItem().toString())) {
t.addRules(r);
}
}
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < t.getRules().size(); i++) {
items.add(t.getRules().get(i).getName());
}
testRuleListView.setItems(items);
}
}
}
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
}
use of eu.tn.model.Database in project TNCY-English-Project by mrngg.
the class DbTestsController method editTest.
@FXML
public void editTest() throws IOException {
if (testsListView.getSelectionModel().getSelectedItem() != null) {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Label name = new Label("Name :");
TextField nameTF = new TextField();
nameTF.setText(testsListView.getSelectionModel().getSelectedItem().toString());
grid.add(nameTF, 1, 1);
grid.add(name, 0, 1);
Button btn = new Button("Edit");
grid.add(btn, 0, 3);
Scene secondScene = new Scene(grid, 300, 150);
Stage newWindow = new Stage();
newWindow.setTitle("Edit a test");
newWindow.setScene(secondScene);
newWindow.show();
btn.setOnAction((event) -> {
if (nameTF.getText() != null) {
for (Tests t : tests) {
if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
t.setName(nameTF.getText());
}
}
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < tests.size(); i++) {
items.add(tests.get(i).getName());
}
testsListView.setItems(items);
newWindow.close();
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Aggregations