Search in sources :

Example 46 with Component

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

the class DesktopGridLayout method removeAll.

@Override
public void removeAll() {
    wrappers.clear();
    impl.removeAll();
    componentByIds.clear();
    captions.clear();
    List<Component> components = new ArrayList<>(ownComponents);
    ownComponents.clear();
    for (Component component : components) {
        if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
            ((DesktopAbstractComponent) component).setParentEnabled(true);
        }
        component.setParent(null);
        DesktopContainerHelper.assignContainer(component, null);
    }
    requestRepaint();
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Example 47 with Component

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

the class WindowCreationHelper method applyComponentActionPermission.

/**
 * Process permissions for actions in action holder
 *
 * @param window          Window
 * @param screenId        Screen Id
 * @param permissionValue Permission value
 * @param componentId     Component Id
 */
private static void applyComponentActionPermission(Window window, String screenId, Integer permissionValue, String componentId) {
    final Matcher matcher = COMPONENT_ACTION_PATTERN.matcher(componentId);
    if (matcher.find()) {
        final String customComponentId = matcher.group(1);
        final String actionId = matcher.group(2);
        final Component actionHolderComponent = window.getComponent(customComponentId);
        if (actionHolderComponent != null) {
            if (actionHolderComponent instanceof Component.SecuredActionsHolder) {
                ActionsPermissions permissions = ((Component.SecuredActionsHolder) actionHolderComponent).getActionsPermissions();
                if (permissionValue == UiPermissionValue.HIDE.getValue()) {
                    permissions.addHiddenActionPermission(actionId);
                } else if (permissionValue == UiPermissionValue.READ_ONLY.getValue()) {
                    permissions.addDisabledActionPermission(actionId);
                }
            } else {
                log.warn(String.format("Couldn't apply permission on action %s for component %s in window %s", actionId, customComponentId, screenId));
            }
        } else {
            log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
        }
    } else {
        log.warn(String.format("Incorrect permission definition for component %s in window %s", componentId, screenId));
    }
}
Also used : ActionsPermissions(com.haulmont.cuba.gui.components.ActionsPermissions) Matcher(java.util.regex.Matcher) Component(com.haulmont.cuba.gui.components.Component)

Example 48 with Component

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

the class DsContextImpl method get.

@Override
public Datasource get(String id) {
    Preconditions.checkNotNullArgument(id, "Null datasource ID");
    Datasource ds = null;
    if (!id.contains(".")) {
        ds = datasourceMap.get(id);
        if (ds == null && parent != null) {
            ds = parent.get(id);
        }
    } else {
        if (windowContext != null) {
            String nestedFramePath = id.substring(0, id.indexOf("."));
            Component nestedFrame = getFrameContext().getFrame().getComponent(nestedFramePath);
            if ((nestedFrame) != null && (nestedFrame instanceof Frame)) {
                String nestedDsId = id.substring(id.indexOf(".") + 1);
                ds = ((Frame) nestedFrame).getDsContext().get(nestedDsId);
            }
        }
    }
    return ds;
}
Also used : Frame(com.haulmont.cuba.gui.components.Frame) Component(com.haulmont.cuba.gui.components.Component)

Example 49 with Component

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

the class DesktopWindowManager method addShortcuts.

protected void addShortcuts(Window window, OpenType openType) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    String closeShortcut = clientConfig.getCloseShortcut();
    window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("closeWindowShortcutAction", closeShortcut) {

        @Override
        public void actionPerform(Component component) {
            if (openType.getOpenMode() != OpenMode.DIALOG || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
                if (!isCloseWithShortcutPrevented(window)) {
                    window.close("close");
                }
            }
        }
    });
    String previousTabShortcut = clientConfig.getPreviousTabShortcut();
    window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onPreviousTab", previousTabShortcut) {

        @Override
        public void actionPerform(Component component) {
            if (window.getWindowManager() != DesktopWindowManager.this) {
                // detached tab
                return;
            }
            if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
                int selectedIndex = getSelectedTabIndex();
                int newIndex = (selectedIndex + tabsPane.getTabCount() - 1) % tabsPane.getTabCount();
                java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
                tabsPane.setSelectedComponent(newTab);
                moveFocus(newTab);
            }
        }
    });
    String nextTabShortcut = clientConfig.getNextTabShortcut();
    window.addAction(new com.haulmont.cuba.gui.components.AbstractAction("onNextTab", nextTabShortcut) {

        @Override
        public void actionPerform(Component component) {
            if (window.getWindowManager() != DesktopWindowManager.this) {
                // detached tab
                return;
            }
            if (isMainWindowManager && getLastDialogWindow() == null && tabsPane.getTabCount() > 1) {
                int selectedIndex = getSelectedTabIndex();
                int newIndex = (selectedIndex + 1) % tabsPane.getTabCount();
                java.awt.Component newTab = tabsPane.getComponentAt(newIndex);
                tabsPane.setSelectedComponent(newTab);
                moveFocus(newTab);
            }
        }
    });
}
Also used : com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) ClientConfig(com.haulmont.cuba.client.ClientConfig) DesktopAbstractComponent(com.haulmont.cuba.desktop.gui.components.DesktopAbstractComponent) Component(com.haulmont.cuba.gui.components.Component)

Example 50 with Component

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

the class DesktopWindowManager method checkModificationsAndCloseAll.

public void checkModificationsAndCloseAll(final Runnable runIfOk, @Nullable final Runnable runIfCancel) {
    boolean modified = false;
    for (Window window : getOpenWindows()) {
        if (!disableSavingScreenHistory) {
            screenHistorySupport.saveScreenHistory(window, windowOpenMode.get(window).getOpenMode());
        }
        recursiveFramesClose = true;
        try {
            if (window instanceof WrappedWindow && ((WrappedWindow) window).getWrapper() != null) {
                ((WrappedWindow) window).getWrapper().saveSettings();
            } else {
                window.saveSettings();
            }
        } finally {
            recursiveFramesClose = false;
        }
        if (window.getDsContext() != null && window.getDsContext().isModified()) {
            modified = true;
        }
    }
    disableSavingScreenHistory = true;
    if (modified) {
        showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("discardChangesOnClose"), MessageType.WARNING, new Action[] { new com.haulmont.cuba.gui.components.AbstractAction(messages.getMainMessage("closeApplication")) {

            @Override
            public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
                if (runIfOk != null)
                    runIfOk.run();
            }

            @Override
            public String getIcon() {
                return "icons/ok.png";
            }
        }, new com.haulmont.cuba.gui.components.AbstractAction(messages.getMainMessage("actions.Cancel"), Status.PRIMARY) {

            @Override
            public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
                if (runIfCancel != null)
                    runIfCancel.run();
            }

            @Override
            public String getIcon() {
                return "icons/cancel.png";
            }
        } });
    } else {
        runIfOk.run();
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DesktopWindow(com.haulmont.cuba.desktop.gui.components.DesktopWindow) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Component(com.haulmont.cuba.gui.components.Component)

Aggregations

Component (com.haulmont.cuba.gui.components.Component)78 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Datasource (com.haulmont.cuba.gui.data.Datasource)10 User (com.haulmont.cuba.security.entity.User)9 List (java.util.List)9 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)8 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Group (com.haulmont.cuba.security.entity.Group)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Element (org.dom4j.Element)6 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)5 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)5 Frame (com.haulmont.cuba.gui.components.Frame)4 AbstractComponent (com.vaadin.ui.AbstractComponent)4