Switch to menu bar actions

master
Markus Kreth 6 years ago
parent 1314eb2ce5
commit 7daf22a7e3
  1. 6
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
  2. 42
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/AbstractExportAction.java
  3. 23
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/ExportCalendarMonthCommand.java
  4. 22
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/ExportCalendarYearCommand.java
  5. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/LoginCommand.java
  6. 31
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/OpenPersonEditorCommand.java
  7. 43
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/SwitchViewCommand.java
  8. 19
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  9. 25
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ClubEventProvider.java
  10. 5
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java
  11. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/ClubhelperMenuBar.java
  12. 38
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/CommandWrapper.java
  13. 43
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/LoggedOffState.java
  14. 87
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/LoggedinMenuitemState.java
  15. 117
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/MenuItemStateFactory.java
  16. 38
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java
  17. 15
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperViews.java
  18. 16
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/DesktopHeadView.java
  19. 166
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/HeadView.java
  20. 77
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/MainView.java
  21. 40
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/MainViewDesktop.java
  22. 20
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/MainViewMobile.java
  23. 21
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/PersonEditView.java
  24. 1
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoTest.java
  25. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/YearlyCalendarCreatorTest.java
  26. 1
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/LoginUITest.java

@ -20,6 +20,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
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;
@ -30,6 +31,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews
public class MainUi extends UI { public class MainUi extends UI {
private static final long serialVersionUID = 7581634188909841919L; private static final long serialVersionUID = 7581634188909841919L;
private static final Logger LOGGER = LoggerFactory.getLogger(MainUi.class); private static final Logger LOGGER = LoggerFactory.getLogger(MainUi.class);
@Autowired @Autowired
@ -53,6 +55,9 @@ public class MainUi extends UI {
@Autowired @Autowired
ClubhelperNavigation clubhelperNavigation; ClubhelperNavigation clubhelperNavigation;
@Autowired
MenuItemStateFactory menuStateFactory;
@Override @Override
protected void init(VaadinRequest request) { protected void init(VaadinRequest request) {
@ -67,6 +72,7 @@ public class MainUi extends UI {
page.setTitle("Vereinshelfer"); page.setTitle("Vereinshelfer");
clubhelperNavigation.configure(this); clubhelperNavigation.configure(this);
menuStateFactory.configure(getUI());
clubhelperNavigation.navigateTo(ClubhelperViews.MainView.name()); clubhelperNavigation.navigateTo(ClubhelperViews.MainView.name());
} }

@ -2,8 +2,6 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -17,7 +15,7 @@ import com.vaadin.ui.Notification;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator; import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider;
import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrint;
@ -25,8 +23,6 @@ public abstract class AbstractExportAction implements ClubCommand {
protected final transient Logger log = LoggerFactory.getLogger(getClass()); protected final transient Logger log = LoggerFactory.getLogger(getClass());
private transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uuuu");
private final Supplier<ZonedDateTime> startTime; private final Supplier<ZonedDateTime> startTime;
private final Supplier<ZonedDateTime> endTime; private final Supplier<ZonedDateTime> endTime;
@ -49,20 +45,10 @@ public abstract class AbstractExportAction implements ClubCommand {
@Override @Override
public void execute() { public void execute() {
boolean monthOnly = getMonthOnly();
List<ClubEvent> items; List<ClubEvent> items;
ZonedDateTime start; ZonedDateTime start = startTime.get();
ZonedDateTime end; ZonedDateTime end = endTime.get();
if (monthOnly) { items = dataProvider.getItems(start, end);
start = startTime.get();
end = endTime.get();
items = dataProvider.getItems(start, end);
}
else {
start = startTime.get().withDayOfYear(1);
end = start.withMonth(12).withDayOfMonth(31);
items = dataProvider.getItems(start, end);
}
Map<LocalDate, StringBuilder> values = new HashMap<>(); Map<LocalDate, StringBuilder> values = new HashMap<>();
List<LocalDate> holidays = CalendarCreator.filterHolidays(items); List<LocalDate> holidays = CalendarCreator.filterHolidays(items);
@ -94,22 +80,10 @@ public abstract class AbstractExportAction implements ClubCommand {
}); });
} }
String calendarMonth; String calendarMonth = getTitle();
if (monthOnly) {
calendarMonth = dfMonth.format(start);
}
else {
calendarMonth = "Jahr " + start.getYear();
}
try { try {
JasperPrint print; JasperPrint print = createPrint(values, holidays);
if (monthOnly) {
print = CalendarCreator.createCalendar(new Date(start.toInstant().toEpochMilli()), values, holidays);
}
else {
print = CalendarCreator.createYearCalendar(start.getYear(), values, holidays);
}
log.trace("Created Jasper print for {}", calendarMonth); log.trace("Created Jasper print for {}", calendarMonth);
printConsumer.accept(calendarMonth, print); printConsumer.accept(calendarMonth, print);
@ -121,6 +95,8 @@ public abstract class AbstractExportAction implements ClubCommand {
} }
} }
protected abstract boolean getMonthOnly(); protected abstract String getTitle();
protected abstract JasperPrint createPrint(Map<LocalDate, StringBuilder> values, List<LocalDate> holidays)
throws JRException;
} }

