Search in sources :

Example 46 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class WebWindowManager method createTopLevelWindow.

public void createTopLevelWindow(WindowInfo windowInfo) {
    ui.beforeTopLevelWindowInit();
    String template = windowInfo.getTemplate();
    Window.TopLevelWindow topLevelWindow;
    Map<String, Object> params = Collections.emptyMap();
    if (template != null) {
        // noinspection unchecked
        topLevelWindow = (Window.TopLevelWindow) createWindow(windowInfo, OpenType.NEW_TAB, params, LayoutLoaderConfig.getWindowLoaders(), true);
    } else {
        Class screenClass = windowInfo.getScreenClass();
        if (screenClass != null) {
            // noinspection unchecked
            topLevelWindow = (Window.TopLevelWindow) createWindowByScreenClass(windowInfo, params);
        } else {
            throw new DevelopmentException("Unable to load top level window");
        }
    }
    // detect work area
    Window windowImpl = ((Window.Wrapper) topLevelWindow).getWrappedWindow();
    if (topLevelWindow instanceof AbstractMainWindow) {
        AbstractMainWindow mainWindow = (AbstractMainWindow) topLevelWindow;
        // bind system UI components to AbstractMainWindow
        ComponentsHelper.walkComponents(windowImpl, component -> {
            if (component instanceof AppWorkArea) {
                mainWindow.setWorkArea((AppWorkArea) component);
            } else if (component instanceof UserIndicator) {
                mainWindow.setUserIndicator((UserIndicator) component);
            } else if (component instanceof FoldersPane) {
                mainWindow.setFoldersPane((FoldersPane) component);
            }
            return false;
        });
    }
    ui.setTopLevelWindow(topLevelWindow);
    // load menu
    ComponentsHelper.walkComponents(windowImpl, component -> {
        if (component instanceof TopLevelWindowAttachListener) {
            ((TopLevelWindowAttachListener) component).topLevelWindowAttached(topLevelWindow);
        }
        return false;
    });
    if (topLevelWindow instanceof Window.HasWorkArea) {
        AppWorkArea workArea = ((Window.HasWorkArea) topLevelWindow).getWorkArea();
        if (workArea != null) {
            workArea.addStateChangeListener(new AppWorkArea.StateChangeListener() {

                @Override
                public void stateChanged(AppWorkArea.State newState) {
                    if (newState == AppWorkArea.State.WINDOW_CONTAINER) {
                        initTabShortcuts();
                        // listener used only once
                        getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).removeStateChangeListener(this);
                    }
                }
            });
        }
    }
    afterShowWindow(topLevelWindow);
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) FoldersPane(com.haulmont.cuba.gui.components.mainwindow.FoldersPane) TopLevelWindowAttachListener(com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) UserIndicator(com.haulmont.cuba.gui.components.mainwindow.UserIndicator)

Example 47 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class WebWindowManager method showWindowThisTab.

protected Component showWindowThisTab(final Window window, final String caption, final String description) {
    getDialogParams().reset();
    WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
    Layout layout;
    if (workArea.getMode() == Mode.TABBED) {
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        layout = (Layout) tabSheet.getSelectedTab();
    } else {
        layout = (Layout) workArea.getSingleWindowContainer().getComponent(0);
    }
    final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
    if (breadCrumbs == null) {
        throw new IllegalStateException("BreadCrumbs not found");
    }
    final Window currentWindow = breadCrumbs.getCurrentWindow();
    Set<Map.Entry<Window, Integer>> set = windows.entrySet();
    boolean pushed = false;
    for (Map.Entry<Window, Integer> entry : set) {
        if (entry.getKey().equals(currentWindow)) {
            windows.remove(currentWindow);
            getStack(breadCrumbs).push(new Pair<>(entry.getKey(), entry.getValue()));
            pushed = true;
            break;
        }
    }
    if (!pushed) {
        getStack(breadCrumbs).push(new Pair<>(currentWindow, null));
    }
    removeFromWindowMap(currentWindow);
    layout.removeComponent(WebComponentsHelper.getComposition(currentWindow));
    final Component component = WebComponentsHelper.getComposition(window);
    component.setSizeFull();
    layout.addComponent(component);
    breadCrumbs.addWindow(window);
    if (workArea.getMode() == Mode.TABBED) {
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId = tabSheet.getTab(layout);
        String formattedCaption = formatTabCaption(caption, description);
        tabSheet.setTabCaption(tabId, formattedCaption);
        String formattedDescription = formatTabDescription(caption, description);
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(window.getContentSwitchMode().name());
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
    } else {
        layout.markAsDirtyRecursive();
    }
    return layout;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) CssLayout(com.vaadin.ui.CssLayout) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component) ParamsMap(com.haulmont.bali.util.ParamsMap) Collections.singletonMap(java.util.Collections.singletonMap)

