parent
1314eb2ce5
commit
7daf22a7e3
@ -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); |
||||
} |
||||
|
||||
} |
||||
@ -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(); |
||||
} |
||||
|
||||
} |
||||
@ -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,9 +1,94 @@ |
||||
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 |
||||
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; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue