Hello,
in our application we have a dashboard screen that should always be opened as the first tab and should remain open. When you try to close it, this Dashboard Screen should only refresh itself. Also, the dashboard should not be able to be opened twice, but the existing tab should be opened and refreshed.
Currently I use the following solution for this, but it has the disadvantage that I can’t close all tabs (except the dashboard) via the context menu:
Main screen:
@Subscribe
public void onInit(InitEvent event) {
// Open Dashboard, if alle screens are closed
final SideMenu.MenuItem dashboardMenuItem = sideMenu.getMenuItem("agov_Dashboard");
if (workArea instanceof WebAppWorkArea && dashboardMenuItem != null) {
workArea.addStateChangeListener(stateChangeEvent -> {
if (stateChangeEvent.getState() == INITIAL_LAYOUT) {
screenBuilders.screen(this)
.withScreenClass(Dashboard.class)
.show();
}
});
// Prevent to open the dashboard twice
final Consumer<SideMenu.MenuItem> dashboardMenuItemCommand = dashboardMenuItem.getCommand();
dashboardMenuItem.setCommand(menuItem -> {
screens.getOpenedScreens().getWorkAreaStacks().stream()
.filter(windowStack -> windowStack.getBreadcrumbs().stream().anyMatch(screen -> screen instanceof Dashboard))
.peek(Screens.WindowStack::select)
.flatMap(windowStack -> windowStack.getBreadcrumbs().stream())
.filter(screen -> !(screen instanceof Dashboard))
.forEach(Screen::closeWithDefaultAction);
if (screens.getOpenedScreens().getWorkAreaScreens().stream().noneMatch(screen -> screen instanceof Dashboard)) {
dashboardMenuItemCommand.accept(dashboardMenuItem);
}
});
}
}
Dashboard screen:
@Subscribe
public void onBeforeClose(BeforeCloseEvent event) {
refresh();
event.preventWindowClose();
}
Does anyone have a better solution?
Greetings
Andreas