Example 48 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class TaskHandlerImpl method detachCloseListener.

private void detachCloseListener() {
    // force remove close listener
    Frame ownerFrame = getTask().getOwnerFrame();
    if (ownerFrame != null) {
        Window ownerWindow = ComponentsHelper.getWindowImplementation(ownerFrame);
        if (ownerWindow != null) {
            ownerWindow.removeCloseListener(closeListener);
            String windowClass = ownerFrame.getClass().getCanonicalName();
            log.trace("Resources were disposed. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
        } else {
            log.trace("Empty ownerWindow. Resources were not disposed. Task: {}", taskExecutor.getTask());
        }
    } else {
        log.trace("Empty ownerFrame. Resources were not disposed. Task: {}", taskExecutor.getTask());
    }
    closeListener = null;
}
Also used : Window(com.haulmont.cuba.gui.components.Window) Frame(com.haulmont.cuba.gui.components.Frame)

Example 49 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, RelatedScreenDescriptor descriptor) {
    Preconditions.checkNotNullArgument(metaClass, "MetaClass can't be null");
    Preconditions.checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screen;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screen = descriptor.getScreenId();
        } else {
            screen = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screen)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Window window = windowManager.openWindow(windowConfig.getWindowInfo(screen), openType, params);
        boolean found = ComponentsHelper.walkComponents(window, screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((Filter) screenComponent).getDatasource().getMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), Frame.NotificationType.WARNING);
        }
        ((DsContextImplementation) window.getDsContext()).resumeSuspended();
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) MetaClass(com.haulmont.chile.core.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter)

Example 50 with Window

use of com.haulmont.cuba.gui.components.Window in project cuba by cuba-platform.

the class WebDataGrid method handleDoubleClickAction.

protected void handleDoubleClickAction() {
    Action action = getItemClickAction();
    if (action == null) {
        action = getEnterAction();
        if (action == null) {
            action = getAction("edit");
            if (action == null) {
                action = getAction("view");
            }
        }
    }
    if (action != null && action.isEnabled()) {
        Window window = ComponentsHelper.getWindowImplementation(WebDataGrid.this);
        if (window instanceof Window.Wrapper) {
            window = ((Window.Wrapper) window).getWrappedWindow();
        }
        if (!(window instanceof Window.Lookup)) {
            action.actionPerform(WebDataGrid.this);
        } else {
            Window.Lookup lookup = (Window.Lookup) window;
            com.haulmont.cuba.gui.components.Component lookupComponent = lookup.getLookupComponent();
            if (lookupComponent != this)
                action.actionPerform(WebDataGrid.this);
            else if (action.getId().equals(WindowDelegate.LOOKUP_ITEM_CLICK_ACTION_ID)) {
                action.actionPerform(WebDataGrid.this);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) SortableDataGridIndexedCollectionDsWrapper(com.haulmont.cuba.web.gui.data.SortableDataGridIndexedCollectionDsWrapper) DataGridIndexedCollectionDsWrapper(com.haulmont.cuba.web.gui.data.DataGridIndexedCollectionDsWrapper) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components)

Aggregations

Window (com.haulmont.cuba.gui.components.Window)54 DesktopWindow (com.haulmont.cuba.desktop.gui.components.DesktopWindow)15 WebWindow (com.haulmont.cuba.web.gui.WebWindow)13 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)10 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)6 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)6 ParamsMap (com.haulmont.bali.util.ParamsMap)5 Component (com.haulmont.cuba.gui.components.Component)5 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)5 Component (com.vaadin.ui.Component)5 Entity (com.haulmont.cuba.core.entity.Entity)4 TopLevelFrame (com.haulmont.cuba.desktop.TopLevelFrame)4 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)4 CssLayout (com.vaadin.ui.CssLayout)4 Pair (com.haulmont.bali.datastruct.Pair)3 WindowManager (com.haulmont.cuba.gui.WindowManager)3 Action (com.haulmont.cuba.gui.components.Action)3 ButtonsPanel (com.haulmont.cuba.gui.components.ButtonsPanel)3 Frame (com.haulmont.cuba.gui.components.Frame)3 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)3