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.components.ConfirmDialog;
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 net.sf.jasperreports.engine.JasperPrint;
/**
* Status für authentifizierte User mit Menuitems für jedes View
* @author markus
*
*/
class LoggedinMenuitemState extends LoggedOffState {
private ClubNavigator navigator2;
private SecurityVerifier securityVerifier;
private ClubhelperNavigation navigator;
@ -90,7 +92,7 @@ class LoggedinMenuitemState extends LoggedOffState {
@Override
protected ClubCommand loginOutCommand() {
return new LogoutCommand(navigator2, securityVerifier);
return new LogoutCommand(navigator.getNavigator(), securityVerifier);
}
private void prepareViewMenu(ClubhelperMenuBar menuBar) {
@ -123,6 +125,7 @@ class LoggedinMenuitemState extends LoggedOffState {
CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent));
deleteMenuItem = editMenu.addItem(deleeteEvent.getLabel(), deleeteEvent);
}
protected void setSelectedMenuItem(ClubhelperViews view) {

@ -4,6 +4,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.slf4j.Logger;
@ -21,6 +22,7 @@ import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.UI;
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.ui.navigation.ClubhelperNavigation;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews;
@ -47,12 +49,16 @@ public class MenuItemStateFactory implements ApplicationContextAware {
private Supplier<ZonedDateTime> endDateSupplier;
private Consumer<Person> newPersonConsumer;
public MenuItemState currentState() {
MenuItemState state;
View currentView = clubhelperNavigation.getNavigator().getCurrentView();
ClubhelperViews current = ClubhelperViews.byView(currentView);
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()) {
state = new LoggedinMenuitemState(context, ui, startDateSupplier, endDateSupplier, this::showPrint);
@ -113,4 +119,8 @@ public class MenuItemStateFactory implements ApplicationContextAware {
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);
mainView = factory.createMain();
personEdit = factory.createPersonEdit();
MenuItemStateFactory menuItemFactory = context.getBean(MenuItemStateFactory.class);
setupMenuItemStateFactory(menuItemFactory);
navi = new ClubNavigator().init(mainUI);
ClubhelperMenuBar menuBar = new ClubhelperMenuBar(menuItemFactory.currentState());
personEdit.setMenuBar(menuBar);
personEdit.setMenuStateFactory(menuItemFactory);
navi.addView("", mainView);
navi.addView(ClubhelperViews.MainView.name(), mainView);
navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personBusiness, securityGroupVerifier));
personEdit = factory.createPersonEdit();
navi.addView(ClubhelperViews.PersonEditView.name(), personEdit);
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() {
return navi;
}
@ -114,12 +130,9 @@ public class ClubhelperNavigation implements ApplicationContextAware {
}
public PersonEditView createPersonEdit() {
MenuItemStateFactory menuItemFactory = context.getBean(MenuItemStateFactory.class);
menuItemFactory.setStartDateSupplier(mainView.startDateSupplier());
menuItemFactory.setEndDateSupplier(mainView.endDateSupplier());
ClubhelperMenuBar menuBar = new ClubhelperMenuBar(menuItemFactory.currentState());
return new PersonEditView(groupDao, personBusiness,
menuBar, menuItemFactory, (page.getBrowserWindowWidth() >= WIDTH_LIMIT_FOR_MOBILE));
PersonEditView personEditView = new PersonEditView(groupDao, personBusiness,
(page.getBrowserWindowWidth() >= WIDTH_LIMIT_FOR_MOBILE));
return personEditView;
}
}

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