use of io.jmix.ui.component.impl.AppWorkAreaImpl 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.AppWorkAreaImpl in project jmix by jmix-framework.
the class ScreensImpl method prepareScreenOpenDetails.
protected ScreenOpenDetails prepareScreenOpenDetails(Class<? extends Screen> resolvedScreenClass, @Nullable Element element, OpenMode requiredOpenMode) {
// check if we need to change openMode to DIALOG
boolean forceDialog = false;
OpenMode openMode = requiredOpenMode;
if (element != null && element.element("dialogMode") != null) {
String forceDialogAttr = element.element("dialogMode").attributeValue("forceDialog");
if (StringUtils.isNotEmpty(forceDialogAttr) && Boolean.parseBoolean(forceDialogAttr)) {
openMode = OpenMode.DIALOG;
}
}
DialogMode dialogMode = resolvedScreenClass.getAnnotation(DialogMode.class);
if (dialogMode != null && dialogMode.forceDialog()) {
openMode = OpenMode.DIALOG;
}
if (openMode != OpenMode.DIALOG && openMode != OpenMode.ROOT) {
if (hasModalDialogWindow()) {
openMode = OpenMode.DIALOG;
forceDialog = true;
}
}
if (openMode == OpenMode.THIS_TAB) {
AppWorkAreaImpl workArea = getConfiguredWorkArea();
switch(workArea.getMode()) {
case SINGLE:
if (workArea.getSingleWindowContainer().getWindowContainer() == null) {
openMode = OpenMode.NEW_TAB;
}
break;
case TABBED:
TabSheetBehaviour tabSheetBehaviour = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheetBehaviour.getComponentCount() == 0) {
openMode = OpenMode.NEW_TAB;
}
break;
default:
throw new UnsupportedOperationException("Unsupported AppWorkArea mode");
}
} else if (openMode == OpenMode.NEW_WINDOW) {
openMode = OpenMode.NEW_TAB;
}
return new ScreenOpenDetails(forceDialog, openMode);
}
use of io.jmix.ui.component.impl.AppWorkAreaImpl in project jmix by jmix-framework.
the class ScreensImpl method checkOpened.
protected void checkOpened(Screen screen) {
if (getConfiguredWorkAreaOrNull() == null) {
return;
}
// In case of 'managedMainTabSheetMode = UNLOAD_TABS',
// inactive screens are detached, so we need to skip this check
AppWorkAreaImpl workArea = getConfiguredWorkArea();
HasTabSheetBehaviour behaviour = workArea.getTabbedWindowContainer();
if (behaviour instanceof JmixManagedTabSheet && ((JmixManagedTabSheet) behaviour).getMode() == JmixManagedTabSheet.Mode.UNLOAD_TABS) {
return;
}
com.vaadin.ui.Component uiComponent = screen.getWindow().unwrapComposition(com.vaadin.ui.Component.class);
if (!uiComponent.isAttached()) {
throw new IllegalStateException("Screen is not opened " + screen.getId());
}
}
use of io.jmix.ui.component.impl.AppWorkAreaImpl in project jmix by jmix-framework.
the class CubaScreens method selectWindowTab.
@Override
public void selectWindowTab(Window window) {
AppWorkAreaImpl workArea = getConfiguredWorkArea();
Collection<WindowStack> workAreaStacks = getWorkAreaStacks(workArea);
Screen screen = window.getFrameOwner();
workAreaStacks.stream().filter(ws -> ws.getBreadcrumbs().contains(screen)).findFirst().ifPresent(WindowStack::select);
}
use of io.jmix.ui.component.impl.AppWorkAreaImpl in project jmix by jmix-framework.
the class ScreensImpl method showFromNavigation.
@Override
public OperationResult showFromNavigation(Screen screen) {
OpenMode openMode = screen.getWindow().getContext().getOpenMode();
if (openMode == OpenMode.NEW_TAB || openMode == OpenMode.NEW_WINDOW) {
AppWorkAreaImpl workArea = getConfiguredWorkArea();
if (workArea.getMode() == Mode.SINGLE) {
Collection<Screen> currentBreadcrumbs = workArea.getCurrentBreadcrumbs();
if (!currentBreadcrumbs.isEmpty()) {
Iterator<Screen> iterator = currentBreadcrumbs.iterator();
OperationResult result = OperationResult.success();
// close all
while (result.getStatus() == OperationResult.Status.SUCCESS && iterator.hasNext()) {
Screen previousScreen = iterator.next();
result = previousScreen.close(NAVIGATION_CLOSE_ACTION);
}
if (result.getStatus() != OperationResult.Status.SUCCESS) {
// if unsaved changes dialog is shown, we can continue later
return result.compose(() -> showFromNavigation(screen));
}
}
} else {
if (isMaxTabCountExceeded(screen)) {
showTooManyOpenTabsMessage();
return OperationResult.fail();
}
if (!UiControllerUtils.isMultipleOpen(screen)) {
Screen sameScreen = getTabbedScreensStacks(workArea).filter(// never close non-top active screens
windowStack -> windowStack.getBreadcrumbs().size() == 1).map(windowStack -> windowStack.getBreadcrumbs().iterator().next()).filter(tabScreen -> isAlreadyOpened(screen, tabScreen)).findFirst().orElse(null);
if (sameScreen != null) {
OperationResult result = sameScreen.close(NAVIGATION_CLOSE_ACTION);
if (result.getStatus() != OperationResult.Status.SUCCESS) {
// if unsaved changes dialog is shown, we can continue later
return result.compose(() -> showFromNavigation(screen));
}
}
}
}
}
return show(screen);
}
Aggregations