Search in sources :

Example 1 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class DbTestsController method removeTest.

@FXML
public void removeTest() throws IOException {
    int j = 0;
    if (testsListView.getSelectionModel().getSelectedItem() != null) {
        for (Tests t : tests) {
            if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
                j = tests.indexOf(t);
            }
        }
        tests.remove(j);
        ObservableList<String> items = FXCollections.observableArrayList();
        for (int i = 0; i < tests.size(); i++) {
            items.add(tests.get(i).getName());
        }
        testsListView.setItems(items);
        ObservableList<String> itemS = FXCollections.observableArrayList();
        testRuleListView.setItems(itemS);
        new Database().save();
    }
}
Also used : Database(eu.tn.model.Database) Tests(eu.tn.model.Tests) FXML(javafx.fxml.FXML)

Example 2 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class DbTestsController method newTest.

@FXML
public void newTest() {
    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();
    grid.add(nameTF, 1, 1);
    grid.add(name, 0, 1);
    Button btn = new Button("Create");
    grid.add(btn, 0, 3);
    Scene secondScene = new Scene(grid, 300, 150);
    Stage newWindow = new Stage();
    newWindow.setTitle("Create a test");
    newWindow.setScene(secondScene);
    newWindow.show();
    btn.setOnAction((event) -> {
        if (nameTF.getText() != null) {
            new Tests(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();
            }
        }
    });
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) IOException(java.io.IOException) Scene(javafx.scene.Scene) Tests(eu.tn.model.Tests) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) FXML(javafx.fxml.FXML)

Example 3 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class DbTestsController method removeRules.

public void removeRules() throws IOException {
    if (testRuleListView.getSelectionModel().getSelectedItem() != null && testsListView.getSelectionModel().getSelectedItem() != null) {
        for (Tests t : tests) {
            if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
                int j = 0;
                for (Rules r : t.getRules()) {
                    if (r.getName().equals(testRuleListView.getSelectionModel().getSelectedItem().toString())) {
                        j = t.getRules().indexOf(r);
                    }
                }
                t.getRules().remove(j);
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < t.getRules().size(); i++) {
                    items.add(t.getRules().get(i).getName());
                }
                testRuleListView.setItems(items);
            }
        }
        new Database().save();
    }
}
Also used : Database(eu.tn.model.Database) Rules(eu.tn.model.Rules) Tests(eu.tn.model.Tests)

Example 4 with Tests

use of eu.tn.model.Tests 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();
    }
}
Also used : Database(eu.tn.model.Database) IOException(java.io.IOException) Rules(eu.tn.model.Rules) Tests(eu.tn.model.Tests)

Example 5 with Tests

use of eu.tn.model.Tests in project TNCY-English-Project by mrngg.

the class DbTestsController method showRules.

public void showRules() {
    if (testsListView.getSelectionModel().getSelectedItem() != null) {
        for (Tests t : tests) {
            if (t.getName().equals(testsListView.getSelectionModel().getSelectedItem().toString())) {
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < t.getRules().size(); i++) {
                    items.add(t.getRules().get(i).getName());
                }
                testRuleListView.setItems(items);
            }
        }
    }
}
Also used : Tests(eu.tn.model.Tests)

Aggregations

Tests (eu.tn.model.Tests)7 Database (eu.tn.model.Database)5 IOException (java.io.IOException)4 FXML (javafx.fxml.FXML)4 Scene (javafx.scene.Scene)3 Stage (javafx.stage.Stage)3 Rules (eu.tn.model.Rules)2 Insets (javafx.geometry.Insets)2 Button (javafx.scene.control.Button)2 Label (javafx.scene.control.Label)2 TextField (javafx.scene.control.TextField)2 GridPane (javafx.scene.layout.GridPane)2 Tests.tests (eu.tn.model.Tests.tests)1 Platform (javafx.application.Platform)1 FXMLLoader (javafx.fxml.FXMLLoader)1 ChoiceBox (javafx.scene.control.ChoiceBox)1 BorderPane (javafx.scene.layout.BorderPane)1