@ -1,19 +1,31 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.vaadin.server.Resource; import com.vaadin.server.Resource;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrint;
public class ExportCalendarMonthCommand extends AbstractExportAction { public class ExportCalendarMonthCommand extends AbstractExportAction {
private transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uuuu");
private ZonedDateTime start;
public ExportCalendarMonthCommand(Supplier<ZonedDateTime> startTime, Supplier<ZonedDateTime> endTime, public ExportCalendarMonthCommand(Supplier<ZonedDateTime> startTime, Supplier<ZonedDateTime> endTime,
ClubEventProvider dataProvider, BiConsumer<String, JasperPrint> printConsumer) { ClubEventProvider dataProvider, BiConsumer<String, JasperPrint> printConsumer) {
super(startTime, endTime, dataProvider, printConsumer); super(startTime, endTime, dataProvider, printConsumer);
this.start = startTime.get();
} }
@Override @Override
@ -27,8 +39,13 @@ public class ExportCalendarMonthCommand extends AbstractExportAction {
} }
@Override @Override
protected boolean getMonthOnly() { protected String getTitle() {
return true; return dfMonth.format(start);
} }
@Override
protected JasperPrint createPrint(Map<LocalDate, StringBuilder> values, List<LocalDate> holidays)
throws JRException {
return CalendarCreator.createCalendar(new Date(start.toInstant().toEpochMilli()), values, holidays);
}
} }

@ -1,19 +1,28 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.vaadin.server.Resource; import com.vaadin.server.Resource;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrint;
public class ExportCalendarYearCommand extends AbstractExportAction { public class ExportCalendarYearCommand extends AbstractExportAction {
private ZonedDateTime start;
public ExportCalendarYearCommand(Supplier<ZonedDateTime> startTime, Supplier<ZonedDateTime> endTime, public ExportCalendarYearCommand(Supplier<ZonedDateTime> startTime, Supplier<ZonedDateTime> endTime,
ClubEventProvider dataProvider, BiConsumer<String, JasperPrint> printConsumer) { ClubEventProvider dataProvider, BiConsumer<String, JasperPrint> printConsumer) {
super(startTime, endTime, dataProvider, printConsumer); super(() -> startTime.get().withDayOfYear(1), () -> startTime.get().withMonth(12).withDayOfMonth(31),
dataProvider, printConsumer);
this.start = startTime.get().withDayOfYear(1);
} }
@Override @Override
@ -27,8 +36,13 @@ public class ExportCalendarYearCommand extends AbstractExportAction {
} }
@Override @Override
protected boolean getMonthOnly() { protected String getTitle() {
return false; return "Jahr " + start.getYear();
} }
@Override
protected JasperPrint createPrint(Map<LocalDate, StringBuilder> values, List<LocalDate> holidays)
throws JRException {
return CalendarCreator.createYearCalendar(start.getYear(), values, holidays);
}
} }

