Search in sources :

Example 76 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class AccessGroupCompanion method initDragAndDrop.

@Override
public void initDragAndDrop(Table<User> usersTable, Tree<Group> groupsTree, Consumer<UserGroupChangedEvent> userGroupChangedHandler) {
    com.vaadin.ui.Table vTable = usersTable.unwrap(com.vaadin.ui.Table.class);
    vTable.setDragMode(com.vaadin.ui.Table.TableDragMode.MULTIROW);
    CubaTree vTree = groupsTree.unwrap(CubaTree.class);
    vTree.setDragMode(com.vaadin.ui.Tree.TreeDragMode.NODE);
    vTree.setDropHandler(new DropHandler() {

        @Override
        public void drop(DragAndDropEvent dropEvent) {
            DataBoundTransferable transferable = (DataBoundTransferable) dropEvent.getTransferable();
            AbstractSelect.AbstractSelectTargetDetails dropData = ((AbstractSelect.AbstractSelectTargetDetails) dropEvent.getTargetDetails());
            Component sourceComponent = transferable.getSourceComponent();
            List<User> users = null;
            if (sourceComponent instanceof com.vaadin.ui.Table) {
                users = new ArrayList<>(usersTable.getSelected());
            }
            if (users == null) {
                return;
            }
            if (users.isEmpty()) {
                User user = convertToEntity(vTable.getItem(transferable.getItemId()), User.class);
                users.add(user);
            }
            final Object targetItemId = dropData.getItemIdOver();
            if (targetItemId == null) {
                return;
            }
            Group group = convertToEntity(vTree.getItem(targetItemId), Group.class);
            if (group == null) {
                return;
            }
            userGroupChangedHandler.accept(new UserGroupChangedEvent(groupsTree, users, group));
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return new And(AbstractSelect.AcceptItem.ALL);
        }
    });
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DragAndDropEvent(com.vaadin.event.dd.DragAndDropEvent) ArrayList(java.util.ArrayList) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree) DataBoundTransferable(com.vaadin.event.DataBoundTransferable) UserGroupChangedEvent(com.haulmont.cuba.gui.app.security.group.browse.UserGroupChangedEvent) And(com.vaadin.event.dd.acceptcriteria.And) ArrayList(java.util.ArrayList) List(java.util.List) DropHandler(com.vaadin.event.dd.DropHandler) Component(com.vaadin.ui.Component) AcceptCriterion(com.vaadin.event.dd.acceptcriteria.AcceptCriterion)

Example 77 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class WebWindowManager method createCloseShortcut.

public ShortcutListener createCloseShortcut(Window.TopLevelWindow topLevelWindow) {
    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination combination = KeyCombination.create(closeShortcut);
    return new ShortcutListener("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {

        @Override
        public void handleAction(Object sender, Object target) {
            WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow));
            if (workArea.getState() != AppWorkArea.State.WINDOW_CONTAINER) {
                return;
            }
            if (workArea.getMode() == Mode.TABBED) {
                TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                if (tabSheet != null) {
                    Layout layout = (Layout) tabSheet.getSelectedTab();
                    if (layout != null) {
                        tabSheet.focus();
                        WindowBreadCrumbs breadCrumbs = tabs.get(layout);
                        if (!canWindowBeClosed(breadCrumbs.getCurrentWindow())) {
                            return;
                        }
                        if (isCloseWithShortcutPrevented(breadCrumbs.getCurrentWindow())) {
                            return;
                        }
                        if (stacks.get(breadCrumbs).empty()) {
                            final Component previousTab = tabSheet.getPreviousTab(layout);
                            if (previousTab != null) {
                                breadCrumbs.getCurrentWindow().closeAndRun(Window.CLOSE_ACTION_ID, () -> tabSheet.setSelectedTab(previousTab));
                            } else {
                                breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
                            }
                        } else {
                            breadCrumbs.getCurrentWindow().close(Window.CLOSE_ACTION_ID);
                        }
                    }
                }
            } else {
                Iterator<WindowBreadCrumbs> it = tabs.values().iterator();
                if (it.hasNext()) {
                    Window currentWindow = it.next().getCurrentWindow();
                    if (!isCloseWithShortcutPrevented(currentWindow)) {
                        ui.focus();
                        currentWindow.close(Window.CLOSE_ACTION_ID);
                    }
                }
            }
        }
    };
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) ShortcutListener(com.vaadin.event.ShortcutListener) 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)

Example 78 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class WebWindowManager method showWindow.

