parent
e8f0612912
commit
4bec3c1ed8
@ -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; |
||||
} |
||||
|
||||
} |
||||
@ -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("<H1>Notizen</H1>", ContentMode.HTML));
|
||||
addComponent(notesComponent); |
||||
hasChanges = false; |
||||
} |
||||
|
||||
private void textChange(ValueChangeEvent<String> 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<PersonNote> 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; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue