From 13334f73d62fc3970a2dc0b70d81edade69a303d Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Tue, 12 Jan 2016 20:35:59 +0100 Subject: Allow a projektthema only once --- .../view/ProjektHinzufuegenController.java | 105 ++++++++++++++------- 1 file changed, 69 insertions(+), 36 deletions(-) (limited to 'src/de/fhswf/in/inf/se/projektthemenvergabe') diff --git a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java index a51a326..77608a1 100644 --- a/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java +++ b/src/de/fhswf/in/inf/se/projektthemenvergabe/view/ProjektHinzufuegenController.java @@ -239,54 +239,87 @@ public class ProjektHinzufuegenController { if (!projektthemaTextField.getText().trim().isEmpty()) { - if (projekt == null) - { - projekt = new Projekt(projektthemaTextField.getText().trim(), - student1ComboBox.getValue(), student2ComboBox.getValue(), - student3ComboBox.getValue(), - ansprechpartnerComboBox.getValue()); - } - else - { - projekt.setProjektthema(projektthemaTextField.getText().trim()); - projekt.setAnsprechpartner(ansprechpartnerComboBox.getValue()); + boolean projektthemaAlreadyExists = false; - if (projekt.getStudent1() != null) - { - projekt.removeStudent(projekt.getStudent1()); - } - if (projekt.getStudent2() != null) - { - projekt.removeStudent(projekt.getStudent2()); - } - if (projekt.getStudent3() != null) + for (Projekt projekt : main.getProjekte()) + { + if (projekt.getProjektthema() + .equals(projektthemaTextField.getText().trim())) { - projekt.removeStudent(projekt.getStudent3()); + projektthemaAlreadyExists = true; + break; } + } - if (student1ComboBox.getValue() != null) + if ((projekt != null && projektthemaTextField.getText().trim() + .equals(projekt.getProjektthema())) + || !projektthemaAlreadyExists) + { + if (projekt == null) { - projekt.addStudent(student1ComboBox.getValue()); + projekt = new Projekt(projektthemaTextField.getText().trim(), + student1ComboBox.getValue(), student2ComboBox.getValue(), + student3ComboBox.getValue(), + ansprechpartnerComboBox.getValue()); } - - if (student2ComboBox.getValue() != null) + else { - projekt.addStudent(student2ComboBox.getValue()); + projekt + .setProjektthema(projektthemaTextField.getText().trim()); + projekt.setAnsprechpartner(ansprechpartnerComboBox.getValue()); + + if (projekt.getStudent1() != null) + { + projekt.removeStudent(projekt.getStudent1()); + } + if (projekt.getStudent2() != null) + { + projekt.removeStudent(projekt.getStudent2()); + } + if (projekt.getStudent3() != null) + { + projekt.removeStudent(projekt.getStudent3()); + } + + if (student1ComboBox.getValue() != null) + { + projekt.addStudent(student1ComboBox.getValue()); + } + + if (student2ComboBox.getValue() != null) + { + projekt.addStudent(student2ComboBox.getValue()); + } + + if (student3ComboBox.getValue() != null) + { + projekt.addStudent(student3ComboBox.getValue()); + } } - if (student3ComboBox.getValue() != null) - { - projekt.addStudent(student3ComboBox.getValue()); - } + projekt.setSkizze(projektskizzeTextField.getText().trim()); + projekt.setProjektbeschreibung( + projekthintergrundTextField.getText().trim()); + projekt.setProjekteinhalte( + projektinhalteTextField.getText().trim()); + + wasAborted = false; + projekthinzufuegenStage.close(); } + else + { + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("Projektthema ist bereits vorhanden"); + alert.setHeaderText("Projekt wurde bereits angelegt."); + alert.setContentText( + "Bitte geben Sie ein neues Projektthema ein."); - projekt.setSkizze(projektskizzeTextField.getText().trim()); - projekt.setProjektbeschreibung( - projekthintergrundTextField.getText().trim()); - projekt.setProjekteinhalte(projektinhalteTextField.getText().trim()); + alert.initOwner(main.getProjekthinzufuegenStage()); - wasAborted = false; - projekthinzufuegenStage.close(); + alert.showAndWait(); + + projektthemaTextField.requestFocus(); + } } else { -- cgit v1.2.3-70-g09d2