|
|
|
@ -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)); |
|
|
|
|