use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebWindowManager method createNewTabLayout.
protected Layout createNewTabLayout(final Window window, final boolean multipleOpen, WindowBreadCrumbs breadCrumbs, Component... additionalComponents) {
Layout layout = new CssLayout();
layout.setPrimaryStyleName("c-app-window-wrap");
layout.setSizeFull();
layout.addComponent(breadCrumbs);
if (additionalComponents != null) {
for (final Component c : additionalComponents) {
layout.addComponent(c);
}
}
final Component component = WebComponentsHelper.getComposition(window);
component.setSizeFull();
layout.addComponent(component);
WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
if (workArea.getMode() == Mode.TABBED) {
layout.addStyleName("c-app-tabbed-window");
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId;
Integer hashCode = getWindowHashCode(window);
ComponentContainer tab = null;
if (hashCode != null) {
tab = findTab(hashCode);
}
if (tab != null && !multipleOpen) {
tabSheet.replaceComponent(tab, layout);
tabSheet.removeComponent(tab);
tabs.put(layout, breadCrumbs);
tabId = tabSheet.getTab(layout);
} else {
tabs.put(layout, breadCrumbs);
tabId = "tab_" + uuidSource.createUuid();
tabSheet.addTab(layout, tabId);
if (ui.isTestMode()) {
String id = "tab_" + window.getId();
tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
tabSheet.setTabCubaId(tabId, id);
}
}
String windowContentSwitchMode = window.getContentSwitchMode().name();
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
String formattedCaption = formatTabCaption(window.getCaption(), window.getDescription());
tabSheet.setTabCaption(tabId, formattedCaption);
String formattedDescription = formatTabDescription(window.getCaption(), window.getDescription());
if (!Objects.equals(formattedCaption, formattedDescription)) {
tabSheet.setTabDescription(tabId, formattedDescription);
} else {
tabSheet.setTabDescription(tabId, null);
}
tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
tabSheet.setTabClosable(tabId, true);
tabSheet.setTabCloseHandler(layout, (targetTabSheet, tabContent) -> {
// noinspection SuspiciousMethodCalls
WindowBreadCrumbs breadCrumbs1 = tabs.get(tabContent);
if (!canWindowBeClosed(breadCrumbs1.getCurrentWindow())) {
return;
}
Runnable closeTask = new TabCloseTask(breadCrumbs1);
closeTask.run();
// it is needed to force redraw tabsheet if it has a lot of tabs and part of them are hidden
targetTabSheet.markAsDirty();
});
tabSheet.setSelectedTab(layout);
} else {
tabs.put(layout, breadCrumbs);
layout.addStyleName("c-app-single-window");
VerticalLayout mainLayout = workArea.getSingleWindowContainer();
mainLayout.removeAllComponents();
mainLayout.addComponent(layout);
}
return layout;
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebWindowManager method createWindowBreadCrumbs.
protected WindowBreadCrumbs createWindowBreadCrumbs(Window window) {
WebAppWorkArea appWorkArea = getConfiguredWorkArea(createWorkAreaContext(window));
WindowBreadCrumbs windowBreadCrumbs = new WindowBreadCrumbs(appWorkArea);
boolean showBreadCrumbs = webConfig.getShowBreadCrumbs() || Mode.SINGLE == appWorkArea.getMode();
windowBreadCrumbs.setVisible(showBreadCrumbs);
stacks.put(windowBreadCrumbs, new Stack<>());
return windowBreadCrumbs;
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method removeThisTabWindow.
protected void removeThisTabWindow(Screen screen) {
TabWindow window = (TabWindow) screen.getWindow();
com.vaadin.ui.Component windowComposition = window.unwrapComposition(com.vaadin.ui.Component.class);
TabWindowContainer windowContainer = (TabWindowContainer) windowComposition.getParent();
windowContainer.removeComponent(windowComposition);
WindowBreadCrumbs breadCrumbs = windowContainer.getBreadCrumbs();
breadCrumbs.removeWindow();
Window currentWindow = breadCrumbs.getCurrentWindow();
com.vaadin.ui.Component currentWindowComposition = currentWindow.unwrapComposition(com.vaadin.ui.Component.class);
windowContainer.addComponent(currentWindowComposition);
WebAppWorkArea workArea = getConfiguredWorkArea();
if (workArea.getMode() == Mode.TABBED) {
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = tabSheet.getTab(windowContainer);
TabWindow tabWindow = (TabWindow) currentWindow;
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(currentWindow.getIcon()));
tabSheet.setTabClosable(tabId, currentWindow.isCloseable());
ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(tabWindow.getContentSwitchMode().name());
tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
}
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method checkOpened.
protected void checkOpened(Screen screen) {
WebAppWorkArea workArea = getConfiguredWorkAreaOrNull();
if (workArea == null) {
return;
}
// In case of 'managedMainTabSheetMode = UNLOAD_TABS',
// inactive screens are detached, so we need to skip this check
HasTabSheetBehaviour behaviour = workArea.getTabbedWindowContainer();
if (behaviour instanceof CubaManagedTabSheet && ((CubaManagedTabSheet) behaviour).getMode() == 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 com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method createNewTabLayout.
protected void createNewTabLayout(Screen screen) {
WindowBreadCrumbs breadCrumbs = createWindowBreadCrumbs(screen);
breadCrumbs.setWindowNavigateHandler(this::handleWindowBreadCrumbsNavigate);
breadCrumbs.addWindow(screen.getWindow());
WebWindow webWindow = (WebWindow) screen.getWindow();
webWindow.setResolvedState(createOrUpdateState(webWindow.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
TabWindowContainer windowContainer = new TabWindowContainerImpl();
windowContainer.setPrimaryStyleName("c-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);
WebAppWorkArea workArea = getConfiguredWorkArea();
if (workArea.getMode() == Mode.TABBED) {
windowContainer.addStyleName("c-app-tabbed-window");
TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
String tabId = "tab_" + uuidSource.createUuid();
tabSheet.addTab(windowContainer, tabId);
if (ui.isTestMode()) {
String id = "tab_" + window.getId();
tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
tabSheet.setTabCubaId(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("c-app-single-window");
CubaSingleModeContainer 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(AppWorkArea.State.WINDOW_CONTAINER);
}
mainLayout.setWindowContainer(windowContainer);
}
}
Aggregations