use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method getConfiguredWorkArea.
/**
* @return workarea instance of the root screen
* @throws IllegalStateException if there is no root screen or root screen does not have {@link AppWorkArea}
*/
@Nonnull
protected WebAppWorkArea getConfiguredWorkArea() {
RootWindow topLevelWindow = ui.getTopLevelWindow();
if (topLevelWindow == null) {
throw new IllegalStateException("There is no root screen opened");
}
Screen controller = topLevelWindow.getFrameOwner();
if (controller instanceof HasWorkArea) {
AppWorkArea workArea = ((HasWorkArea) controller).getWorkArea();
if (workArea != null) {
return (WebAppWorkArea) workArea;
}
}
throw new IllegalStateException("RootWindow does not have any configured work area");
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method showNewTabWindow.
protected void showNewTabWindow(Screen screen) {
WebAppWorkArea workArea = getConfiguredWorkArea();
workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
// work with new window
createNewTabLayout(screen);
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method showFromNavigation.
@Override
public OperationResult showFromNavigation(Screen screen) {
LaunchMode launchMode = screen.getWindow().getContext().getLaunchMode();
if (launchMode == OpenMode.NEW_TAB || launchMode == OpenMode.NEW_WINDOW) {
WebAppWorkArea 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);
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method prepareScreenOpenDetails.
protected ScreenOpenDetails prepareScreenOpenDetails(Class<? extends Screen> resolvedScreenClass, @Nullable Element element, LaunchMode requiredLaunchMode) {
if (!(requiredLaunchMode instanceof OpenMode)) {
throw new UnsupportedOperationException("Unsupported LaunchMode " + requiredLaunchMode);
}
// check if we need to change launchMode to DIALOG
boolean forceDialog = false;
OpenMode launchMode = (OpenMode) requiredLaunchMode;
if (element != null && element.element("dialogMode") != null) {
String forceDialogAttr = element.element("dialogMode").attributeValue("forceDialog");
if (StringUtils.isNotEmpty(forceDialogAttr) && Boolean.parseBoolean(forceDialogAttr)) {
launchMode = OpenMode.DIALOG;
}
}
DialogMode dialogMode = resolvedScreenClass.getAnnotation(DialogMode.class);
if (dialogMode != null && dialogMode.forceDialog()) {
launchMode = OpenMode.DIALOG;
}
if (launchMode != OpenMode.DIALOG && launchMode != OpenMode.ROOT) {
if (hasModalDialogWindow()) {
launchMode = OpenMode.DIALOG;
forceDialog = true;
}
}
if (launchMode == OpenMode.THIS_TAB) {
WebAppWorkArea workArea = getConfiguredWorkArea();
switch(workArea.getMode()) {
case SINGLE:
if (workArea.getSingleWindowContainer().getWindowContainer() == null) {
launchMode = OpenMode.NEW_TAB;
}
break;
case TABBED:
TabSheetBehaviour tabSheetBehaviour = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
if (tabSheetBehaviour.getComponentCount() == 0) {
launchMode = OpenMode.NEW_TAB;
}
break;
default:
throw new UnsupportedOperationException("Unsupported AppWorkArea mode");
}
} else if (launchMode == OpenMode.NEW_WINDOW) {
launchMode = OpenMode.NEW_TAB;
}
return new ScreenOpenDetails(forceDialog, launchMode);
}
use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.
the class WebScreens method showDialogWindow.
protected void showDialogWindow(Screen screen) {
DialogWindow window = (DialogWindow) screen.getWindow();
WebAppWorkArea workArea = getConfiguredWorkAreaOrNull();
if (workArea != null) {
WebWindow webWindow = (WebWindow) screen.getWindow();
webWindow.setResolvedState(createOrUpdateState(webWindow.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
}
window.withUnwrappedComposition(CubaWindow.class, vWindow -> {
vWindow.setErrorHandler(ui);
String cubaId = "dialog_" + window.getId();
if (ui.isTestMode()) {
vWindow.setCubaId(cubaId);
}
if (ui.isPerformanceTestMode()) {
vWindow.setId(ui.getTestIdManager().getTestId(cubaId));
}
if (hasModalWindow()) {
// force modal
window.setModal(true);
}
ui.addWindow(vWindow);
});
}
Aggregations