Search in sources :

Example 11 with Rules

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

the class DbRulesController method editSentences.

public void editSentences() {
    if (rulesSentences.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 sentence = new Label("Sentence :");
        TextField sentenceTF = new TextField();
        sentenceTF.setText(rulesSentences.getSelectionModel().getSelectedItem().toString());
        grid.add(sentenceTF, 1, 1);
        grid.add(sentence, 0, 1);
        Label answer = new Label("Answer :");
        TextField answerTF = new TextField();
        String answerS = "";
        for (Rules r : rules) {
            if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                for (Sentences s : r.getSentences()) {
                    if (s.getName().equals(rulesSentences.getSelectionModel().getSelectedItem().toString())) {
                        answerS = s.getAnswer();
                    }
                }
            }
        }
        answerTF.setText(answerS);
        grid.add(answerTF, 1, 2);
        grid.add(answer, 0, 2);
        Button btn = new Button("Edit");
        grid.add(btn, 0, 3);
        Scene secondScene = new Scene(grid, 300, 300);
        Stage newWindow = new Stage();
        newWindow.setTitle("Edit a sentence");
        newWindow.setScene(secondScene);
        newWindow.show();
        btn.setOnAction((event) -> {
            int j = 0;
            if (sentenceTF.getText() != null) {
                for (Rules r : rules) {
                    if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                        j = rules.indexOf(r);
                        for (Sentences s : r.getSentences()) {
                            if (s.getName().equals(rulesSentences.getSelectionModel().getSelectedItem().toString())) {
                                s.setName(sentenceTF.getText());
                                if (answerTF.getText() == null) {
                                    s.setAnswer("");
                                } else {
                                    s.setAnswer(answerTF.getText());
                                }
                            }
                        }
                    }
                }
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < rules.get(j).getSentences().size(); i++) {
                    items.add(rules.get(j).getSentences().get(i).getName());
                }
                rulesSentences.setItems(items);
                newWindow.close();
                try {
                    new Database().save();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                sentencesName.setText(sentenceTF.getText());
                sentencesAnswer.setText(answerTF.getText());
            }
        });
    }
}
Also used : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) IOException(java.io.IOException) Scene(javafx.scene.Scene) Rules(eu.tn.model.Rules) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Sentences(eu.tn.model.Sentences) Stage(javafx.stage.Stage)

Example 12 with Rules

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

the class DbRulesController method newSentences.

public void newSentences() {
    if (availableRules.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 sentence = new Label("Sentence :");
        TextField sentenceTF = new TextField();
        grid.add(sentenceTF, 1, 1);
        grid.add(sentence, 0, 1);
        Label answer = new Label("Answer :");
        TextField answerTF = new TextField();
        grid.add(answerTF, 1, 2);
        grid.add(answer, 0, 2);
        Button btn = new Button("Create");
        grid.add(btn, 0, 3);
        Scene secondScene = new Scene(grid, 300, 300);
        Stage newWindow = new Stage();
        newWindow.setTitle("New sentence");
        newWindow.setScene(secondScene);
        newWindow.show();
        btn.setOnAction((event) -> {
            if (sentenceTF.getText() != null && sentenceTF.getText() != null) {
                Sentences s;
                if (answerTF == null) {
                    s = new Sentences(sentenceTF.getText(), "");
                } else {
                    s = new Sentences(sentenceTF.getText(), answerTF.getText());
                }
                int j = 0;
                for (Rules r : rules) {
                    if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                        r.addSentences(s);
                        j = rules.indexOf(r);
                    }
                }
                ObservableList<String> items = FXCollections.observableArrayList();
                for (int i = 0; i < rules.get(j).getSentences().size(); i++) {
                    items.add(rules.get(j).getSentences().get(i).getName());
                }
                rulesSentences.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) Rules(eu.tn.model.Rules) Button(javafx.scene.control.Button) Database(eu.tn.model.Database) TextField(javafx.scene.control.TextField) Stage(javafx.stage.Stage) Sentences(eu.tn.model.Sentences)

Example 13 with Rules

use of eu.tn.model.Rules 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 14 with Rules

use of eu.tn.model.Rules 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)

Aggregations

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