Search in sources :

Example 26 with Window

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

the class WindowCreationHelper method applyUiPermissions.

/**
 * Apply UI permissions to a frame.
 *
 * @param container frame
 */
public static void applyUiPermissions(Frame container) {
    Window window = container instanceof Window ? (Window) container : ComponentsHelper.getWindow(container);
    if (window == null) {
        log.warn(String.format("Unable to find window for container %s with id '%s'", container.getClass(), container.getId()));
        return;
    }
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    UserSession userSession = sessionSource.getUserSession();
    String screenId = window.getId();
    Map<String, Integer> uiPermissions = userSession.getPermissionsByType(PermissionType.UI);
    for (Map.Entry<String, Integer> permissionEntry : uiPermissions.entrySet()) {
        String target = permissionEntry.getKey();
        String targetComponentId = getTargetComponentId(target, screenId);
        if (targetComponentId != null) {
            if (targetComponentId.contains("[")) {
                applyCompositeComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            } else if (targetComponentId.contains(">")) {
                applyComponentActionPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            } else {
                applyComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Map(java.util.Map)

Example 27 with Window

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

the class DesktopWindowManager method attachTab.

public void attachTab(WindowBreadCrumbs breadCrumbs, Stack<Map.Entry<Window, Integer>> stack, Window window, Integer hashCode, final JComponent tabContent, Map<Window, WindowOpenInfo> openInfos) {
    frame.add(tabContent);
    frame.addWindowListener(new ValidationAwareWindowClosingListener() {

        @Override
        public void windowClosingAfterValidation(WindowEvent e) {
            closeTab(tabContent);
        }
    });
    tabs.put(tabContent, breadCrumbs);
    windowOpenMode.putAll(openInfos);
    stacks.put(breadCrumbs, stack);
    for (Map.Entry<Window, Integer> entry : stack) {
        entry.getKey().setWindowManager(this);
    }
    window.setWindowManager(this);
    if (hashCode != null) {
        windows.put(window, hashCode);
    }
    JPopupMenu popupMenu = createWindowPopupMenu(window);
    if (popupMenu.getComponentCount() > 0) {
        frame.getRootPane().setComponentPopupMenu(popupMenu);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow) ValidationAwareWindowClosingListener(com.haulmont.cuba.desktop.sys.validation.ValidationAwareWindowClosingListener) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 28 with Window

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

the class DesktopWindowManager method detachTab.

protected void detachTab(int tabIndex) {
    // Create new top-level frame, put this tab to it with breadcrumbs.
    // remove tab data from this window manager
    JComponent tabContent = (JComponent) tabsPane.getComponentAt(tabIndex);
    WindowBreadCrumbs breadCrumbs = tabs.get(tabContent);
    Window window = breadCrumbs.getCurrentWindow();
    if (window == null) {
        throw new IllegalArgumentException("window is null");
    }
    // WindowOpenMode map
    Map<Window, WindowOpenInfo> detachOpenModes = new HashMap<>();
    detachOpenModes.put((Window) window.getFrame(), windowOpenMode.get(window.<Window>getFrame()));
    windowOpenMode.remove(window.<Window>getFrame());
    Stack<Map.Entry<Window, Integer>> stack = stacks.get(breadCrumbs);
    for (Map.Entry<Window, Integer> entry : stack) {
        WindowOpenInfo openInfo = windowOpenMode.get(entry.getKey().<Window>getFrame());
        detachOpenModes.put((Window) entry.getKey().getFrame(), openInfo);
        windowOpenMode.remove(entry.getKey().<Window>getFrame());
    }
    tabs.remove(tabContent);
    Integer hashCode = windows.remove(window);
    tabsPane.remove(tabIndex);
    stacks.remove(breadCrumbs);
    final TopLevelFrame windowFrame = createTopLevelFrame(window.getCaption());
    App.getInstance().registerFrame(windowFrame);
    windowFrame.setVisible(true);
    windowFrame.getWindowManager().attachTab(breadCrumbs, stack, window, hashCode, tabContent, detachOpenModes);
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow) TopLevelFrame(com.haulmont.cuba.desktop.TopLevelFrame) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 29 with Window

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

the class DesktopWindowManager method setWindowCaption.

@Override
public void setWindowCaption(Window window, String caption, String description) {
    Window desktopWindow = window;
    if (window instanceof Window.Wrapper) {
        desktopWindow = ((Window.Wrapper) window).getWrappedWindow();
    }
    window.setCaption(caption);
    String formattedCaption = formatTabDescription(caption, description);
    WindowOpenInfo openInfo = windowOpenMode.get(desktopWindow);
    if (openInfo != null) {
        OpenMode openMode = openInfo.getOpenMode();
        if (openMode != OpenMode.DIALOG) {
            if (tabsPane != null) {
                int selectedIndex = tabsPane.getSelectedIndex();
                if (selectedIndex != -1) {
                    setActiveWindowCaption(caption, description, selectedIndex);
                }
            } else if (!isMainWindowManager) {
                setTopLevelWindowCaption(formattedCaption);
            }
        } else {
            JDialog jDialog = (JDialog) openInfo.getData();
            if (jDialog != null) {
                jDialog.setTitle(formattedCaption);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow)

Example 30 with Window

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

the class DesktopWindowManager method showNewWindow.

protected JComponent showNewWindow(Window window, OpenType openType, String caption) {
    window.setHeight("100%");
    window.setWidth("100%");
    TopLevelFrame windowFrame = createTopLevelFrame(caption);
    windowFrame.setName(window.getId());
    Dimension dimension = new Dimension();
    dimension.width = 800;
    if (openType.getWidth() != null) {
        dimension.width = openType.getWidth().intValue();
    }
    dimension.height = 500;
    if (openType.getHeight() != null) {
        dimension.height = openType.getHeight().intValue();
    }
    boolean resizable = true;
    if (openType.getResizable() != null) {
        resizable = openType.getResizable();
    }
    windowFrame.setResizable(resizable);
    windowFrame.setMinimumSize(dimension);
    windowFrame.pack();
    getDialogParams().reset();
    WindowBreadCrumbs breadCrumbs = createBreadCrumbs();
    breadCrumbs.addWindow(window);
    JComponent tabContent = createTabPanel(window, breadCrumbs);
    WindowOpenInfo openInfo = new WindowOpenInfo(window, OpenMode.NEW_WINDOW);
    openInfo.setData(tabContent);
    Map<Window, WindowOpenInfo> openInfos = new HashMap<>();
    if (window instanceof Window.Wrapper) {
        Window wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
        openInfos.put(wrappedWindow, openInfo);
    } else {
        openInfos.put(window, openInfo);
    }
    windowFrame.getWindowManager().attachTab(breadCrumbs, new Stack<>(), window, getWindowHashCode(window), tabContent, openInfos);
    App.getInstance().registerFrame(windowFrame);
    windowFrame.setVisible(true);
    return DesktopComponentsHelper.getComposition(window);
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow) TopLevelFrame(com.haulmont.cuba.desktop.TopLevelFrame)

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