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());
}
});
}
}
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();
}
}
});
}
}
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();
}
}
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();
}
}
Aggregations