Add person converted to menu item

master
Markus Kreth 6 years ago
parent ace56732ea
commit 8ffc598d12
  1. 47
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/AddPersonCommand.java
  2. 50
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/LoggedinEditPersonViewMenuitemState.java
  3. 11
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/LoggedinMenuitemState.java
  4. 12
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/MenuItemStateFactory.java
  5. 27
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java
  6. 33
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java

@ -0,0 +1,47 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.function.Consumer;
import com.vaadin.server.Resource;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
public class AddPersonCommand implements ClubCommand {
private final Consumer<Person> createdPersonConsumer;
private final GroupDef defaultGroup;
public AddPersonCommand(Consumer<Person> createdPersonConsumer, GroupDef defaultGroup) {
super();
this.createdPersonConsumer = createdPersonConsumer;
this.defaultGroup = defaultGroup;
}
@Override
public String getLabel() {
return "Person Hinzufügen";
}
@Override
public Resource getIcon() {
return null;
}
@Override
public void execute() {
Person person = new Person();
person.setGroups(new HashSet<>());
person.setAdresses(new ArrayList<>());
person.setEvents(new HashSet<>());
person.setRelatives1(new ArrayList<>());
person.add(defaultGroup);
createdPersonConsumer.accept(person);
}
}

@ -0,0 +1,50 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu;
import java.time.ZonedDateTime;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.springframework.context.ApplicationContext;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.UI;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.AddPersonCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.PersonEditView;
import net.sf.jasperreports.engine.JasperPrint;
/**
* Status für authentifizierte User im {@link PersonEditView}
* @author markus
*
*/
class LoggedinEditPersonViewMenuitemState extends LoggedinMenuitemState {
private final Consumer<Person> newPersonConsumer;
private GroupDao groupDao;
public LoggedinEditPersonViewMenuitemState(ApplicationContext context, UI ui, Supplier<ZonedDateTime> startProvider,
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer,
Consumer<Person> newPersonConsumer) {
super(context, ui, startProvider, endProvider, printConsumer);
this.newPersonConsumer = newPersonConsumer;
groupDao = context.getBean(GroupDao.class);
}
@Override
public void applyMenuStates(ClubhelperMenuBar menuBar) {
super.applyMenuStates(menuBar);
MenuItem editMenu = menuBar.getEditMenuItem();
GroupDef defaultGroup = groupDao.get(1);
editMenu.addSeparator();
AddPersonCommand addPersonCommand = new AddPersonCommand(newPersonConsumer, defaultGroup);
editMenu.addItem(addPersonCommand.getLabel(), new CommandWrapper(addPersonCommand));
}
}

