use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.
the class ScreensImpl method createNewTabLayout.
protected void createNewTabLayout(Screen screen) {
WindowBreadCrumbs breadCrumbs = createWindowBreadCrumbs(screen);
breadCrumbs.setWindowNavigateHandler(this::handleWindowBreadCrumbsNavigate);
breadCrumbs.addWindow(screen.getWindow());
WindowImpl windowImpl = (WindowImpl) screen.getWindow();
windowImpl.setResolvedState(createOrUpdateState(windowImpl.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
TabWindowContainer windowContainer = new TabWindowContainerImpl();
windowContainer.setPrimaryStyleName("jmix-app-window-wrap");
windowContainer.setSizeFull();
windowContainer.setBreadCrumbs(breadCrumbs);
windowContainer.addComponent(breadCrumbs);
Window window = screen.getWindow();
com.vaadin.ui.Component windowComposition = window.unwrapComposition(com.vaadin.ui.Component.class);
windowContainer.addComponent(windowComposition);
AppWorkAreaImpl workArea = getConfiguredWorkArea();
if (workArea.getMode() == Mode.TABBED) {
windowContainer.addStyleName("jmix-app-tabbed-window");
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = "tab_" + UuidProvider.createUuid();
tabSheet.addTab(windowContainer, tabId);
if (ui.isTestMode()) {
String id = "tab_" + window.getId();
tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
tabSheet.setTabJmixId(tabId, id);
}
TabWindow tabWindow = (TabWindow) window;
String windowContentSwitchMode = tabWindow.getContentSwitchMode().name();
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
String formattedCaption = tabWindow.formatTabCaption();
String formattedDescription = tabWindow.formatTabDescription();
tabSheet.setTabCaption(tabId, formattedCaption);
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
tabSheet.setTabClosable(tabId, window.isCloseable());
tabSheet.setTabCloseHandler(windowContainer, this::handleTabWindowClose);
tabSheet.setSelectedTab(windowContainer);
} else {
windowContainer.addStyleName("jmix-app-single-window");
JmixSingleModeContainer mainLayout = workArea.getSingleWindowContainer();
if (mainLayout.getWindowContainer() != null) {
// remove all windows from single stack
TabWindowContainer oldWindowContainer = (TabWindowContainer) mainLayout.getWindowContainer();
Deque<Window> windows = oldWindowContainer.getBreadCrumbs().getWindows();
Iterator<Window> iterator = windows.descendingIterator();
while (iterator.hasNext()) {
Window oldWindow = iterator.next();
remove(oldWindow.getFrameOwner());
}
// after last window closed we need to switch back to window container
workArea.switchTo(State.WINDOW_CONTAINER);
}
mainLayout.setWindowContainer(windowContainer);
}
}
use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.
the class ParamsNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState)) {
return false;
}
Screen screen = urlChangeHandler.getActiveScreen();
if (screen == null) {
log.debug("Unable to find a screen for state: '{}", requestedState);
return false;
}
Map<String, String> params = requestedState.getParams() != null ? requestedState.getParams() : Collections.emptyMap();
WindowImpl window = (WindowImpl) screen.getWindow();
NavigationState resolvedState = window.getResolvedState();
if (resolvedState == null || params.equals(resolvedState.getParams())) {
return false;
}
NavigationState newState = new NavigationState(resolvedState.getRoot(), resolvedState.getStateMark(), resolvedState.getNestedRoute(), params);
window.setResolvedState(newState);
UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, params));
return true;
}
use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.
the class RootNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState)) {
urlChangeHandler.revertNavigationState();
return false;
}
if (!rootChanged(requestedState, ui)) {
return false;
}
String rootRoute = requestedState.getRoot();
WindowInfo windowInfo = windowConfig.findWindowInfoByRoute(rootRoute);
if (windowInfo == null) {
log.info("No registered screen found for route: '{}'", rootRoute);
urlChangeHandler.revertNavigationState();
handle404(rootRoute, ui);
return true;
}
if (urlChangeHandler.shouldRedirect(windowInfo)) {
urlChangeHandler.redirect(requestedState);
return true;
}
if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
return true;
}
Screen screen = ui.getScreens().create(windowInfo.getId(), OpenMode.ROOT);
boolean hasNestedRoute = StringUtils.isNotEmpty(requestedState.getNestedRoute());
if (!hasNestedRoute && MapUtils.isNotEmpty(requestedState.getParams())) {
UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, requestedState.getParams()));
((WindowImpl) screen.getWindow()).setResolvedState(requestedState);
}
screen.show();
return !hasNestedRoute;
}
use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.
the class UrlChangeHandler method restoreState.
public void restoreState() {
if (notSuitableMode()) {
log.debug("UrlChangeHandler is disabled for '{}' URL handling mode", uiProperties.getUrlHandlingMode());
return;
}
NavigationState currentState = urlTools.parseState(ui.getPage().getUriFragment());
if (currentState == null || currentState == NavigationState.EMPTY) {
RootWindow topLevelWindow = ui.getTopLevelWindow();
if (topLevelWindow instanceof WindowImpl) {
NavigationState topScreenState = ((WindowImpl) topLevelWindow).getResolvedState();
urlTools.replaceState(topScreenState.asRoute(), ui);
}
}
}
use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.
the class AppUI method restoreRouteState.
/*
* During AppUI initialization process the initial URL is replaced
* with the created Root Window route. In case the requested state
* contains parameters for the root window, we need to restore it
* to keep in sync the browser URL and params that can be obtained
* from UrlParamsChangedEvent
*/
protected void restoreRouteState(NavigationState requestedState) {
// Check that the requested state doesn't contain nested route
// that will be handled by navigation handlers and that there
// are parameters to restore in the browser URL.
Map<String, String> requestedParams = requestedState.getParams();
if (!Strings.isNullOrEmpty(requestedState.getNestedRoute()) || MapUtils.isEmpty(requestedParams)) {
return;
}
RootWindow topLevelWindow = getTopLevelWindow();
if (topLevelWindow instanceof WindowImpl) {
Screen frameOwner = topLevelWindow.getFrameOwner();
NavigationState resolvedState = ((WindowImpl) topLevelWindow).getResolvedState();
if (resolvedState == null) {
return;
}
// Check that the actual Root Window and the requested Root Window is the same
if (Objects.equals(requestedState.getRoot(), resolvedState.getRoot())) {
urlRouting.replaceState(frameOwner, requestedParams);
// Because of usage of 'urlRouting.replaceState' UrlParamsChangedEvent
// won't be fired for the Root Window by ParamsNavigationHandler, hence
// we need to do it here.
UiControllerUtils.fireEvent(frameOwner, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(frameOwner, requestedParams));
}
}
}
Aggregations