|
|
|
@ -1,6 +1,8 @@ |
|
|
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu; |
|
|
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.time.ZonedDateTime; |
|
|
|
import java.time.ZonedDateTime; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.function.Supplier; |
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
|
|
@ -8,16 +10,29 @@ import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
import com.vaadin.icons.VaadinIcons; |
|
|
|
import com.vaadin.icons.VaadinIcons; |
|
|
|
import com.vaadin.navigator.View; |
|
|
|
import com.vaadin.navigator.View; |
|
|
|
|
|
|
|
import com.vaadin.shared.ui.ContentMode; |
|
|
|
|
|
|
|
import com.vaadin.ui.Label; |
|
|
|
import com.vaadin.ui.MenuBar.MenuItem; |
|
|
|
import com.vaadin.ui.MenuBar.MenuItem; |
|
|
|
|
|
|
|
import com.vaadin.ui.Notification; |
|
|
|
|
|
|
|
import com.vaadin.ui.UI; |
|
|
|
|
|
|
|
import com.vaadin.ui.VerticalLayout; |
|
|
|
|
|
|
|
import com.vaadin.ui.Window; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import de.kreth.googleconnectors.calendar.CalendarAdapter; |
|
|
|
|
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; |
|
|
|
|
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung.EventMeldung; |
|
|
|
|
|
|
|
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.commands.ClubCommand; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand; |
|
|
|
|
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.CreateMeldungCommand; |
|
|
|
|
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.DeleteEventCommand; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ExportCalendarMonthCommand; |
|
|
|
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.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.LogoutCommand; |
|
|
|
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.ClubEventProvider; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.ClubEventProvider; |
|
|
|
|
|
|
|
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.ClubhelperNavigation.ClubNavigator; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperViews; |
|
|
|
@ -41,26 +56,83 @@ class LoggedinMenuitemState implements MenuItemState { |
|
|
|
|
|
|
|
|
|
|
|
private BiConsumer<String, JasperPrint> printConsumer; |
|
|
|
private BiConsumer<String, JasperPrint> printConsumer; |
|
|
|
|
|
|
|
|
|
|
|
public LoggedinMenuitemState(ApplicationContext context, Supplier<ZonedDateTime> startProvider, |
|
|
|
private MenuItem openPersonMenuItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MenuItem calendarMenuItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UI ui; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MenuItem eventDetailItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EventBusiness eventBusiness; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MenuItem createMeldungMenuItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MenuItem deleteMenuItem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LoggedinMenuitemState(ApplicationContext context, UI ui, Supplier<ZonedDateTime> startProvider, |
|
|
|
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) { |
|
|
|
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.navigator = context.getBean(ClubhelperNavigation.class); |
|
|
|
this.ui = ui; |
|
|
|
this.context = context; |
|
|
|
this.context = context; |
|
|
|
this.dataProvider = context.getBean(ClubEventProvider.class); |
|
|
|
|
|
|
|
this.startProvider = startProvider; |
|
|
|
this.startProvider = startProvider; |
|
|
|
this.endProvider = endProvider; |
|
|
|
this.endProvider = endProvider; |
|
|
|
this.printConsumer = printConsumer; |
|
|
|
this.printConsumer = printConsumer; |
|
|
|
|
|
|
|
this.navigator = context.getBean(ClubhelperNavigation.class); |
|
|
|
|
|
|
|
this.dataProvider = context.getBean(ClubEventProvider.class); |
|
|
|
|
|
|
|
this.eventBusiness = context.getBean(EventBusiness.class); |
|
|
|
|
|
|
|
navigator.add(ev -> setSelectedMenuItem(ev.getNewView())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
View current = navigator.getNavigator().getCurrentView(); |
|
|
|
|
|
|
|
ClubhelperViews view = ClubhelperViews.byView(current); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventBusiness.add(ev -> setSelectedMenuItem(view)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void applyMenuStates(ClubhelperMenuBar menuBar) { |
|
|
|
public void applyMenuStates(ClubhelperMenuBar menuBar) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menuBar.getAllMainMenus().forEach(m -> m.setVisible(false)); |
|
|
|
|
|
|
|
|
|
|
|
MenuItem fileMenuItem = menuBar.getFileMenuItem(); |
|
|
|
MenuItem fileMenuItem = menuBar.getFileMenuItem(); |
|
|
|
fileMenuItem.setVisible(true); |
|
|
|
fileMenuItem.setVisible(true); |
|
|
|
CommandWrapper logout = new CommandWrapper(new LogoutCommand(navigator2, securityVerifier)); |
|
|
|
CommandWrapper logout = new CommandWrapper(new LogoutCommand(navigator2, securityVerifier)); |
|
|
|
fileMenuItem.addItem(logout.getLabel(), logout); |
|
|
|
fileMenuItem.addItem(logout.getLabel(), logout); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareEditMenu(menuBar); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareViewMenu(menuBar); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menuBar.getSettingsItem().setVisible(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
View current = navigator.getNavigator().getCurrentView(); |
|
|
|
|
|
|
|
ClubhelperViews view = ClubhelperViews.byView(current); |
|
|
|
|
|
|
|
setSelectedMenuItem(view); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void prepareViewMenu(ClubhelperMenuBar menuBar) { |
|
|
|
|
|
|
|
MenuItem viewMenu = menuBar.getViewMenuItem(); |
|
|
|
|
|
|
|
viewMenu.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandWrapper calendarView = new CommandWrapper( |
|
|
|
|
|
|
|
new SwitchViewCommand(context, "Hauptansicht", VaadinIcons.CALENDAR, ClubhelperViews.MainView)); |
|
|
|
|
|
|
|
calendarMenuItem = viewMenu.addItem(calendarView.getLabel(), calendarView); |
|
|
|
|
|
|
|
calendarMenuItem.setCheckable(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandWrapper openPersonEditor = new CommandWrapper( |
|
|
|
|
|
|
|
new SwitchViewCommand(context, "Personen verwalten", VaadinIcons.EDIT, ClubhelperViews.PersonEditView)); |
|
|
|
|
|
|
|
openPersonMenuItem = viewMenu.addItem(openPersonEditor.getLabel(), openPersonEditor); |
|
|
|
|
|
|
|
openPersonMenuItem.setCheckable(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandWrapper detailViewCommand = new CommandWrapper( |
|
|
|
|
|
|
|
new SwitchViewCommand(context, "Veranstaltung Detail", null, ClubhelperViews.EventDetails)); |
|
|
|
|
|
|
|
eventDetailItem = viewMenu.addItem(detailViewCommand.getLabel(), detailViewCommand); |
|
|
|
|
|
|
|
eventDetailItem.setCheckable(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void prepareEditMenu(ClubhelperMenuBar menuBar) { |
|
|
|
MenuItem editMenu = menuBar.getEditMenuItem(); |
|
|
|
MenuItem editMenu = menuBar.getEditMenuItem(); |
|
|
|
|
|
|
|
editMenu.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
CommandWrapper exportCalendarMonthCommand = new CommandWrapper( |
|
|
|
CommandWrapper exportCalendarMonthCommand = new CommandWrapper( |
|
|
|
new ExportCalendarMonthCommand(startProvider, endProvider, dataProvider, printConsumer)); |
|
|
|
new ExportCalendarMonthCommand(startProvider, endProvider, dataProvider, printConsumer)); |
|
|
|
@ -71,24 +143,89 @@ class LoggedinMenuitemState implements MenuItemState { |
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
|
|
MenuItem viewMenu = menuBar.getViewMenuItem(); |
|
|
|
CreateMeldungCommand createMeldungCommand = new CreateMeldungCommand(context, this::show); |
|
|
|
viewMenu.setVisible(true); |
|
|
|
createMeldungMenuItem = editMenu.addItem(createMeldungCommand.getLabel(), |
|
|
|
CommandWrapper openPersonEditor = new CommandWrapper( |
|
|
|
new CommandWrapper(createMeldungCommand)); |
|
|
|
new SwitchViewCommand(context, "Personen verwalten", VaadinIcons.EDIT, ClubhelperViews.PersonEditView)); |
|
|
|
|
|
|
|
MenuItem openPersonMenuItem = viewMenu.addItem(openPersonEditor.getLabel(), openPersonEditor); |
|
|
|
CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent)); |
|
|
|
openPersonMenuItem.setCheckable(true); |
|
|
|
deleteMenuItem = editMenu.addItem(deleeteEvent.getLabel(), deleeteEvent); |
|
|
|
CommandWrapper calendarView = new CommandWrapper( |
|
|
|
} |
|
|
|
new SwitchViewCommand(context, "Hauptansicht", VaadinIcons.CALENDAR, ClubhelperViews.MainView)); |
|
|
|
|
|
|
|
MenuItem calendarMenuItem = viewMenu.addItem(calendarView.getLabel(), calendarView); |
|
|
|
protected void setSelectedMenuItem(ClubhelperViews view) { |
|
|
|
calendarMenuItem.setCheckable(true); |
|
|
|
|
|
|
|
View current = navigator.getNavigator().getCurrentView(); |
|
|
|
if (eventBusiness.getCurrent() != null) { |
|
|
|
ClubhelperViews view = ClubhelperViews.byView(current); |
|
|
|
createMeldungMenuItem.setEnabled(true); |
|
|
|
|
|
|
|
eventDetailItem.setVisible(true); |
|
|
|
|
|
|
|
deleteMenuItem.setEnabled(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
createMeldungMenuItem.setEnabled(false); |
|
|
|
|
|
|
|
eventDetailItem.setVisible(false); |
|
|
|
|
|
|
|
deleteMenuItem.setEnabled(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (MenuItem item : Arrays.asList(openPersonMenuItem, calendarMenuItem, eventDetailItem)) { |
|
|
|
|
|
|
|
item.setChecked(false); |
|
|
|
|
|
|
|
item.setEnabled(true); |
|
|
|
|
|
|
|
} |
|
|
|
if (ClubhelperViews.PersonEditView == view) { |
|
|
|
if (ClubhelperViews.PersonEditView == view) { |
|
|
|
openPersonMenuItem.setChecked(true); |
|
|
|
openPersonMenuItem.setChecked(true); |
|
|
|
|
|
|
|
openPersonMenuItem.setEnabled(false); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else if (ClubhelperViews.MainView == view) { |
|
|
|
calendarMenuItem.setChecked(true); |
|
|
|
calendarMenuItem.setChecked(true); |
|
|
|
|
|
|
|
calendarMenuItem.setEnabled(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (ClubhelperViews.EventDetails.equals(view)) { |
|
|
|
|
|
|
|
eventDetailItem.setChecked(true); |
|
|
|
|
|
|
|
eventDetailItem.setEnabled(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void show(EventMeldung createMeldung) { |
|
|
|
|
|
|
|
VerticalLayout content = new VerticalLayout(); |
|
|
|
|
|
|
|
content.addComponent(new Label(createMeldung.toString(), ContentMode.PREFORMATTED)); |
|
|
|
|
|
|
|
Window dlg = new Window("Meldung für " + eventBusiness.getCurrent().getCaption()); |
|
|
|
|
|
|
|
dlg.setContent(content); |
|
|
|
|
|
|
|
dlg.center(); |
|
|
|
|
|
|
|
ui.addWindow(dlg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteEvent() { |
|
|
|
|
|
|
|
ClubEvent bean = eventBusiness.getCurrent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConfirmDialog dlg = ConfirmDialog.builder().setCaption("Löschen bestätigen!").setMessage("Wollen Sie Termin \"" |
|
|
|
|
|
|
|
+ bean.getCaption() + "\" vom " + bean.getStart() + "\" bis " + bean.getEnd() |
|
|
|
|
|
|
|
+ " wirklich löschen? Dieser Vorgang kann nicht rückgängig gemacht werden und betrifft auch den Online Google Calendar.") |
|
|
|
|
|
|
|
.setResultHandler(btn -> { |
|
|
|
|
|
|
|
if (btn == ConfirmDialog.Buttons.YES) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String host = ui.getPage().getLocation().getHost(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CalendarAdapter calendarAdapter = context.getBean(CalendarAdapter.class); |
|
|
|
|
|
|
|
if (calendarAdapter.deleteEvent(host, bean.getOrganizerDisplayName(), bean.getId())) { |
|
|
|
|
|
|
|
eventBusiness.delete(bean); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
View current = navigator.getNavigator().getCurrentView(); |
|
|
|
|
|
|
|
ClubhelperViews view = ClubhelperViews.byView(current); |
|
|
|
|
|
|
|
if (ClubhelperViews.EventDetails.equals(view)) { |
|
|
|
|
|
|
|
navigator.getNavigator().back(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
Notification.show("Fehler beim Löschen von " + bean, "Bitte erneut versuchen.", |
|
|
|
|
|
|
|
Notification.Type.ERROR_MESSAGE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (IOException e) { |
|
|
|
|
|
|
|
Notification.show("Fehler beim Löschen von " + bean, e.toString(), |
|
|
|
|
|
|
|
Notification.Type.ERROR_MESSAGE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}).yesCancel().build(); |
|
|
|
|
|
|
|
ui.addWindow(dlg); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|