Search in sources :

Example 6 with Database

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

the class DbRulesController method removeSentences.

public void removeSentences() throws IOException {
    if (availableRules.getSelectionModel().getSelectedItem() != null && rulesSentences.getSelectionModel().getSelectedItem() != null) {
        int j = 0;
        int i = 0;
        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())) {
                        i = r.getSentences().indexOf(s);
                    }
                }
            }
        }
        rules.get(j).getSentences().remove(i);
        ObservableList<String> items = FXCollections.observableArrayList();
        for (i = 0; i < rules.size(); i++) {
            items.add(rules.get(i).getName());
        }
        availableRules.setItems(items);
        ObservableList<String> itemS = FXCollections.observableArrayList();
        for (i = 0; i < rules.get(j).getSentences().size(); i++) {
            itemS.add(rules.get(j).getSentences().get(i).getName());
        }
        rulesSentences.setItems(itemS);
        sentencesName.setText("");
        sentencesAnswer.setText("");
        new Database().save();
    }
}
Also used : Database(eu.tn.model.Database) Sentences(eu.tn.model.Sentences) Rules(eu.tn.model.Rules)

Example 7 with Database

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

the class DbRulesController method removeRules.

public void removeRules() throws IOException {
    int j = 0;
    if (availableRules.getSelectionModel().getSelectedItem() != null) {
        for (Rules r : rules) {
            if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
                j = rules.indexOf(r);
            }
        }
        rules.remove(j);
        ObservableList<String> items = FXCollections.observableArrayList();
        for (int i = 0; i < rules.size(); i++) {
            items.add(rules.get(i).getName());
        }
        availableRules.setItems(items);
        ObservableList<String> itemS = FXCollections.observableArrayList();
        rulesSentences.setItems(itemS);
        rulesName.setText("");
        rulesHint.setText("");
        sentencesName.setText("");
        sentencesAnswer.setText("");
        new Database().save();
    }
}
Also used : Database(eu.tn.model.Database) Rules(eu.tn.model.Rules)

Example 8 with Database

use of eu.tn.model.Database 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 9 with Database

use of eu.tn.model.Database 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 10 with Database

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

Aggregations

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