use of com.haulmont.cuba.gui.screen.Screen 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.gui.screen.Screen in project cuba by cuba-platform.
the class WebScreens method openEditor.
@SuppressWarnings({ "deprecation", "IncorrectCreateGuiComponent", "unchecked" })
@Override
public Window.Editor openEditor(WindowInfo windowInfo, Entity item, OpenType openType, @Nullable Map<String, Object> params, Datasource parentDs) {
params = createParametersMap(windowInfo, params);
params.put(WindowParams.ITEM.name(), item);
MapScreenOptions options = new MapScreenOptions(params);
Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
applyOpenTypeParameters(screen.getWindow(), openType);
EditorScreen editorScreen = (EditorScreen) screen;
if (editorScreen instanceof AbstractEditor) {
((AbstractEditor) editorScreen).setParentDs(parentDs);
}
editorScreen.setEntityToEdit(item);
show(screen);
return screen instanceof Window.Editor ? (Window.Editor) screen : new ScreenEditorWrapper(screen);
}
use of com.haulmont.cuba.gui.screen.Screen 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.gui.screen.Screen in project cuba by cuba-platform.
the class WebScreens method getConfiguredWorkAreaOrNull.
@Nullable
protected WebAppWorkArea getConfiguredWorkAreaOrNull() {
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;
}
}
return null;
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class WebScreens method removeAll.
@Override
public void removeAll() {
List<Screen> dialogScreens = getDialogScreensStream().collect(Collectors.toList());
for (Screen dialogScreen : dialogScreens) {
remove(dialogScreen);
}
WebAppWorkArea workArea = getConfiguredWorkAreaOrNull();
if (workArea != null) {
Collection<WindowStack> workAreaStacks = getWorkAreaStacks(workArea);
for (WindowStack workAreaStack : workAreaStacks) {
Collection<Screen> tabScreens = workAreaStack.getBreadcrumbs();
for (Screen screen : tabScreens) {
remove(screen);
}
}
}
}
Aggregations