@ -30,14 +30,16 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.LogoutCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.SwitchViewCommand; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.SwitchViewCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ConfirmDialog; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ConfirmDialog;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews;
import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrint;
/**
* Status für authentifizierte User mit Menuitems für jedes View
* @author markus
*
*/
class LoggedinMenuitemState extends LoggedOffState { class LoggedinMenuitemState extends LoggedOffState {
private ClubNavigator navigator2;
private SecurityVerifier securityVerifier; private SecurityVerifier securityVerifier;
private ClubhelperNavigation navigator; private ClubhelperNavigation navigator;
@ -90,7 +92,7 @@ class LoggedinMenuitemState extends LoggedOffState {
@Override @Override
protected ClubCommand loginOutCommand() { protected ClubCommand loginOutCommand() {
return new LogoutCommand(navigator2, securityVerifier); return new LogoutCommand(navigator.getNavigator(), securityVerifier);
} }
private void prepareViewMenu(ClubhelperMenuBar menuBar) { private void prepareViewMenu(ClubhelperMenuBar menuBar) {
@ -123,6 +125,7 @@ class LoggedinMenuitemState extends LoggedOffState {
CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent)); CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent));
deleteMenuItem = editMenu.addItem(deleeteEvent.getLabel(), deleeteEvent); deleteMenuItem = editMenu.addItem(deleeteEvent.getLabel(), deleeteEvent);
} }
protected void setSelectedMenuItem(ClubhelperViews view) { protected void setSelectedMenuItem(ClubhelperViews view) {

@ -4,6 +4,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -21,6 +22,7 @@ import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.UI; import com.vaadin.ui.UI;
import com.vaadin.ui.Window; import com.vaadin.ui.Window;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews;
@ -47,12 +49,16 @@ public class MenuItemStateFactory implements ApplicationContextAware {
private Supplier<ZonedDateTime> endDateSupplier; private Supplier<ZonedDateTime> endDateSupplier;
private Consumer<Person> newPersonConsumer;
public MenuItemState currentState() { public MenuItemState currentState() {
MenuItemState state; MenuItemState state;
View currentView = clubhelperNavigation.getNavigator().getCurrentView(); View currentView = clubhelperNavigation.getNavigator().getCurrentView();
ClubhelperViews current = ClubhelperViews.byView(currentView); ClubhelperViews current = ClubhelperViews.byView(currentView);
if (ClubhelperViews.PersonEditView == current) { if (ClubhelperViews.PersonEditView == current) {
state = new LoggedinMenuitemState(context, ui, startDateSupplier, endDateSupplier, this::showPrint); state = new LoggedinEditPersonViewMenuitemState(context, ui, startDateSupplier, endDateSupplier,
this::showPrint,
newPersonConsumer);
} }
else if (securityGroupVerifier.isLoggedin()) { else if (securityGroupVerifier.isLoggedin()) {
state = new LoggedinMenuitemState(context, ui, startDateSupplier, endDateSupplier, this::showPrint); state = new LoggedinMenuitemState(context, ui, startDateSupplier, endDateSupplier, this::showPrint);
@ -113,4 +119,8 @@ public class MenuItemStateFactory implements ApplicationContextAware {
this.ui = ui; this.ui = ui;
} }
public void setNewPersonConsumer(Consumer<Person> newPersonConsumer) {
this.newPersonConsumer = newPersonConsumer;
}
} }

@ -71,12 +71,19 @@ public class ClubhelperNavigation implements ApplicationContextAware {
ViewFactory factory = new ViewFactory(page); ViewFactory factory = new ViewFactory(page);
mainView = factory.createMain(); mainView = factory.createMain();
personEdit = factory.createPersonEdit();
MenuItemStateFactory menuItemFactory = context.getBean(MenuItemStateFactory.class);
setupMenuItemStateFactory(menuItemFactory);
navi = new ClubNavigator().init(mainUI); navi = new ClubNavigator().init(mainUI);
ClubhelperMenuBar menuBar = new ClubhelperMenuBar(menuItemFactory.currentState());
personEdit.setMenuBar(menuBar);
personEdit.setMenuStateFactory(menuItemFactory);
navi.addView("", mainView); navi.addView("", mainView);
navi.addView(ClubhelperViews.MainView.name(), mainView); navi.addView(ClubhelperViews.MainView.name(), mainView);
navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personBusiness, securityGroupVerifier)); navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personBusiness, securityGroupVerifier));
personEdit = factory.createPersonEdit();
navi.addView(ClubhelperViews.PersonEditView.name(), personEdit); navi.addView(ClubhelperViews.PersonEditView.name(), personEdit);
navi.addView(ClubhelperViews.EventDetails.name(), new EventDetails(context)); navi.addView(ClubhelperViews.EventDetails.name(), new EventDetails(context));
@ -91,6 +98,15 @@ public class ClubhelperNavigation implements ApplicationContextAware {
}); });
} }
private void setupMenuItemStateFactory(MenuItemStateFactory menuItemFactory) {
menuItemFactory.setStartDateSupplier(mainView.startDateSupplier());
menuItemFactory.setEndDateSupplier(mainView.endDateSupplier());
menuItemFactory.setNewPersonConsumer(personEdit::setNewPerson);
}
public ClubNavigator getNavigator() { public ClubNavigator getNavigator() {
return navi; return navi;
} }
@ -114,12 +130,9 @@ public class ClubhelperNavigation implements ApplicationContextAware {
} }
public PersonEditView createPersonEdit() { public PersonEditView createPersonEdit() {
MenuItemStateFactory menuItemFactory = context.getBean(MenuItemStateFactory.class); PersonEditView personEditView = new PersonEditView(groupDao, personBusiness,
menuItemFactory.setStartDateSupplier(mainView.startDateSupplier()); (page.getBrowserWindowWidth() >= WIDTH_LIMIT_FOR_MOBILE));
menuItemFactory.setEndDateSupplier(mainView.endDateSupplier()); return personEditView;
ClubhelperMenuBar menuBar = new ClubhelperMenuBar(menuItemFactory.currentState());
return new PersonEditView(groupDao, personBusiness,
menuBar, menuItemFactory, (page.getBrowserWindowWidth() >= WIDTH_LIMIT_FOR_MOBILE));
} }
} }