@Override
protected void showWindow(final Window window, final String caption, final String description, OpenType type, final boolean multipleOpen) {
    OpenType targetOpenType = type.copy();
    // for backward compatibility only
    copyDialogParamsToOpenType(targetOpenType);
    overrideOpenTypeParams(targetOpenType, window.getDialogOptions());
    boolean forciblyDialog = false;
    if (targetOpenType.getOpenMode() != OpenMode.DIALOG && hasModalWindow()) {
        targetOpenType.setOpenMode(OpenMode.DIALOG);
        forciblyDialog = true;
    }
    if (targetOpenType.getOpenMode() == OpenMode.THIS_TAB && tabs.size() == 0) {
        targetOpenType.setOpenMode(OpenMode.NEW_TAB);
    }
    final WindowOpenInfo openInfo = new WindowOpenInfo(window, targetOpenType.getOpenMode());
    Component component;
    window.setCaption(caption);
    window.setDescription(description);
    switch(targetOpenType.getOpenMode()) {
        case NEW_TAB:
        case NEW_WINDOW:
            final WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
            workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
            if (workArea.getMode() == Mode.SINGLE) {
                VerticalLayout mainLayout = workArea.getSingleWindowContainer();
                if (mainLayout.iterator().hasNext()) {
                    ComponentContainer oldLayout = (ComponentContainer) mainLayout.iterator().next();
                    WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
                    if (oldBreadCrumbs != null) {
                        Window oldWindow = oldBreadCrumbs.getCurrentWindow();
                        oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> showWindow(window, caption, description, OpenType.NEW_TAB, false));
                        return;
                    }
                }
            } else {
                final Integer hashCode = getWindowHashCode(window);
                ComponentContainer tab = null;
                if (hashCode != null && !multipleOpen) {
                    tab = findTab(hashCode);
                }
                ComponentContainer oldLayout = tab;
                final WindowBreadCrumbs oldBreadCrumbs = tabs.get(oldLayout);
                if (oldBreadCrumbs != null && windowOpenMode.containsKey(oldBreadCrumbs.getCurrentWindow().getFrame()) && !multipleOpen) {
                    Window oldWindow = oldBreadCrumbs.getCurrentWindow();
                    selectWindowTab(((Window.Wrapper) oldBreadCrumbs.getCurrentWindow()).getWrappedWindow());
                    int tabPosition = -1;
                    final TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                    String tabId = tabSheet.getTab(tab);
                    if (tabId != null) {
                        tabPosition = tabSheet.getTabPosition(tabId);
                    }
                    final int finalTabPosition = tabPosition;
                    oldWindow.closeAndRun(MAIN_MENU_ACTION_ID, () -> {
                        showWindow(window, caption, description, OpenType.NEW_TAB, false);
                        Window wrappedWindow = window;
                        if (window instanceof Window.Wrapper) {
                            wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
                        }
                        if (finalTabPosition >= 0 && finalTabPosition < tabSheet.getComponentCount() - 1) {
                            moveWindowTab(workArea, wrappedWindow, finalTabPosition);
                        }
                    });
                    return;
                }
            }
            component = showWindowNewTab(window, multipleOpen);
            break;
        case THIS_TAB:
            getConfiguredWorkArea(createWorkAreaContext(window)).switchTo(AppWorkArea.State.WINDOW_CONTAINER);
            component = showWindowThisTab(window, caption, description);
            break;
        case DIALOG:
            component = showWindowDialog(window, targetOpenType, forciblyDialog);
            break;
        default:
            throw new UnsupportedOperationException();
    }
    openInfo.setData(component);
    if (window instanceof Window.Wrapper) {
        Window wrappedWindow = ((Window.Wrapper) window).getWrappedWindow();
        windowOpenMode.put(wrappedWindow, openInfo);
    } else {
        windowOpenMode.put(window, openInfo);
    }
    afterShowWindow(window);
}
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) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 79 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class WebWindowManager method setWindowCaption.