@ -17,7 +17,6 @@ public class LoginCommand implements ClubCommand {
@Override @Override
public void execute() { public void execute() {
navigator.navigateTo(ClubhelperViews.LoginUI.name()); navigator.navigateTo(ClubhelperViews.LoginUI.name());
} }

@ -1,31 +0,0 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import com.vaadin.server.Resource;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews;
public class OpenPersonEditorCommand implements ClubCommand {
private ClubNavigator navigator;
public OpenPersonEditorCommand(ClubNavigator navigator2) {
this.navigator = navigator2;
}
@Override
public String getLabel() {
return "Personen verwalten";
}
@Override
public Resource getIcon() {
return null;
}
@Override
public void execute() {
navigator.navigateTo(ClubhelperViews.PersonEditView.name());
}
}

@ -0,0 +1,43 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
import org.springframework.context.ApplicationContext;
import com.vaadin.server.Resource;
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;
public class SwitchViewCommand implements ClubCommand {
private ClubNavigator navigator;
private ClubhelperViews target;
private String label;
private Resource icon;
public SwitchViewCommand(ApplicationContext context, String label, Resource icon, ClubhelperViews target) {
this.navigator = context.getBean(ClubhelperNavigation.class).getNavigator();
this.label = label;
this.target = target;
this.icon = icon;
}
@Override
public String getLabel() {
return label;
}
@Override
public Resource getIcon() {
return icon;
}
@Override
public void execute() {
navigator.navigateTo(target);
}
}

@ -11,7 +11,6 @@ import java.util.function.Consumer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.vaadin.addon.calendar.Calendar; import org.vaadin.addon.calendar.Calendar;
import org.vaadin.addon.calendar.item.BasicItemProvider;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents.BackwardEvent; import org.vaadin.addon.calendar.ui.CalendarComponentEvents.BackwardEvent;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents.ForwardEvent; import org.vaadin.addon.calendar.ui.CalendarComponentEvents.ForwardEvent;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents.ItemClickHandler; import org.vaadin.addon.calendar.ui.CalendarComponentEvents.ItemClickHandler;
@ -83,24 +82,6 @@ public class CalendarComponent extends CustomComponent implements CalendarView {
calendar.markAsDirty(); calendar.markAsDirty();
} }
/**
* {@link ClubEvent} provider for vaadin calendar addon.
* @author markus
*
*/
public static class ClubEventProvider extends BasicItemProvider<ClubEvent> {
private static final long serialVersionUID = -5415397258827236704L;
@Override
public void setItems(Collection<ClubEvent> items) {
super.itemList.clear();
super.setItems(items);
fireItemSetChanged();
}
}
@Override @Override
public ZonedDateTime getStartDate() { public ZonedDateTime getStartDate() {
return calendar.getStartDate(); return calendar.getStartDate();

@ -0,0 +1,25 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.util.Collection;
import org.springframework.stereotype.Component;
import org.vaadin.addon.calendar.item.BasicItemProvider;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
/**
* {@link ClubEvent} provider for vaadin calendar addon.
* @author markus
*
*/
@Component
public class ClubEventProvider extends BasicItemProvider<ClubEvent> {
@Override
public void setItems(Collection<ClubEvent> items) {
super.itemList.clear();
super.setItems(items);
fireItemSetChanged();
}
}

@ -15,7 +15,6 @@ import com.vaadin.server.SerializablePredicate;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.renderers.AbstractRenderer; import com.vaadin.ui.renderers.AbstractRenderer;
import com.vaadin.ui.renderers.Renderer;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@ -78,10 +77,6 @@ public class EventGrid extends Grid<ClubEvent> {
} }
} }
private Renderer<Set<Person>> createRenderer() {
return new PersonSetRenderer();
}
private static final Set<Person> set = new HashSet<>(); private static final Set<Person> set = new HashSet<>();
class PersonSetRenderer extends AbstractRenderer<Object, Set<Person>> { class PersonSetRenderer extends AbstractRenderer<Object, Set<Person>> {

@ -16,6 +16,7 @@ public class ClubhelperMenuBar extends MenuBar {
private final MenuItem settingsItem; private final MenuItem settingsItem;
public ClubhelperMenuBar(MenuItemState initialState) { public ClubhelperMenuBar(MenuItemState initialState) {
setWidth("100%");
fileMenuItem = addItem("Datei"); fileMenuItem = addItem("Datei");
editMenuItem = addItem("Bearbeiten"); editMenuItem = addItem("Bearbeiten");
viewMenuItem = addItem("Ansicht"); viewMenuItem = addItem("Ansicht");

@ -0,0 +1,38 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu;
import com.vaadin.server.Resource;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
public class CommandWrapper implements Command, ClubCommand {
private final ClubCommand command;
public CommandWrapper(ClubCommand command) {
super();
this.command = command;
}
@Override
public void menuSelected(MenuItem selectedItem) {
execute();
}
@Override
public String getLabel() {
return command.getLabel();
}
@Override
public Resource getIcon() {
return command.getIcon();
}
@Override
public void execute() {
command.execute();
}
}

@ -1,26 +1,46 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu;
import java.time.ZonedDateTime;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem; import com.vaadin.ui.MenuBar.MenuItem;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarMonthCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarYearCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCsvCommand; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCsvCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.LoginCommand; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.LoginCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider;
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.ClubhelperNavigation.ClubNavigator;
import net.sf.jasperreports.engine.JasperPrint;
public class LoggedOffState implements MenuItemState { class LoggedOffState implements MenuItemState {
private final ClubNavigator navigator; private final ClubNavigator navigator;
private ApplicationContext context; private final ApplicationContext context;
private final ClubEventProvider dataProvider;
private final Supplier<ZonedDateTime> startProvider;
private final Supplier<ZonedDateTime> endProvider;
public LoggedOffState(ApplicationContext context) { private BiConsumer<String, JasperPrint> printConsumer;
public LoggedOffState(ApplicationContext context, Supplier<ZonedDateTime> startProvider,
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) {
super(); super();
this.navigator = context.getBean(ClubhelperNavigation.class).getNavigator(); this.navigator = context.getBean(ClubhelperNavigation.class).getNavigator();
this.context = context; this.context = context;
this.dataProvider = context.getBean(ClubEventProvider.class);
this.startProvider = startProvider;
this.endProvider = endProvider;
this.printConsumer = printConsumer;
} }
@Override @Override
@ -32,15 +52,16 @@ public class LoggedOffState implements MenuItemState {
MenuItem fileMenu = menuBar.getFileMenuItem(); MenuItem fileMenu = menuBar.getFileMenuItem();
fileMenu.setVisible(true); fileMenu.setVisible(true);
LoginCommand loginCommand = new LoginCommand(navigator); LoginCommand loginCommand = new LoginCommand(navigator);
fileMenu.addItem(loginCommand.getLabel(), new Command() { fileMenu.addItem(loginCommand.getLabel(), new CommandWrapper(loginCommand));
@Override
public void menuSelected(MenuItem selectedItem) {
loginCommand.execute();
}
});
MenuItem editMenu = menuBar.getEditMenuItem(); MenuItem editMenu = menuBar.getEditMenuItem();
editMenu.setVisible(true); editMenu.setVisible(true);
CommandWrapper exportCalendarMonthCommand = new CommandWrapper(
new ExportCalendarMonthCommand(startProvider, endProvider, dataProvider, printConsumer));
editMenu.addItem(exportCalendarMonthCommand.getLabel(), exportCalendarMonthCommand);
ClubCommand exportCalendarYearCommand = new ExportCalendarYearCommand(startProvider, endProvider, dataProvider,
printConsumer);
editMenu.addItem(exportCalendarYearCommand.getLabel(), new CommandWrapper(exportCalendarYearCommand));
ClubCommand exportCsvCommand = new ExportCsvCommand(menuBar, context); ClubCommand exportCsvCommand = new ExportCsvCommand(menuBar, context);
editMenu.addItem(exportCsvCommand.getLabel(), ev -> exportCsvCommand.execute()); editMenu.addItem(exportCsvCommand.getLabel(), ev -> exportCsvCommand.execute());

@ -1,9 +1,94 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu;
public class LoggedinMenuitemState implements MenuItemState { import java.time.ZonedDateTime;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.springframework.context.ApplicationContext;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.View;
import com.vaadin.ui.MenuBar.MenuItem;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarMonthCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarYearCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCsvCommand;
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.ClubEventProvider;
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;
class LoggedinMenuitemState implements MenuItemState {
private ClubNavigator navigator2;
private SecurityVerifier securityVerifier;
private ClubhelperNavigation navigator;
private ApplicationContext context;
private ClubEventProvider dataProvider;
private Supplier<ZonedDateTime> startProvider;
private Supplier<ZonedDateTime> endProvider;
private BiConsumer<String, JasperPrint> printConsumer;
public LoggedinMenuitemState(ApplicationContext context, Supplier<ZonedDateTime> startProvider,
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) {
super();
this.navigator = context.getBean(ClubhelperNavigation.class);
this.context = context;
this.dataProvider = context.getBean(ClubEventProvider.class);
this.startProvider = startProvider;
this.endProvider = endProvider;
this.printConsumer = printConsumer;
}
@Override @Override
public void applyMenuStates(ClubhelperMenuBar menuBar) { public void applyMenuStates(ClubhelperMenuBar menuBar) {
MenuItem fileMenuItem = menuBar.getFileMenuItem();
fileMenuItem.setVisible(true);
CommandWrapper logout = new CommandWrapper(new LogoutCommand(navigator2, securityVerifier));
fileMenuItem.addItem(logout.getLabel(), logout);
MenuItem editMenu = menuBar.getEditMenuItem();
CommandWrapper exportCalendarMonthCommand = new CommandWrapper(
new ExportCalendarMonthCommand(startProvider, endProvider, dataProvider, printConsumer));
editMenu.addItem(exportCalendarMonthCommand.getLabel(), exportCalendarMonthCommand);
ClubCommand exportCalendarYearCommand = new ExportCalendarYearCommand(startProvider, endProvider, dataProvider,
printConsumer);
editMenu.addItem(exportCalendarYearCommand.getLabel(), new CommandWrapper(exportCalendarYearCommand));
ClubCommand exportCsvCommand = new ExportCsvCommand(menuBar, context);
editMenu.addItem(exportCsvCommand.getLabel(), ev -> exportCsvCommand.execute());
MenuItem viewMenu = menuBar.getViewMenuItem();
viewMenu.setVisible(true);
CommandWrapper openPersonEditor = new CommandWrapper(
new SwitchViewCommand(context, "Personen verwalten", VaadinIcons.EDIT, ClubhelperViews.PersonEditView));
MenuItem openPersonMenuItem = viewMenu.addItem(openPersonEditor.getLabel(), openPersonEditor);
openPersonMenuItem.setCheckable(true);
CommandWrapper calendarView = new CommandWrapper(
new SwitchViewCommand(context, "Hauptansicht", VaadinIcons.CALENDAR, ClubhelperViews.MainView));
MenuItem calendarMenuItem = viewMenu.addItem(calendarView.getLabel(), calendarView);
calendarMenuItem.setCheckable(true);
View current = navigator.getNavigator().getCurrentView();
ClubhelperViews view = ClubhelperViews.byView(current);
if (ClubhelperViews.PersonEditView == view) {
openPersonMenuItem.setChecked(true);
}
else {
calendarMenuItem.setChecked(true);
}
} }
} }

@ -0,0 +1,117 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import com.vaadin.navigator.View;
import com.vaadin.server.FileResource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
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;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
@Component
public class MenuItemStateFactory implements ApplicationContextAware {
private static final Logger LOGGER = LoggerFactory.getLogger(MenuItemStateFactory.class);
private ApplicationContext context;
@Autowired
ClubhelperNavigation clubhelperNavigation;
@Autowired
SecurityVerifier securityGroupVerifier;
private UI ui;
private Supplier<ZonedDateTime> startDateSupplier;
private Supplier<ZonedDateTime> endDateSupplier;
public MenuItemState currentState() {
MenuItemState state;
View currentView = clubhelperNavigation.getNavigator().getCurrentView();
ClubhelperViews current = ClubhelperViews.byView(currentView);
if (ClubhelperViews.PersonEditView == current) {
state = new LoggedinMenuitemState(context, startDateSupplier, endDateSupplier, this::showPrint);
}
else if (securityGroupVerifier.isLoggedin()) {
state = new LoggedinMenuitemState(context, startDateSupplier, endDateSupplier, this::showPrint);
}
else {
state = new LoggedOffState(context, startDateSupplier, endDateSupplier, this::showPrint);
}
return state;
}
private void showPrint(String calendarMonth, JasperPrint print) {
Window window = new Window();
window.setCaption("View PDF");
AbstractComponent e;
try {
e = createEmbedded(calendarMonth, print);
}
catch (Exception e1) {
LOGGER.error("Error creating PDF Element", e1);
return;
}
window.setContent(e);
window.setModal(true);
window.setWidth("50%");
window.setHeight("90%");
ui.addWindow(window);
}
private AbstractComponent createEmbedded(String title, JasperPrint print) throws IOException, JRException {
Path pdfFile = Files.createTempFile(title.replace(' ', '_'), ".pdf").toAbsolutePath();
JasperExportManager.exportReportToPdfFile(print, pdfFile.toString());
final FileResource resource = new FileResource(pdfFile.toFile());
BrowserFrame c = new BrowserFrame("PDF invoice", resource);
c.setSizeFull();
return c;
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
this.context = context;
}
public void setStartDateSupplier(Supplier<ZonedDateTime> startDateSupplier) {
this.startDateSupplier = startDateSupplier;
}
public void setEndDateSupplier(Supplier<ZonedDateTime> endDateSupplier) {
this.endDateSupplier = endDateSupplier;
}
public void configure(UI ui) {
this.ui = ui;
}
}

@ -1,6 +1,8 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.time.ZonedDateTime;
import java.util.Stack; import java.util.Stack;
import java.util.function.Supplier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,12 +24,16 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.EventDetails; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.EventDetails;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.ClubhelperMenuBar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
@Component @Component
public class ClubhelperNavigation implements ApplicationContextAware { public class ClubhelperNavigation implements ApplicationContextAware {
private static final Logger LOGGER = LoggerFactory.getLogger(ClubhelperNavigation.class); private static final Logger LOGGER = LoggerFactory.getLogger(ClubhelperNavigation.class);
private static final int WIDTH_LIMIT_FOR_MOBILE = 1000;
private ApplicationContext context; private ApplicationContext context;
@Autowired @Autowired
@ -50,21 +56,25 @@ public class ClubhelperNavigation implements ApplicationContextAware {
@Autowired @Autowired
PersonBusiness personBusiness; PersonBusiness personBusiness;
public void configure(UI mainUI) { private MainView mainView;
navi = new ClubNavigator().init(mainUI); private PersonEditView personEdit;
public void configure(UI mainUI) {
// Create and register the views // Create and register the views
Page page = mainUI.getPage(); Page page = mainUI.getPage();
ViewFactory factory = new ViewFactory(page); ViewFactory factory = new ViewFactory(page);
MainView mainView = factory.createMain(); mainView = factory.createMain();
navi = new ClubNavigator().init(mainUI);
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));
navi.addView(ClubhelperViews.PersonEditView.name(), factory.createPersonEdit()); personEdit = factory.createPersonEdit();
navi.addView(ClubhelperViews.PersonEditView.name(), personEdit);
navi.addView(ClubhelperViews.EventDetails.name(), navi.addView(ClubhelperViews.EventDetails.name(),
new EventDetails(personBusiness, groupDao, eventBusiness, pflichtenDao, calendarAdapter)); new EventDetails(personBusiness, groupDao, eventBusiness, pflichtenDao, calendarAdapter));
@ -93,7 +103,7 @@ public class ClubhelperNavigation implements ApplicationContextAware {
public MainView createMain() { public MainView createMain() {
if (page.getBrowserWindowWidth() < 1000) { if (page.getBrowserWindowWidth() < WIDTH_LIMIT_FOR_MOBILE) {
return new MainViewMobile(context, personBusiness, groupDao, eventBusiness, securityGroupVerifier); return new MainViewMobile(context, personBusiness, groupDao, eventBusiness, securityGroupVerifier);
} }
else { else {
@ -102,7 +112,12 @@ public class ClubhelperNavigation implements ApplicationContextAware {
} }
public PersonEditView createPersonEdit() { public PersonEditView createPersonEdit() {
return new PersonEditView(groupDao, personBusiness, (page.getBrowserWindowWidth() >= 1000)); 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));
} }
} }
@ -141,7 +156,7 @@ public class ClubhelperNavigation implements ApplicationContextAware {
int width = navi.getUI().getPage().getBrowserWindowWidth(); int width = navi.getUI().getPage().getBrowserWindowWidth();
boolean loggedIn = securityGroupVerifier.isLoggedin(); boolean loggedIn = securityGroupVerifier.isLoggedin();
if (!loggedIn && width < 1000) { if (!loggedIn && width < WIDTH_LIMIT_FOR_MOBILE) {
navigationViewNames.clear(); navigationViewNames.clear();
navigationViewNames.add(ClubhelperViews.MainView); navigationViewNames.add(ClubhelperViews.MainView);
super.navigateTo(ClubhelperViews.LoginUI.name()); super.navigateTo(ClubhelperViews.LoginUI.name());
@ -163,4 +178,13 @@ public class ClubhelperNavigation implements ApplicationContextAware {
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext; this.context = applicationContext;
} }
public Supplier<ZonedDateTime> startDateSupplier() {
return mainView.startDateSupplier();
}
public Supplier<ZonedDateTime> endDateSupplier() {
return mainView.endDateSupplier();
}
} }

@ -1,10 +1,15 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import com.vaadin.navigator.View;
public enum ClubhelperViews { public enum ClubhelperViews {
/** /**
* With Alias '' * With Alias ''
*/ */
MainView, EventDetails, PersonEditView, LoginUI; MainView,
EventDetails,
PersonEditView,
LoginUI;
public static ClubhelperViews byState(String state) { public static ClubhelperViews byState(String state) {
if (state.isBlank()) { if (state.isBlank()) {
@ -17,4 +22,12 @@ public enum ClubhelperViews {
} }
throw new IllegalArgumentException("View not found for state=" + state); throw new IllegalArgumentException("View not found for state=" + state);
} }
public static ClubhelperViews byView(View currentView) {
if (currentView == null) {
return MainView;
}
return byState(currentView.getClass().getSimpleName());
}
} }

@ -1,27 +1,15 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.function.Function;
import org.springframework.context.ApplicationContext;
import com.vaadin.ui.Component;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
public class DesktopHeadView extends HeadView { public class DesktopHeadView extends HeadView {
private static final long serialVersionUID = 1596573215389558000L; private static final long serialVersionUID = 1596573215389558000L;
public DesktopHeadView(ApplicationContext context, ClubNavigator navigator, public DesktopHeadView(SecurityVerifier securityVerifier) {
Function<Component, ZonedDateTime> startTime, super(securityVerifier);
Function<Component, ZonedDateTime> endTime, ClubEventProvider dataProvider,
SecurityVerifier securityVerifier) {
super(context, navigator, startTime, endTime, dataProvider, securityVerifier);
} }
public void updateMonthText(ZonedDateTime startDate) { public void updateMonthText(ZonedDateTime startDate) {

@ -1,45 +1,16 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.function.Function;
import java.util.function.Supplier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import com.vaadin.contextmenu.ContextMenu;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.StreamResource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment; import com.vaadin.ui.Alignment;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityGroups;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarMonthCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarYearCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCsvCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.LoginCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.LogoutCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.OpenPersonEditorCommand;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
public class HeadView extends HorizontalLayout { public class HeadView extends HorizontalLayout {
@ -47,57 +18,30 @@ public class HeadView extends HorizontalLayout {
protected transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uuuu"); protected transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uuuu");
private final ClubEventProvider dataProvider; private final Label personLabel;
private final Button personLabel;
protected final Label monthName; protected final Label monthName;
private final Function<Component, ZonedDateTime> startTime;
private final Function<Component, ZonedDateTime> endTime;
private final ClubNavigator navigator;
private final SecurityVerifier securityVerifier; private final SecurityVerifier securityVerifier;
private ApplicationContext context; public HeadView(SecurityVerifier securityVerifier) {
public HeadView(ApplicationContext context, ClubNavigator navigator2,
Function<Component, ZonedDateTime> startTime,
Function<Component, ZonedDateTime> endTime, ClubEventProvider dataProvider,
SecurityVerifier securityVerifier) {
this.context = context;
this.navigator = navigator2;
this.securityVerifier = securityVerifier; this.securityVerifier = securityVerifier;
this.startTime = startTime;
this.endTime = endTime;
Button popupButton = new Button(VaadinIcons.MENU);
popupButton.setId("head.menu");
popupButton.addClickListener(ev -> openPopupMenu(ev));
popupButton.setWidth(null);
monthName = new Label(); monthName = new Label();
monthName.setId("calendar.month"); monthName.setId("calendar.month");
monthName.setStyleName("title_caption"); monthName.setStyleName("title_caption");
monthName.setWidth(""); monthName.setWidth("");
personLabel = new Button(VaadinIcons.USER); personLabel = new Label();
personLabel.setId("head.user"); personLabel.setId("head.user");
personLabel.addClickListener(this::openPopupMenu);
addComponent(popupButton);
addComponent(monthName); addComponent(monthName);
addComponent(personLabel); addComponent(personLabel);
setComponentAlignment(popupButton, Alignment.MIDDLE_LEFT); setComponentAlignment(monthName, Alignment.MIDDLE_LEFT);
setComponentAlignment(monthName, Alignment.MIDDLE_CENTER);
setComponentAlignment(personLabel, Alignment.MIDDLE_RIGHT); setComponentAlignment(personLabel, Alignment.MIDDLE_RIGHT);
setExpandRatio(monthName, 1.0f); setExpandRatio(monthName, 1.0f);
this.dataProvider = dataProvider;
} }
public void updateLoggedinPerson() { public void updateLoggedinPerson() {
@ -111,106 +55,4 @@ public class HeadView extends HorizontalLayout {
} }
} }
private void openPopupMenu(ClickEvent ev) {
Button button = ev.getButton();
ContextMenu contextMenu = new ContextMenu(button, true);
switch (button.getId()) {
case "head.menu":
Supplier<ZonedDateTime> start = () -> startTime.apply(button);
Supplier<ZonedDateTime> end = () -> endTime.apply(button);
ClubCommand exportCalendarMonthCommand = new ExportCalendarMonthCommand(start, end,
dataProvider, this::showPrint);
contextMenu.addItem(exportCalendarMonthCommand.getLabel(),
ev1 -> exportCalendarMonthCommand.execute());
ClubCommand exportCalendarYearCommand = new ExportCalendarYearCommand(start, end,
dataProvider, this::showPrint);
contextMenu.addItem(exportCalendarYearCommand.getLabel(), ev1 -> exportCalendarYearCommand.execute());
ClubCommand exportCsvCommand = new ExportCsvCommand(button, context);
contextMenu.addItem(exportCsvCommand.getLabel(), ev1 -> exportCsvCommand.execute());
if (securityVerifier.isLoggedin()
&& securityVerifier.isPermitted(SecurityGroups.ADMIN, SecurityGroups.UEBUNGSLEITER)) {
ClubCommand openPersonEditor = new OpenPersonEditorCommand(navigator);
contextMenu.addItem(openPersonEditor.getLabel(),
ev1 -> openPersonEditor.execute());
}
contextMenu.open(50, 50);
break;
case "head.user":
if (securityVerifier.isLoggedin()) {
LogoutCommand logoutCommand = new LogoutCommand(navigator, securityVerifier);
contextMenu.addItem(logoutCommand.getLabel(), ev1 -> {
logoutCommand.execute();
});
}
else {
LoginCommand loginCommand = new LoginCommand(navigator);
contextMenu.addItem(loginCommand.getLabel(), ev1 -> {
loginCommand.execute();
});
}
int width = getUI().getPage().getBrowserWindowWidth();
contextMenu.open(width - 150, 50);
break;
default:
break;
}
}
private void showPrint(String calendarMonth, JasperPrint print) {
Window window = new Window();
window.setCaption("View PDF");
AbstractComponent e;
try {
e = createEmbedded(calendarMonth, print);
}
catch (Exception e1) {
return;
}
window.setContent(e);
window.setModal(true);
window.setWidth("50%");
window.setHeight("90%");
personLabel.getUI().addWindow(window);
}
private AbstractComponent createEmbedded(String title, JasperPrint print) throws IOException, JRException {
final PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
final StreamResource resource = new StreamResource(() -> in, title);
resource.setMIMEType("application/pdf");
BrowserFrame c = new BrowserFrame("PDF invoice", resource);
c.setSizeFull();
try {
JasperExportManager.exportReportToPdfStream(print, out);
}
finally {
try {
out.close();
in.close();
}
catch (IOException e) {
log.warn("Error closing Jasper output stream.", e);
}
}
return c;
}
} }

@ -1,15 +1,25 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.time.ZonedDateTime;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import com.vaadin.event.selection.SelectionEvent; import com.vaadin.event.selection.SelectionEvent;
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.server.StreamResource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ClubhelperException; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ClubhelperException;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness;
@ -19,9 +29,13 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; 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.ClubhelperErrorDialog; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.ClubhelperErrorDialog;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.SingleEventView; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.SingleEventView;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperPrint;
public abstract class MainView extends VerticalLayout implements View { public abstract class MainView extends VerticalLayout implements View {
@ -29,6 +43,8 @@ public abstract class MainView extends VerticalLayout implements View {
protected final Logger LOGGER = LoggerFactory.getLogger(getClass()); protected final Logger LOGGER = LoggerFactory.getLogger(getClass());
private ApplicationContext context;
private final GroupDao groupDao; private final GroupDao groupDao;
protected final EventBusiness eventBusiness; protected final EventBusiness eventBusiness;
@ -43,12 +59,18 @@ public abstract class MainView extends VerticalLayout implements View {
private final PersonBusiness personBusiness; private final PersonBusiness personBusiness;
public MainView(GroupDao groupDao, EventBusiness eventBusiness, PersonBusiness personBusiness, protected ClubEventProvider dataProvider;
public MainView(ApplicationContext context2, GroupDao groupDao, EventBusiness eventBusiness,
PersonBusiness personBusiness,
SecurityVerifier securityGroupVerifier) { SecurityVerifier securityGroupVerifier) {
this.context = context2;
this.personBusiness = personBusiness; this.personBusiness = personBusiness;
this.groupDao = groupDao; this.groupDao = groupDao;
this.eventBusiness = eventBusiness; this.eventBusiness = eventBusiness;
this.securityVerifier = securityGroupVerifier; this.securityVerifier = securityGroupVerifier;
dataProvider = context2.getBean(ClubEventProvider.class);
} }
@Override @Override
@ -87,6 +109,56 @@ public abstract class MainView extends VerticalLayout implements View {
} }
public ApplicationContext getContext() {
return context;
}
protected void showPrint(String calendarMonth, JasperPrint print) {
Window window = new Window();
window.setCaption("View PDF");
AbstractComponent e;
try {
e = createEmbedded(calendarMonth, print);
}
catch (Exception e1) {
return;
}
window.setContent(e);
window.setModal(true);
window.setWidth("50%");
window.setHeight("90%");
eventView.getUI().addWindow(window);
}
private AbstractComponent createEmbedded(String title, JasperPrint print) throws IOException, JRException {
final PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
final StreamResource resource = new StreamResource(() -> in, title);
resource.setMIMEType("application/pdf");
BrowserFrame c = new BrowserFrame("PDF invoice", resource);
c.setSizeFull();
try {
JasperExportManager.exportReportToPdfStream(print, out);
}
finally {
try {
out.close();
in.close();
}
catch (IOException e) {
LOGGER.warn("Error closing Jasper output stream.", e);
}
}
return c;
}
private void personSelectionChange(SelectionEvent<Person> ev) { private void personSelectionChange(SelectionEvent<Person> ev) {
Set<Person> selected = ev.getAllSelectedItems(); Set<Person> selected = ev.getAllSelectedItems();
LOGGER.debug("Selection changed to: {}", selected); LOGGER.debug("Selection changed to: {}", selected);
@ -124,4 +196,7 @@ public abstract class MainView extends VerticalLayout implements View {
eventBusiness.setSelected(ev); eventBusiness.setSelected(ev);
} }
public abstract Supplier<ZonedDateTime> startDateSupplier();
public abstract Supplier<ZonedDateTime> endDateSupplier();
} }

@ -1,8 +1,10 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation; package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Supplier;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents; import org.vaadin.addon.calendar.ui.CalendarComponentEvents;
@ -19,13 +21,12 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.ClubhelperMenuBar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemState;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
public class MainViewDesktop extends MainView { public class MainViewDesktop extends MainView {
/**
*
*/
private static final long serialVersionUID = -3293470536470926668L; private static final long serialVersionUID = -3293470536470926668L;
private VerticalLayout eastLayout; private VerticalLayout eastLayout;
@ -36,30 +37,31 @@ public class MainViewDesktop extends MainView {
private CalendarComponent calendar; private CalendarComponent calendar;
private ClubhelperMenuBar menuBar;
private DesktopHeadView head; private DesktopHeadView head;
private ApplicationContext context; private MenuItemStateFactory menuStateFactory;
public MainViewDesktop(ApplicationContext context, PersonBusiness personDao, GroupDao groupDao, public MainViewDesktop(ApplicationContext context, PersonBusiness personDao, GroupDao groupDao,
EventBusiness eventBusiness, EventBusiness eventBusiness,
SecurityVerifier securityGroupVerifier) { SecurityVerifier securityGroupVerifier) {
super(groupDao, eventBusiness, personDao, securityGroupVerifier); super(context, groupDao, eventBusiness, personDao, securityGroupVerifier);
this.context = context; calendar = new CalendarComponent(dataProvider);
menuStateFactory = context.getBean(MenuItemStateFactory.class);
} }
@Override @Override
public void initUI(ViewChangeEvent event) { public void initUI(ViewChangeEvent event) {
super.initUI(event); super.initUI(event);
MenuItemState state = menuStateFactory.currentState();
ClubEventProvider dataProvider = new ClubEventProvider(); menuBar = new ClubhelperMenuBar(state);
calendar = new CalendarComponent(dataProvider); calendar = new CalendarComponent(dataProvider);
calendar.setSizeFull(); calendar.setSizeFull();
calendar.setId("main.calendar"); calendar.setId("main.calendar");
calendar.setHandler(this::onItemClick); calendar.setHandler(this::onItemClick);
head = new DesktopHeadView(context, navigator, component -> calendar.getStartDate(), head = new DesktopHeadView(securityVerifier);
component -> calendar.getEndDate(),
dataProvider, securityVerifier);
head.setWidth("100%"); head.setWidth("100%");
head.updateMonthText(calendar.getStartDate()); head.updateMonthText(calendar.getStartDate());
@ -87,6 +89,7 @@ public class MainViewDesktop extends MainView {
eastLayout = new VerticalLayout(); eastLayout = new VerticalLayout();
eastLayout.addComponents(eventView, personGrid, eventButtonLayout); eastLayout.addComponents(eventView, personGrid, eventButtonLayout);
addComponent(menuBar);
addComponent(head); addComponent(head);
addComponent(mainLayout); addComponent(mainLayout);
setExpandRatio(mainLayout, 1f); setExpandRatio(mainLayout, 1f);
@ -120,8 +123,9 @@ public class MainViewDesktop extends MainView {
@Override @Override
public void enter(ViewChangeEvent event) { public void enter(ViewChangeEvent event) {
super.enter(event); super.enter(event);
head.updateLoggedinPerson(); head.updateLoggedinPerson();
MenuItemState state = menuStateFactory.currentState();
menuBar.applyState(state);
reloadEvents(); reloadEvents();
} }
@ -157,4 +161,14 @@ public class MainViewDesktop extends MainView {
eventButtonLayout.setVisible(false); eventButtonLayout.setVisible(false);
} }
@Override
public Supplier<ZonedDateTime> startDateSupplier() {
return () -> calendar.getStartDate();
}
@Override
public Supplier<ZonedDateTime> endDateSupplier() {
return () -> calendar.getEndDate();
}
} }

@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Supplier;
import org.basilbourque.timecolumnrenderers.ZonedDateTimeRenderer; import org.basilbourque.timecolumnrenderers.ZonedDateTimeRenderer;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -28,7 +29,6 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.PersonBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider;
public class MainViewMobile extends MainView { public class MainViewMobile extends MainView {
@ -40,13 +40,10 @@ public class MainViewMobile extends MainView {
ConfigurableFilterDataProvider<ClubEvent, Void, SerializablePredicate<ClubEvent>> eventDataProvider; ConfigurableFilterDataProvider<ClubEvent, Void, SerializablePredicate<ClubEvent>> eventDataProvider;
private ApplicationContext context;
public MainViewMobile(ApplicationContext context, PersonBusiness personDao, GroupDao groupDao, public MainViewMobile(ApplicationContext context, PersonBusiness personDao, GroupDao groupDao,
EventBusiness eventBusiness, EventBusiness eventBusiness,
SecurityVerifier securityGroupVerifier) { SecurityVerifier securityGroupVerifier) {
super(groupDao, eventBusiness, personDao, securityGroupVerifier); super(context, groupDao, eventBusiness, personDao, securityGroupVerifier);
this.context = context;
} }
@Override @Override
@ -57,8 +54,7 @@ public class MainViewMobile extends MainView {
return; return;
} }
head = new HeadView(context, navigator, component -> showDateTimeDialog(component, "Startdatum"), head = new HeadView(securityVerifier);
component -> showDateTimeDialog(component, "Endedatum"), new ClubEventProvider(), securityVerifier);
head.setWidth("100%"); head.setWidth("100%");
head.updateLoggedinPerson(); head.updateLoggedinPerson();
@ -115,6 +111,16 @@ public class MainViewMobile extends MainView {
addComponent(personGrid); addComponent(personGrid);
} }
@Override
public Supplier<ZonedDateTime> startDateSupplier() {
return () -> showDateTimeDialog(this.head, "Startdatum");
}
@Override
public Supplier<ZonedDateTime> endDateSupplier() {
return () -> showDateTimeDialog(this.head, "Endedatum");
}
private ZonedDateTime showDateTimeDialog(Component source, String caption) { private ZonedDateTime showDateTimeDialog(Component source, String caption) {
Window window = new Window(); Window window = new Window();
window.setCaption(caption); window.setCaption(caption);

@ -20,20 +20,30 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonEditDetails; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonEditDetails;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.ClubhelperMenuBar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
public class PersonEditView extends VerticalLayout implements View { public class PersonEditView extends VerticalLayout implements View {
private static final long serialVersionUID = 1770993670570422036L; private static final long serialVersionUID = 1770993670570422036L;
private ClubhelperMenuBar menuBar;
private PersonGrid personGrid; private PersonGrid personGrid;
private PersonEditDetails personDetails; private PersonEditDetails personDetails;
private Navigator navigator; private Navigator navigator;
public PersonEditView(GroupDao groupDao, PersonBusiness personDao, boolean horizontalLayout) { private MenuItemStateFactory menuStateFactory;
setMargin(true);
public PersonEditView(GroupDao groupDao, PersonBusiness personDao, ClubhelperMenuBar menuBar,
MenuItemStateFactory menuStateFactory,
boolean horizontalLayout) {
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();
@ -54,9 +64,9 @@ public class PersonEditView extends VerticalLayout implements View {
addPerson.addClickListener(ev -> addPerson()); addPerson.addClickListener(ev -> addPerson());
addComponent(addPerson); addComponent(addPerson);
Button backButton = new Button("Zurück"); // Button backButton = new Button("Zurück");
backButton.addClickListener(ev -> navigator.navigateTo(ClubhelperViews.MainView.name())); // backButton.addClickListener(ev -> navigator.navigateTo(ClubhelperViews.MainView.name()));
addComponent(backButton); // addComponent(backButton);
} }
public HorizontalLayout createHorizontalLayout() { public HorizontalLayout createHorizontalLayout() {
@ -121,6 +131,7 @@ public class PersonEditView extends VerticalLayout implements View {
@Override @Override
public void enter(ViewChangeEvent event) { public void enter(ViewChangeEvent event) {
this.navigator = event.getNavigator(); this.navigator = event.getNavigator();
menuBar.applyState(menuStateFactory.currentState());
} }
} }

@ -11,7 +11,6 @@ import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@ -56,6 +57,7 @@ class YearlyCalendarCreatorTest {
} }
@Test @Test
@Disabled
void testJrxmlResource() { void testJrxmlResource() {
creator = new YearlyCalendarCreator(2019, values); creator = new YearlyCalendarCreator(2019, values);
InputStream jrxml = creator.jrxmlResource(); InputStream jrxml = creator.jrxmlResource();

@ -5,7 +5,6 @@ import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;

Loading…
Cancel
Save