From 4bec3c1ed8ba75283fda92ecda6227855e7ba1b1 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Sat, 18 Jan 2020 17:22:11 +0100 Subject: [PATCH] Person notes --- pom.xml | 6 +- .../vaadinclubhelper/data/Person.java | 12 ++ .../vaadinclubhelper/data/PersonNote.java | 122 ++++++++++++++++++ .../ui/components/NotesComponent.java | 64 +++++++++ .../ui/components/PersonEditDetails.java | 7 + 5 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/PersonNote.java create mode 100644 src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/NotesComponent.java diff --git a/pom.xml b/pom.xml index 1a98816..3ecb3d8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,16 +6,12 @@ de.kreth.vaadin.clubhelper vaadin-clubhelper - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT war vaadin-clubhelper Vaadin Administation Frontend for Clubhelper. - - 3 - - org.springframework.boot spring-boot-starter-parent diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Person.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Person.java index cd2df3d..7237d0f 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Person.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Person.java @@ -77,6 +77,11 @@ public class Person extends BaseEntity implements Serializable { CascadeType.REFRESH }) private List contacts; + // bi-directional many-to-one association to Contact + @OneToMany(mappedBy = "person", cascade = { CascadeType.MERGE, CascadeType.PERSIST, + CascadeType.REFRESH }) + private List notes; + // bi-directional many-to-many association to Persongroup @ManyToMany(targetEntity = GroupDef.class, fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.REFRESH }) @@ -377,6 +382,13 @@ public class Person extends BaseEntity implements Serializable { this.startpass.setStartpassNr(startpass); } + public List getNotes() { + if (notes == null) { + notes = new ArrayList<>(); + } + return notes; + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/PersonNote.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/PersonNote.java new file mode 100644 index 0000000..5a7161a --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/PersonNote.java @@ -0,0 +1,122 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + +@Entity +@Table(name = "notes") +@NamedQuery(name = PersonNote.QUERY_FINDALL, query = "SELECT p FROM Person p WHERE p.deleted is null") +public class PersonNote { + + public static final String QUERY_FINDALL = "PersonNote.findAll"; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + + @ManyToOne + private Person person; + + private String notekey; + + private String notetext; + + public PersonNote() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Person getPerson() { + return person; + } + + public void setPerson(Person person) { + this.person = person; + } + + public String getNotekey() { + return notekey; + } + + public void setNotekey(String notekey) { + this.notekey = notekey; + } + + public String getNotetext() { + return notetext; + } + + public void setNotetext(String notetext) { + this.notetext = notetext; + } + + @Override + public String toString() { + return "PersonNote [id=" + id + ", person=" + person + ", notekey=" + notekey + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + result = prime * result + ((notekey == null) ? 0 : notekey.hashCode()); + result = prime * result + ((notetext == null) ? 0 : notetext.hashCode()); + result = prime * result + ((person == null) ? 0 : person.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PersonNote other = (PersonNote) obj; + if (id != other.id) { + return false; + } + if (notekey == null) { + if (other.notekey != null) { + return false; + } + } + else if (!notekey.equals(other.notekey)) { + return false; + } + if (notetext == null) { + if (other.notetext != null) { + return false; + } + } + else if (!notetext.equals(other.notetext)) { + return false; + } + if (person == null) { + if (other.person != null) { + return false; + } + } + else if (!person.equals(other.person)) { + return false; + } + return true; + } + +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/NotesComponent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/NotesComponent.java new file mode 100644 index 0000000..f8c3dae --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/NotesComponent.java @@ -0,0 +1,64 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; + +import java.util.List; + +import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.shared.ui.ValueChangeMode; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.VerticalLayout; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.PersonNote; + +public class NotesComponent extends VerticalLayout { + + private final TextArea notesComponent; + + private PersonNote note; + + private boolean hasChanges; + + public NotesComponent() { + notesComponent = new TextArea(); + notesComponent.setMaxLength(2000); + notesComponent.setCaption("Notizen"); + notesComponent.setRows(25); + notesComponent.addValueChangeListener(this::textChange); + notesComponent.setValueChangeMode(ValueChangeMode.LAZY); + notesComponent.setValueChangeTimeout(1500); +// addComponent(new Label("

Notizen

", ContentMode.HTML)); + addComponent(notesComponent); + hasChanges = false; + } + + private void textChange(ValueChangeEvent ev) { + if (note != null) { + if (ev.isUserOriginated()) { + hasChanges = true; + } + note.setNotetext(ev.getValue()); + } + } + + public void setPerson(Person person) { + notesComponent.clear(); + hasChanges = false; + if (person != null) { + List notes = person.getNotes(); + if (notes.isEmpty() == false) { + note = notes.get(0); + notesComponent.setValue(note.getNotetext()); + } + else { + note = new PersonNote(); + notes.add(note); + note.setPerson(person); + } + } + } + + public boolean hasChanges() { + return hasChanges; + } + +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonEditDetails.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonEditDetails.java index 1f0783f..2ab6407 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonEditDetails.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonEditDetails.java @@ -55,6 +55,8 @@ public class PersonEditDetails extends HorizontalLayout { private AdressComponent adressLayout; + private NotesComponent notes; + public PersonEditDetails(List groups, PersonBusiness dao) { this(groups, dao, true); } @@ -170,11 +172,15 @@ public class PersonEditDetails extends HorizontalLayout { }); adressLayout.addSuccessConsumer(newAdress -> binder.getBean().addAdress(newAdress)); + notes = new NotesComponent(); + TabSheet sheet = new TabSheet(); sheet.addTab(groupLayout, "Gruppen"); sheet.addTab(contactLayout, "Kontakte"); sheet.addTab(relationshipLayout, "Angehörige"); sheet.addTab(adressLayout, "Adresse"); + sheet.addTab(notes, "Notizen"); + addComponents(layout, sheet); setExpandRatio(layout, 1f); setExpandRatio(sheet, 2f); @@ -256,6 +262,7 @@ public class PersonEditDetails extends HorizontalLayout { contactLayout.setPerson(person); relationshipLayout.setPerson(person); adressLayout.setPerson(person); + notes.setPerson(person); binder.setBean(person); }