@Override
public void setWindowCaption(Window window, String caption, String description) {
    Window webWindow = window;
    if (window instanceof Window.Wrapper) {
        webWindow = ((Window.Wrapper) window).getWrappedWindow();
    }
    window.setCaption(caption);
    window.setDebugId(description);
    WindowOpenInfo openInfo = windowOpenMode.get(webWindow);
    String formattedCaption;
    if (openInfo != null && (openInfo.getOpenMode() == OpenMode.NEW_TAB || openInfo.getOpenMode() == OpenMode.NEW_WINDOW || openInfo.getOpenMode() == OpenMode.THIS_TAB)) {
        formattedCaption = formatTabCaption(caption, description);
    } else {
        formattedCaption = formatTabDescription(caption, description);
    }
    if (openInfo != null) {
        if (openInfo.getOpenMode() == OpenMode.DIALOG) {
            com.vaadin.ui.Window dialog = (com.vaadin.ui.Window) openInfo.getData();
            dialog.setCaption(formattedCaption);
        } else {
            if (getConfiguredWorkArea(createWorkAreaContext(window)).getMode() == Mode.SINGLE) {
                return;
            }
            Component tabContent = (Component) openInfo.getData();
            if (tabContent == null) {
                return;
            }
            TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(window)).getTabbedWindowContainer().getTabSheetBehaviour();
            String tabId = tabSheet.getTab(tabContent);
            if (tabId == null) {
                return;
            }
            tabSheet.setTabCaption(tabId, formattedCaption);
            String formattedDescription = formatTabDescription(caption, description);
            if (!Objects.equals(formattedDescription, formattedCaption)) {
                tabSheet.setTabDescription(tabId, formattedDescription);
            } else {
                tabSheet.setTabDescription(tabId, null);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) com.haulmont.cuba.web.toolkit.ui(com.haulmont.cuba.web.toolkit.ui) com.vaadin.ui(com.vaadin.ui) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 80 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class WebWindowManager method closeWindow.

protected void closeWindow(Window window, WindowOpenInfo openInfo) {
    if (!disableSavingScreenHistory) {
        screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode());
    }
    WebWindow webWindow = (WebWindow) window;
    webWindow.stopTimers();
    switch(openInfo.getOpenMode()) {
        case DIALOG:
            {
                final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData();
                cubaDialogWindow.forceClose();
                fireListeners(window, tabs.size() != 0);
                break;
            }
        case NEW_WINDOW:
        case NEW_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                if (workArea.getMode() == Mode.TABBED) {
                    TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                    tabSheet.silentCloseTabAndSelectPrevious(layout);
                    tabSheet.removeComponent(layout);
                } else {
                    VerticalLayout singleLayout = workArea.getSingleWindowContainer();
                    singleLayout.removeComponent(layout);
                }
                WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout);
                if (windowBreadCrumbs != null) {
                    windowBreadCrumbs.clearListeners();
                    windowBreadCrumbs.removeWindow();
                }
                tabs.remove(layout);
                stacks.remove(windowBreadCrumbs);
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        case THIS_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
                if (breadCrumbs == null) {
                    throw new IllegalStateException("Unable to close screen: breadCrumbs not found");
                }
                breadCrumbs.removeWindow();
                Window currentWindow = breadCrumbs.getCurrentWindow();
                if (!getStack(breadCrumbs).empty()) {
                    Pair<Window, Integer> entry = getStack(breadCrumbs).pop();
                    putToWindowMap(entry.getFirst(), entry.getSecond());
                }
                Component component = WebComponentsHelper.getComposition(currentWindow);
                component.setSizeFull();
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                if (app.getConnection().isConnected()) {
                    layout.addComponent(component);
                    if (workArea.getMode() == Mode.TABBED) {
                        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                        String tabId = tabSheet.getTab(layout);
                        String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription());
                        tabSheet.setTabCaption(tabId, formattedCaption);
                        String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription());
                        if (!Objects.equals(formattedCaption, formattedDescription)) {
                            tabSheet.setTabDescription(tabId, formattedDescription);
                        } else {
                            tabSheet.setTabDescription(tabId, null);
                        }
                        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
                        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(currentWindow.getContentSwitchMode().name());
                        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
                    }
                }
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        default:
            {
                throw new UnsupportedOperationException();
            }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) 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) Pair(com.haulmont.bali.datastruct.Pair)

Aggregations

Component (com.vaadin.ui.Component)146 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)23 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)13 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)11 HorizontalLayout (com.vaadin.ui.HorizontalLayout)11 VerticalLayout (com.vaadin.ui.VerticalLayout)11 Button (com.vaadin.ui.Button)9 Window (com.haulmont.cuba.gui.components.Window)8 Label (com.vaadin.ui.Label)8 Test (org.junit.Test)8 WebWindow (com.haulmont.cuba.web.gui.WebWindow)7 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)6 CssLayout (com.vaadin.ui.CssLayout)6 List (java.util.List)6 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)5 CubaUI (com.haulmont.cuba.web.widgets.CubaUI)5 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 Item (com.vaadin.data.Item)5