package de.fhswf.in.inf.se.projektthemenvergabe.model; import javafx.beans.Observable; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.util.Callback; /** * * Class Projekt to represents data. * * @author Dina-Marie Hanxleden & Stefan Suhren * @version 1.0 */ public class Projekt { private StringProperty projektthema = new SimpleStringProperty(""); private StringProperty skizze = new SimpleStringProperty(""); private StringProperty projektbeschreibung = new SimpleStringProperty(""); private StringProperty projekteinhalte = new SimpleStringProperty(""); private ObjectProperty student1 = new SimpleObjectProperty<>(); private ObjectProperty student2 = new SimpleObjectProperty<>(); private ObjectProperty student3 = new SimpleObjectProperty<>(); private ObjectProperty ansprechpartner = new SimpleObjectProperty<>(); private ObjectProperty status = new SimpleObjectProperty<>( StatusTypes.IN_BEARBEITUNG); private StringProperty dozentenkommentar = new SimpleStringProperty(""); private String oldProjektthema; /** * Generates an extractor that fires when a property of a list value * changes. * * @return The extractor. */ public static Callback extractor() { return projekt -> new Observable[] { projekt.projektthemaProperty(), projekt.skizzeProperty(), projekt.projektbeschreibungProperty(), projekt.projekteinhalteProperty(), projekt.student1Property(), projekt.student2Property(), projekt.student3Property(), projekt.ansprechpartnerProperty(), projekt.statusProperty() }; } /** * * Create the different StatusTypes as enums. * */ public static enum StatusTypes { IN_BEARBEITUNG("In Bearbeitung"), EINGEREICHT( "Eingereicht"), IN_UEBERARBEITUNG("In Überarbeitung"), ANGENOMMEN( "Angenommen"), ABGELEHNT("Abgelehnt"); private String text; StatusTypes(String text) { this.text = text; } public String toString() { return text; } } /** * * Constructor of Project. * * @param projektthema * The name of the {@link Projekt}. * @param student1 * The first Student * @param student2 * The second Student * @param student3 * The third Student * @param ansprechpartner * The Ansprechpartner */ public Projekt(String projektthema, Student student1, Student student2, Student student3, Ansprechpartner ansprechpartner) { if (projektthema == null) { throw new IllegalArgumentException("Projektthema can't be null."); } if (projektthema.isEmpty()) { throw new IllegalArgumentException("Projektthema can't be empty."); } if (student1 == null && student2 == null && student3 == null) { throw new IllegalArgumentException( "Zumindest ein Student sollte das Projekt bearbeiten."); } if (ansprechpartner == null) { throw new IllegalArgumentException( "Das Projekt sollte irgendwo gemacht werden."); } if (student1 != null && student1.getProjekt() == null) { addStudent(student1); student1.setProjekt(this); } if (student2 != null && student2.getProjekt() == null) { addStudent(student2); student2.setProjekt(this); } if (student3 != null && student3.getProjekt() == null) { addStudent(student3); student3.setProjekt(this); } // Because insertions always happen at first free index, here we can // cheat a bit if (this.student1.get() == null) { throw new IllegalArgumentException( "Alle Studenten haben bereits Projekte."); } this.ansprechpartner.set(ansprechpartner); this.ansprechpartner.get().addProjekt(this); this.projektthema.set(projektthema); oldProjektthema = projektthema; } /** * * Getter for the property projektthema. * * @return Returns the property projecthema */ public final StringProperty projektthemaProperty() { return this.projektthema; } /** * * Getter for Projektthema. * * @return Returns Projektthema */ public final String getProjektthema() { return this.projektthemaProperty().get(); } /** * * Setter for the projektthema * * @param projektthema */ public final void setProjektthema(final String projektthema) { this.projektthemaProperty().set(projektthema); } /** * * Getter for the property skizze. * * @return Returns the property skizze */ public final StringProperty skizzeProperty() { return this.skizze; } /** * * Getter for skizze. * * @return Returns the skizze */ public final String getSkizze() { return this.skizzeProperty().get(); } /** * * Setter for the skizze. * * @param skizze */ public final void setSkizze(final String skizze) { this.skizzeProperty().set(skizze); } /** * * Getter for the property projektbeschreibung. * * @return Returns the property projektbeschreibung */ public final StringProperty projektbeschreibungProperty() { return this.projektbeschreibung; } /** * * Getter for projektbeschreibung. * * @return Returns the projektbeschriebung */ public final String getProjektbeschreibung() { return this.projektbeschreibungProperty().get(); } /** * * Setter for projektbeschreibung. * * @param projektbeschreibung */ public final void setProjektbeschreibung(final String projektbeschreibung) { this.projektbeschreibungProperty().set(projektbeschreibung); } /** * * Getter for the property projektinhalte. * * @return Returns the property projektinhalte */ public final StringProperty projekteinhalteProperty() { return this.projekteinhalte; } /** * * Getter for projektinhalte. * * @return Returns the projektinhalte */ public final String getProjekteinhalte() { return this.projekteinhalteProperty().get(); } /** * * Setter for projektinhalte. * * @param projekteinhalte */ public final void setProjekteinhalte(final String projekteinhalte) { this.projekteinhalteProperty().set(projekteinhalte); } public final ObjectProperty student1Property() { return this.student1; } public final Student getStudent1() { return this.student1Property().get(); } public final ObjectProperty student2Property() { return this.student2; } public final Student getStudent2() { return this.student2Property().get(); } public final ObjectProperty student3Property() { return this.student3; } public final Student getStudent3() { return this.student3Property().get(); } /** * Füge einen Studenten hinzu. * * @param student */ public void addStudent(Student student) { if (student == null) { throw new IllegalArgumentException( "Es muss ein Student zum Hinzufügen gegeben sein."); } if (!student.equals(student1.get()) && !student.equals(student2.get()) && !student.equals(student3.get())) { if (student1.get() == null) { student1.set(student); } else if (student2.get() == null) { student2.set(student); } else if (student3.get() == null) { student3.set(student); } else { throw new IllegalArgumentException( "3 Studenten arbeiten bereits an dem Projekt."); } student.setProjekt(this); } } /** * Remove the Student. * * @param student */ public void removeStudent(Student student) { if (student == null) { throw new IllegalArgumentException( "Es muss ein Student zum Entfernen gegeben sein."); } if (student.equals(student1.get())) { student1.set(null); } else if (student.equals(student2.get())) { student2.set(null); } else if (student.equals(student3.get())) { student3.set(null); } } /** * Getter for property ansprechpartner. * * @return Returns the ansprechpartner. */ public ObjectProperty ansprechpartnerProperty() { return ansprechpartner; } /** * * Getter for Ansprechpartner of the Projekt. * * @return Returns the Ansprechpartner of the Projekt */ public Ansprechpartner getAnsprechpartner() { return this.ansprechpartner.get(); } /** * Setter for ansprechpartner. * * @param ansprechpartner * The ansprechpartner to set. */ public void setAnsprechpartner(Ansprechpartner ansprechpartner) { if (this.ansprechpartner.get() != null) { this.ansprechpartner.get().removeProjekt(this); } this.ansprechpartner.set(ansprechpartner); if (ansprechpartner != null) { ansprechpartner.addProjekt(this); } } /** * * Getter for the property Status. * * @return Returns the property status */ public final ObjectProperty statusProperty() { return this.status; } /** * * Getter for status. * * @return Returns the status */ public final StatusTypes getStatus() { return this.statusProperty().get(); } /** * * Setter of status. * * @param status */ public final void setStatus(final StatusTypes status) { this.statusProperty().set(status); } /** * * Getter of the property dozentenkommentar. * * @return Returns the property dozentenkommentar */ public final StringProperty dozentenkommentarProperty() { return this.dozentenkommentar; } /** * * Getter of dozentenkommentar. * * @return Returns the dozentenkommentar */ public final String getDozentenkommentar() { return this.dozentenkommentarProperty().get(); } /** * * Setter for dozentenkommentar. * * @param dozentenkommentar */ public final void setDozentenkommentar(final String dozentenkommentar) { this.dozentenkommentarProperty().set(dozentenkommentar); } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return projektthema.get(); } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof Projekt)) { return false; } return ((Projekt) obj).projektthema.get().equals(projektthema.get()); } /** * Get the previous projektthema of this Projekt. * */ public String getOldProjektthema() { String tmp = oldProjektthema; oldProjektthema = projektthema.get(); return tmp; } }