diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDao.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDao.java index 01d5534..c8d9d40 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDao.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDao.java @@ -4,6 +4,7 @@ import java.util.List; import javax.persistence.NoResultException; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Relation; @@ -20,4 +21,8 @@ public interface PersonDao extends IDao { Person findLoginUser(String username, String password) throws NoResultException; List findRelationsFor(Person p); + + void delete(Contact c); + + void delete(Person p); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java index 16ad967..f85fc3d 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java @@ -1,6 +1,7 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.persistence.Query; @@ -45,10 +46,13 @@ public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao @Transactional public void persistOrUpdate(EntityAccessor c) { - if (c.hasValidId() == false) { - entityManager.persist(c); - } else { + Date now = new Date(); + c.setChanged(now); + if (entityManager.contains(c) || c.hasValidId()) { entityManager.merge(c); + } else { + c.setCreated(now); + entityManager.persist(c); } } @@ -78,12 +82,34 @@ public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao } private Relation toRelative(Object[] r, int ignoring) { - + Person p = null; + String relation = null; if (r[1].equals(ignoring)) { - return new Relation(entityManager.find(Person.class, r[2]), r[3].toString()); + p = entityManager.find(Person.class, r[2]); + relation = r[3].toString(); } else if (r[2].equals(ignoring)) { - return new Relation(entityManager.find(Person.class, r[1]), r[4].toString()); + p = entityManager.find(Person.class, r[1]); + relation = r[4].toString(); + } + if (p != null && p.getDeleted() == null) { + return new Relation(p, relation); } return null; } + + @Override + @Transactional + public void delete(Contact c) { + c.setDeleted(new Date()); + entityManager.merge(c); + Person person = c.getPerson(); + person.getContacts().remove(c); + } + + @Override + @Transactional + public void delete(Person p) { + p.setDeleted(new Date()); + entityManager.merge(p); + } } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java index d7abceb..1bef52e 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java @@ -34,22 +34,33 @@ public abstract class BaseEntity implements EntityAccessor { } public Date getChanged() { + if (changed == null) { + return null; + } return new Date(this.changed.getTime()); } + @Override public void setChanged(Date changed) { this.changed = new Date(changed.getTime()); } public Date getCreated() { + if (created == null) { + return null; + } return new Date(this.created.getTime()); } + @Override public void setCreated(Date created) { this.created = new Date(created.getTime()); } public Date getDeleted() { + if (deleted == null) { + return null; + } return new Date(this.deleted.getTime()); } @@ -66,39 +77,33 @@ public abstract class BaseEntity implements EntityAccessor { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((changed == null) ? 0 : changed.hashCode()); result = prime * result + ((created == null) ? 0 : created.hashCode()); - result = prime * result + ((deleted == null) ? 0 : deleted.hashCode()); result = prime * result + id; return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } BaseEntity other = (BaseEntity) obj; - if (changed == null) { - if (other.changed != null) - return false; - } else if (!changed.equals(other.changed)) - return false; if (created == null) { - if (other.created != null) - return false; - } else if (!created.equals(other.created)) - return false; - if (deleted == null) { - if (other.deleted != null) + if (other.created != null) { return false; - } else if (!deleted.equals(other.deleted)) + } + } else if (!created.equals(other.created)) { return false; - if (id != other.id) + } + if (id != other.id) { return false; + } return true; } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Contact.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Contact.java index 100121b..75bbbdf 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Contact.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Contact.java @@ -9,15 +9,14 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedQuery; import javax.persistence.Table; - /** * The persistent class for the contact database table. * */ @Entity -@Table(name="contact") +@Table(name = "contact") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name="Contact.findAll", query="SELECT c FROM Contact c") +@NamedQuery(name = "Contact.findAll", query = "SELECT c FROM Contact c WHERE c.deleted is not null") public class Contact extends BaseEntity implements Serializable { private static final long serialVersionUID = -7631864028095077913L; @@ -26,7 +25,7 @@ public class Contact extends BaseEntity implements Serializable { private String value; - //bi-directional many-to-one association to Person + // bi-directional many-to-one association to Person @ManyToOne private Person person; @@ -57,4 +56,55 @@ public class Contact extends BaseEntity implements Serializable { this.person = person; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((person == null) ? 0 : person.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Contact other = (Contact) obj; + if (person == null) { + if (other.person != null) { + return false; + } + } else if (!person.equals(other.person)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Contact [type=" + type + ", value=" + value + "]"; + } + } \ No newline at end of file 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 86e0764..3ee92fb 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 @@ -26,8 +26,9 @@ import javax.persistence.Table; @Entity @Table(name = "person") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@NamedQuery(name = Person.QUERY_FINDALL, query = "SELECT p FROM Person p") -@NamedQuery(name = Person.QUERY_FINDLOGIN, query = "FROM Person WHERE username = :username AND password = :password") +@NamedQuery(name = Person.QUERY_FINDALL, query = "SELECT p FROM Person p WHERE p.deleted is null") +@NamedQuery(name = Person.QUERY_FINDLOGIN, query = "FROM Person WHERE username = :username AND password = :password AND deleted is" + + " null") public class Person extends BaseEntity implements Serializable { public static final String SESSION_LOGIN = "SESSION_LOGIN_USER"; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java index c11e865..4c25caf 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java @@ -38,8 +38,8 @@ public class LoginUI extends VerticalLayout implements NamedView { } catch (final Exception ex) { ex.printStackTrace(); logger.error("Error on login for User={}", e.getLoginParameter("username"), ex); - String message = "Incorrect user or password:" + ex.getMessage() + e.getLoginParameter("username") + ":" - + e.getLoginParameter("password"); + String message = "Incorrect user or password for " + e.getLoginParameter("username") + "\n" + + ex.getMessage(); Notification.show(message, Notification.Type.ERROR_MESSAGE); } }); diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java index 570ad8f..dd1b2be 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java @@ -8,6 +8,7 @@ import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.annotations.Push; import com.vaadin.annotations.Theme; import com.vaadin.navigator.Navigator; +import com.vaadin.server.ThemeResource; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.communication.PushMode; import com.vaadin.spring.annotation.SpringUI; @@ -56,8 +57,7 @@ public class MainUi extends UI { navigator.addView(MainView.VIEW_NAME, new MainView(personDao, groupDao, eventBusiness, securityGroupVerifier)); navigator.addView(LoginUI.VIEW_NAME, new LoginUI(personDao, securityGroupVerifier)); navigator.addView(PersonEditView.VIEW_NAME, new PersonEditView(groupDao, personDao)); - navigator.addView(EventDetails.VIEW_NAME, - new EventDetails(personDao, groupDao, eventBusiness, pflichtenDao, securityGroupVerifier)); + navigator.addView(EventDetails.VIEW_NAME, new EventDetails(personDao, groupDao, eventBusiness, pflichtenDao)); navigator.navigateTo(MainView.VIEW_NAME); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java index 405a541..e77fd4b 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/PersonEditView.java @@ -34,6 +34,7 @@ public class PersonEditView extends VerticalLayout implements NamedView { personGrid.setSizeFull(); personGrid.onPersonEdit(); personGrid.onPersonSelect(ev -> selectedPerson(ev)); + personGrid.enableDeleteColumn(true); personDetails = new PersonEditDetails(groupDao.listAll(), personDao, false); personDetails.setSizeFull(); diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/AbstractDataGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/AbstractDataGrid.java new file mode 100644 index 0000000..6c0bf6c --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/AbstractDataGrid.java @@ -0,0 +1,75 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Consumer; + +import com.vaadin.data.Binder; +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.components.grid.Editor; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; + +public abstract class AbstractDataGrid extends Grid { + + private static final long serialVersionUID = -3404971410481135696L; + private final List contactSource; + private final ListDataProvider contactDataProvider; + private boolean hasChanges; + private Column deleteButtonColumn; + private Consumer deleteConsumer; + + public AbstractDataGrid() { + + this.contactSource = new ArrayList<>(); + this.contactDataProvider = DataProvider.ofCollection(contactSource); + setDataProvider(contactDataProvider); + + Editor editor = getEditor(); + editor.setEnabled(true); + Binder binder = editor.getBinder(); + editor.addSaveListener(ev -> hasChanges = true); + + createColumnAndBinding(binder); + + deleteButtonColumn = addComponentColumn(c -> { + Button deleteButton = new Button(VaadinIcons.TRASH); + deleteButton.addClickListener(ev -> deleteConsumer.accept(c)); + return deleteButton; + }); + deleteButtonColumn.setHidden(true); + } + + protected abstract void createColumnAndBinding(Binder binder); + + public void setDeleteConsumer(Consumer deleteConsumer) { + this.deleteConsumer = deleteConsumer; + if (deleteConsumer != null) { + deleteButtonColumn.setHidden(false); + } else { + deleteButtonColumn.setHidden(true); + } + } + + public final void setPerson(Person person) { + hasChanges = false; + contactSource.clear(); + if (person != null) { + contactSource.addAll(readValues(person)); + } + contactDataProvider.refreshAll(); + } + + protected abstract Collection readValues(Person person); + + public final boolean hasChanges() { + return hasChanges; + } + +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ConfirmDialog.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ConfirmDialog.java index 9f1b2c8..a7bd991 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ConfirmDialog.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ConfirmDialog.java @@ -74,6 +74,16 @@ public class ConfirmDialog extends Window { return this; } + public Builder yesNo() { + buttons = EnumSet.of(Buttons.YES, Buttons.NO); + return this; + } + + public Builder yesCancel() { + buttons = EnumSet.of(Buttons.YES, Buttons.CANCEL); + return this; + } + public ConfirmDialog build() { return new ConfirmDialog(this); } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ContactGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ContactGrid.java new file mode 100644 index 0000000..1dba196 --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ContactGrid.java @@ -0,0 +1,35 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; + +import java.util.Collection; +import java.util.stream.Collectors; + +import com.vaadin.data.Binder; +import com.vaadin.data.Binder.Binding; +import com.vaadin.ui.TextField; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; + +public class ContactGrid extends AbstractDataGrid { + + /** + * + */ + private static final long serialVersionUID = -2573761302198992085L; + + @Override + public void createColumnAndBinding(Binder binder) { + Binding typeBinding = binder.bind(new ContactTypeComponent(), Contact::getType, + Contact::setType); + Binding valueBinding = binder.bind(new TextField(), Contact::getValue, Contact::setValue); + + addColumn(Contact::getType).setCaption("Kontaktart").setEditorBinding(typeBinding); + addColumn(Contact::getValue).setCaption("Wert").setEditorBinding(valueBinding); + } + + @Override + protected Collection readValues(Person person) { + return person.getContacts().stream().filter(e -> e.getDeleted() == null).collect(Collectors.toList()); + } + +} \ No newline at end of file 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 148c5df..8e4c1eb 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 @@ -1,22 +1,17 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; -import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; import org.vaadin.teemu.switchui.Switch; import com.vaadin.data.Binder; -import com.vaadin.data.Binder.Binding; import com.vaadin.data.BinderValidationStatus; import com.vaadin.data.ValidationResult; -import com.vaadin.data.provider.DataProvider; -import com.vaadin.data.provider.ListDataProvider; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.Component; import com.vaadin.ui.DateField; -import com.vaadin.ui.Grid; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; import com.vaadin.ui.TabSheet; @@ -24,11 +19,9 @@ import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Gender; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Relation; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Startpass; public class PersonEditDetails extends HorizontalLayout { @@ -44,9 +37,8 @@ public class PersonEditDetails extends HorizontalLayout { private Consumer personChangeHandler; private Button okButton; - private VerticalLayout relationshipLayout; - private List contactSource; - private ListDataProvider contactDataProvider; + private ContactGrid contactLayout; + private RelationComponent relationshipLayout; public PersonEditDetails(List groups, PersonDao dao) { this(groups, dao, true); @@ -117,8 +109,24 @@ public class PersonEditDetails extends HorizontalLayout { okButton); Component groupLayout = createGroupPanel(groups); - Component contactLayout = createContactLayout(); - Component relationshipLayout = createRelationshipLayout(); + contactLayout = new ContactGrid(); + contactLayout.setDeleteConsumer(c -> { + + ConfirmDialog dlg = ConfirmDialog + .builder().setCaption("Kontakt löschen").setMessage(c.getPerson().getPrename() + " " + + c.getPerson().getSurname() + " \"" + c + "\" wirklich löschen?") + .yesCancel().setResultHandler(button -> { + if (button == ConfirmDialog.Buttons.YES) { + if (binder.validate().isOk()) { + dao.delete(c); + } + } + }).build(); + + getUI().addWindow(dlg); + }); + + relationshipLayout = new RelationComponent(dao); TabSheet sheet = new TabSheet(); sheet.addTab(groupLayout, "Gruppen"); sheet.addTab(contactLayout, "Kontakte"); @@ -129,32 +137,6 @@ public class PersonEditDetails extends HorizontalLayout { } - private Component createRelationshipLayout() { - relationshipLayout = new VerticalLayout(); - return relationshipLayout; - } - - private Component createContactLayout() { - Grid contactLayout = new Grid<>(); - contactSource = new ArrayList<>(); - - contactDataProvider = DataProvider.ofCollection(contactSource); - contactLayout.setDataProvider(contactDataProvider); - - contactLayout.getEditor().setEnabled(true); - Binder contactBinder = contactLayout.getEditor().getBinder(); - - ContactTypeComponent comp = new ContactTypeComponent(); - Binding typeBinding = contactBinder.bind(comp, Contact::getType, Contact::setType); - Binding valueBinding = contactBinder.bind(new TextField(), Contact::getValue, - Contact::setValue); - - contactLayout.addColumn(Contact::getType).setCaption("Kontaktart").setEditorBinding(typeBinding); - contactLayout.addColumn(Contact::getValue).setCaption("Wert").setEditorBinding(valueBinding); - - return contactLayout; - } - public Component createGroupPanel(List groups) { VerticalLayout layout = new VerticalLayout(); @@ -180,56 +162,39 @@ public class PersonEditDetails extends HorizontalLayout { } public void setBean(Person person) { + closeWithoutSave(); binder.setBean(person); + contactLayout.setPerson(person); + relationshipLayout.setPerson(person); if (person != null) { okButton.setEnabled(true); - updateRelationshipBinding(); - updateContactBinding(); } else { okButton.setEnabled(false); - contactSource.clear(); - contactDataProvider.refreshAll(); - relationshipLayout.removeAllComponents(); - } - } - - private void updateContactBinding() { - contactSource.clear(); - contactSource.addAll(binder.getBean().getContacts()); - contactDataProvider.refreshAll(); - } - - private void updateRelationshipBinding() { - relationshipLayout.removeAllComponents(); - Person current = binder.getBean(); - List related = dao.findRelationsFor(current); - for (Relation relation : related) { - TextField textField = new TextField(relation.getRelation().getLocalized()); - textField.setValue(relation.getPerson().getPrename() + " " + relation.getPerson().getSurname()); - textField.setEnabled(false); - relationshipLayout.addComponent(textField); } } - private void closeWithoutSave() { - if (binder.hasChanges()) { + void closeWithoutSave() { + if (hasChanges()) { + final Person current = binder.getBean(); ConfirmDialog dlg = ConfirmDialog.builder().setCaption("Ungespeicherte Änderungen") - .setMessage("Die Daten wurden geändert. Sollen die Änderungen gespeichert werden?") + .setMessage(current.getPrename() + " " + current.getSurname() + + " wurde geändert. Sollen die Änderungen gespeichert werden?") .saveDiscardCancel().setResultHandler(button -> { if (button == ConfirmDialog.Buttons.SAVE) { if (binder.validate().isOk()) { - dao.save(binder.getBean()); + dao.save(current); } - } else if (button == ConfirmDialog.Buttons.DISCARD) { - binder.removeBean(); } }).build(); getUI().addWindow(dlg); - } else { } } + public boolean hasChanges() { + return binder.hasChanges() || contactLayout.hasChanges() || relationshipLayout.hasChanges(); + } + } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java index da21697..d563af7 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java @@ -15,12 +15,17 @@ import com.vaadin.data.provider.DataProvider; import com.vaadin.data.provider.ListDataProvider; import com.vaadin.event.selection.SelectionListener; import com.vaadin.event.selection.SingleSelectionEvent; +import com.vaadin.icons.VaadinIcons; +import com.vaadin.shared.ui.ContentMode; +import com.vaadin.ui.Button; import com.vaadin.ui.CheckBox; import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; import com.vaadin.ui.Layout; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; @@ -47,13 +52,17 @@ public class PersonGrid extends VerticalLayout { private final ComboBox comboGroups; private final TextField textFilter; + private final PersonDao personDao; + private List allGroups; private PersonFilter filter; private ClubEvent currentEvent; private Column startpassColumn; private Layout filters; private SelectionMode currentSelectionMode; - private Column genderColumn; + private Column genderColumn; + + private Column deleteButtonColumn; public PersonGrid(GroupDao groupDao, PersonDao personDao) { @@ -61,9 +70,12 @@ public class PersonGrid extends VerticalLayout { setCaption("Teilnehmer"); addStyleName("bold-caption"); + this.personDao = personDao; + checkIncluded = new CheckBox("Nur gemeldete"); comboGroups = new ComboBox<>("Gruppenfilter"); textFilter = new TextField("Namenfilter"); + textFilter.setIcon(VaadinIcons.SEARCH); filters = setupFilterComponents(); allGroups = groupDao.listAll(); @@ -74,13 +86,13 @@ public class PersonGrid extends VerticalLayout { dataProvider = DataProvider.ofCollection(filter.asCollection()); grid = new Grid<>(); - setupPersonGrid(personDao); + setupPersonGrid(); setMargin(false); addComponents(filters, grid); } - public void setupPersonGrid(PersonDao personDao) { + void setupPersonGrid() { filter.add(() -> { setEvent(currentEvent); }); @@ -92,7 +104,8 @@ public class PersonGrid extends VerticalLayout { grid.addColumn(Person::getPrename).setCaption("Vorname"); grid.addColumn(Person::getSurname).setCaption("Nachname"); - grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag"); + grid.addColumn(Person::getBirth, b -> b != null ? birthFormat.format(b) : "").setCaption("Geburtstag") + .setHidable(true); startpassColumn = grid.addColumn(p -> { Startpass startpass = p.getStartpass(); @@ -102,18 +115,85 @@ public class PersonGrid extends VerticalLayout { return null; } }).setCaption("Startpass Nr."); + startpassColumn.setHidable(true); - genderColumn = grid.addColumn(p -> { + genderColumn = grid.addComponentColumn(p -> { Gender gender = p.getGender(); + VaadinIcons icon; + if (gender == null) { - return ""; + icon = VaadinIcons.QUESTION; + } else { + switch (gender) { + case FEMALE: + icon = VaadinIcons.FEMALE; + break; + case MALE: + icon = VaadinIcons.MALE; + break; + default: + icon = VaadinIcons.QUESTION; + break; + } } - return gender.localized(); - }).setCaption("Geschlecht"); + + return new Label(icon.getHtml(), ContentMode.HTML); + + }); + genderColumn.setHidable(true); startpassColumn.setHidden(false); genderColumn.setHidden(true); + + deleteButtonColumn = grid.addComponentColumn(c -> { + Button deleteButton = new Button(VaadinIcons.TRASH); + deleteButton.addClickListener(ev -> delete(c)); + deleteButton.setWidthUndefined(); + return deleteButton; + }).setCaption("Löschen"); + deleteButtonColumn.setHidden(true); + + } + + public VaadinIcons genderToImage(Gender gender) { + VaadinIcons icon; + + if (gender == null) { + icon = VaadinIcons.QUESTION; + } else { + switch (gender) { + case FEMALE: + icon = VaadinIcons.FEMALE; + break; + case MALE: + icon = VaadinIcons.MALE; + break; + default: + icon = VaadinIcons.QUESTION; + break; + } + } + + return icon; + } + + public void enableDeleteColumn(boolean enable) { + deleteButtonColumn.setHidden(!enable); + } + + private void delete(Person c) { + + ConfirmDialog dlg = ConfirmDialog.builder().setCaption("Person löschen") + .setMessage(c.getPrename() + " " + c.getSurname() + " wirklich löschen?").yesCancel() + .setResultHandler(button -> { + if (button == ConfirmDialog.Buttons.YES) { + personDao.delete(c); + dataProvider.refreshAll(); + } + }).build(); + + getUI().addWindow(dlg); } public void setSelectionMode(SelectionMode selectionMode) { diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/RelationComponent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/RelationComponent.java new file mode 100644 index 0000000..644552c --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/RelationComponent.java @@ -0,0 +1,33 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; + +import java.util.Collection; + +import com.vaadin.data.Binder; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Relation; + +public class RelationComponent extends AbstractDataGrid { + + private static final long serialVersionUID = 7813969695936351799L; + private PersonDao dao; + + public RelationComponent(PersonDao dao) { + this.dao = dao; + getEditor().setEnabled(false); + } + + @Override + protected void createColumnAndBinding(Binder binder) { + addColumn(r -> r.getRelation().getLocalized()).setCaption("Beiehung"); + addColumn(r -> r.getPerson().getPrename() + " " + r.getPerson().getSurname()); + + } + + @Override + protected Collection readValues(Person person) { + return dao.findRelationsFor(person); + } + +} diff --git a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/favicon.ico b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/favicon.ico new file mode 100644 index 0000000..89bc68b Binary files /dev/null and b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/favicon.ico differ diff --git a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowLeft.png b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowLeft.png index 6fa56c3..3b9659f 100644 Binary files a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowLeft.png and b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowLeft.png differ diff --git a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowRight.png b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowRight.png index 24aa593..7fa9e65 100644 Binary files a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowRight.png and b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/images/arrowRight.png differ