@ -1,14 +1,11 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.vaadin.event.selection.SelectionEvent; import com.vaadin.event.selection.SelectionEvent;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View; import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.ContentMode;
@ -38,17 +35,11 @@ public class PersonEditView extends VerticalLayout implements View {
private PersonEditDetails personDetails; private PersonEditDetails personDetails;
private Navigator navigator;
private MenuItemStateFactory menuStateFactory; private MenuItemStateFactory menuStateFactory;
public PersonEditView(GroupDao groupDao, PersonBusiness personDao, ClubhelperMenuBar menuBar, public PersonEditView(GroupDao groupDao, PersonBusiness personDao,
MenuItemStateFactory menuStateFactory,
boolean horizontalLayout) { boolean horizontalLayout) {
setMargin(true); setMargin(true);
this.menuBar = menuBar;
this.menuStateFactory = menuStateFactory;
addComponent(menuBar);
personGrid = new PersonGrid(groupDao, personDao); personGrid = new PersonGrid(groupDao, personDao);
personGrid.setSizeFull(); personGrid.setSizeFull();
personGrid.onPersonEdit(); personGrid.onPersonEdit();
@ -65,10 +56,6 @@ public class PersonEditView extends VerticalLayout implements View {
else { else {
addComponent(createVerticalLayout()); addComponent(createVerticalLayout());
} }
Button addPerson = new Button("Hinzufügen");
addPerson.addClickListener(ev -> addPerson());
addComponent(addPerson);
} }
public HorizontalLayout createHorizontalLayout() { public HorizontalLayout createHorizontalLayout() {
@ -87,13 +74,8 @@ public class PersonEditView extends VerticalLayout implements View {
return layout; return layout;
} }
private void addPerson() { public void setNewPerson(Person p) {
Person person = new Person(); personDetails.setBean(p);
person.setGroups(new HashSet<>());
person.setAdresses(new ArrayList<>());
person.setEvents(new HashSet<>());
person.setRelatives1(new ArrayList<>());
personDetails.setBean(person);
personGrid.deselectAll(); personGrid.deselectAll();
} }
@ -137,9 +119,16 @@ public class PersonEditView extends VerticalLayout implements View {
@Override @Override
public void enter(ViewChangeEvent event) { public void enter(ViewChangeEvent event) {
this.navigator = event.getNavigator();
menuBar.applyState(menuStateFactory.currentState()); menuBar.applyState(menuStateFactory.currentState());
LOG.debug("opened {}", getClass().getName()); LOG.debug("opened {}", getClass().getName());
} }
public void setMenuBar(ClubhelperMenuBar menuBar) {
this.menuBar = menuBar;
addComponentAsFirst(menuBar);
}
public void setMenuStateFactory(MenuItemStateFactory menuStateFactory) {
this.menuStateFactory = menuStateFactory;
}
} }

Loading…
Cancel
Save