GroupDef bugfix, Refactoring

master
Markus Kreth 7 years ago
parent 184bbf1e20
commit c60b46c02a
  1. 21
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/GroupDef.java
  2. 64
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
  3. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/SingleEventView.java

@ -67,29 +67,28 @@ public class GroupDef extends BaseEntity implements Serializable {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((persongroups == null) ? 0 : persongroups.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (!super.equals(obj)) }
if (!super.equals(obj)) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
GroupDef other = (GroupDef) obj; GroupDef other = (GroupDef) obj;
if (name == null) { if (name == null) {
if (other.name != null) if (other.name != null) {
return false;
} else if (!name.equals(other.name))
return false; return false;
if (persongroups == null) { }
if (other.persongroups != null) } else if (!name.equals(other.name)) {
return false;
} else if (!persongroups.equals(other.persongroups))
return false; return false;
}
return true; return true;
} }

@ -19,10 +19,10 @@ import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox; import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox; import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Layout;
import com.vaadin.ui.MultiSelect; import com.vaadin.ui.MultiSelect;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme; import com.vaadin.ui.themes.ValoTheme;
@ -33,7 +33,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
public class PersonGrid extends CustomComponent { public class PersonGrid extends VerticalLayout {
private static final long serialVersionUID = -8148097982839343673L; private static final long serialVersionUID = -8148097982839343673L;
private final transient Logger log = LoggerFactory.getLogger(getClass()); private final transient Logger log = LoggerFactory.getLogger(getClass());
@ -58,52 +58,64 @@ public class PersonGrid extends CustomComponent {
setCaption("Teilnehmer"); setCaption("Teilnehmer");
addStyleName("bold-caption"); addStyleName("bold-caption");
checkIncluded = new CheckBox("Nur gemeldete"); checkIncluded = new CheckBox("Nur gemeldete");
checkIncluded.setId("person.filter.checked");
checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev));
comboGroups = new ComboBox<>("Gruppenfilter"); comboGroups = new ComboBox<>("Gruppenfilter");
comboGroups.setId("person.filter.groups"); Layout filters = setupFilterComponents();
comboGroups.setEmptySelectionAllowed(true);
comboGroups.setEmptySelectionCaption("Alle");
comboGroups.setItemCaptionGenerator(GroupDef::getName);
comboGroups.addSelectionListener(ev -> onGroupSelected(ev));
allGroups = groupDao.listAll(); allGroups = groupDao.listAll();
comboGroups.setItems(allGroups); comboGroups.setItems(allGroups);
log.info("Loaded Groups: {}", allGroups); log.info("Loaded Groups: {}", allGroups);
HorizontalLayout filters = new HorizontalLayout();
filters.addComponents(checkIncluded, comboGroups);
filter = new PersonFilter(personDao); filter = new PersonFilter(personDao);
dataProvider = DataProvider.ofCollection(filter.asCollection());
grid = new Grid<>();
setupPersonGrid(personDao);
Button close = new Button("Schließen", ev -> {
PersonGrid.this.setVisible(false);
if (closedFunction != null) {
closedFunction.closed();
}
});
close.setId("person.close");
setMargin(false);
addComponents(filters, grid, close);
}
public void setupPersonGrid(PersonDao personDao) {
filter.add(() -> { filter.add(() -> {
setEvent(currentEvent); setEvent(currentEvent);
}); });
dataProvider = DataProvider.ofCollection(filter.asCollection());
dataProvider.addDataProviderListener(filter); dataProvider.addDataProviderListener(filter);
grid = new Grid<>();
grid.setDataProvider(dataProvider); grid.setDataProvider(dataProvider);
grid.setId("person.grid"); grid.setId("person.grid");
grid.addColumn(Person::getPrename).setCaption("Vorname"); grid.addColumn(Person::getPrename).setCaption("Vorname");
grid.addColumn(Person::getSurname).setCaption("Nachname"); 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");
grid.addComponentColumn(this::buildDeleteButton); grid.addComponentColumn(this::buildPersonEditButton);
grid.setSelectionMode(SelectionMode.MULTI); grid.setSelectionMode(SelectionMode.MULTI);
Button close = new Button("Schließen", ev -> {
PersonGrid.this.setVisible(false);
if (closedFunction != null) {
closedFunction.closed();
} }
});
close.setId("person.close");
VerticalLayout panel = new VerticalLayout(); private Layout setupFilterComponents() {
panel.addComponents(filters, grid, close); checkIncluded.setId("person.filter.checked");
setCompositionRoot(panel); checkIncluded.addValueChangeListener(ev -> onSelectedOnly(ev));
comboGroups.setId("person.filter.groups");
comboGroups.setEmptySelectionAllowed(true);
comboGroups.setEmptySelectionCaption("Alle");
comboGroups.setItemCaptionGenerator(GroupDef::getName);
comboGroups.addSelectionListener(ev -> onGroupSelected(ev));
HorizontalLayout filters = new HorizontalLayout();
filters.setMargin(false);
filters.addComponents(checkIncluded, comboGroups);
return filters;
} }
private Button buildDeleteButton(Person p) { private Button buildPersonEditButton(Person p) {
Button button = new Button(VaadinIcons.EDIT); Button button = new Button(VaadinIcons.EDIT);
button.addStyleName(ValoTheme.BUTTON_SMALL); button.addStyleName(ValoTheme.BUTTON_SMALL);
button.addClickListener(e -> showPersonDetails(p)); button.addClickListener(e -> showPersonDetails(p));

@ -32,6 +32,7 @@ public class SingleEventView extends CustomComponent {
textLocation.setSizeFull(); textLocation.setSizeFull();
VerticalLayout panel = new VerticalLayout(); VerticalLayout panel = new VerticalLayout();
panel.setMargin(false);
panel.addComponents(textTitle, textLocation); panel.addComponents(textTitle, textLocation);
setCompositionRoot(panel); setCompositionRoot(panel);
} }

Loading…
Cancel
Save