Search in sources :

Example 26 with Component

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

the class WebWindowManager method showFrame.

@Override
public void showFrame(com.haulmont.cuba.gui.components.Component parent, Frame frame) {
    if (parent instanceof Container) {
        Container container = (Container) parent;
        for (com.haulmont.cuba.gui.components.Component c : container.getComponents()) {
            if (c instanceof com.haulmont.cuba.gui.components.Component.Disposable) {
                com.haulmont.cuba.gui.components.Component.Disposable disposable = (com.haulmont.cuba.gui.components.Component.Disposable) c;
                if (!disposable.isDisposed()) {
                    disposable.dispose();
                }
            }
            container.remove(c);
        }
        container.add(frame);
    } else {
        throw new IllegalStateException("Parent component must be com.haulmont.cuba.gui.components.Component.Container");
    }
}
Also used : Container(com.haulmont.cuba.gui.components.Component.Container) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 27 with Component

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

the class WebWindowManager method createNextWindowTabShortcut.

public ShortcutListener createNextWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
    String nextTabShortcut = clientConfig.getNextTabShortcut();
    KeyCombination combination = KeyCombination.create(nextTabShortcut);
    return new ShortcutListener("onNextTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {

        @Override
        public void handleAction(Object sender, Object target) {
            TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
            if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
                Component selectedTabComponent = tabSheet.getSelectedTab();
                String tabId = tabSheet.getTab(selectedTabComponent);
                int tabPosition = tabSheet.getTabPosition(tabId);
                int newTabPosition = (tabPosition + 1) % tabSheet.getComponentCount();
                String newTabId = tabSheet.getTab(newTabPosition);
                tabSheet.setSelectedTab(newTabId);
                moveFocus(tabSheet, newTabId);
            }
        }
    };
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 28 with Component

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

the class WebWindowManager method createNewTabLayout.

protected Layout createNewTabLayout(final Window window, final boolean multipleOpen, WindowBreadCrumbs breadCrumbs, Component... additionalComponents) {
    Layout layout = new CssLayout();
    layout.setPrimaryStyleName("c-app-window-wrap");
    layout.setSizeFull();
    layout.addComponent(breadCrumbs);
    if (additionalComponents != null) {
        for (final Component c : additionalComponents) {
            layout.addComponent(c);
        }
    }
    final Component component = WebComponentsHelper.getComposition(window);
    component.setSizeFull();
    layout.addComponent(component);
    WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
    if (workArea.getMode() == Mode.TABBED) {
        layout.addStyleName("c-app-tabbed-window");
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId;
        Integer hashCode = getWindowHashCode(window);
        ComponentContainer tab = null;
        if (hashCode != null) {
            tab = findTab(hashCode);
        }
        if (tab != null && !multipleOpen) {
            tabSheet.replaceComponent(tab, layout);
            tabSheet.removeComponent(tab);
            tabs.put(layout, breadCrumbs);
            tabId = tabSheet.getTab(layout);
        } else {
            tabs.put(layout, breadCrumbs);
            tabId = "tab_" + uuidSource.createUuid();
            tabSheet.addTab(layout, tabId);
            if (ui.isTestMode()) {
                String id = "tab_" + window.getId();
                tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
                tabSheet.setTabCubaId(tabId, id);
            }
        }
        String windowContentSwitchMode = window.getContentSwitchMode().name();
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
        String formattedCaption = formatTabCaption(window.getCaption(), window.getDescription());
        tabSheet.setTabCaption(tabId, formattedCaption);
        String formattedDescription = formatTabDescription(window.getCaption(), window.getDescription());
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        tabSheet.setTabClosable(tabId, true);
        tabSheet.setTabCloseHandler(layout, (targetTabSheet, tabContent) -> {
            // noinspection SuspiciousMethodCalls
            WindowBreadCrumbs breadCrumbs1 = tabs.get(tabContent);
            if (!canWindowBeClosed(breadCrumbs1.getCurrentWindow())) {
                return;
            }
            Runnable closeTask = new TabCloseTask(breadCrumbs1);
            closeTask.run();
            // it is needed to force redraw tabsheet if it has a lot of tabs and part of them are hidden
            targetTabSheet.markAsDirty();
        });
        tabSheet.setSelectedTab(layout);
    } else {
        tabs.put(layout, breadCrumbs);
        layout.addStyleName("c-app-single-window");
        VerticalLayout mainLayout = workArea.getSingleWindowContainer();
        mainLayout.removeAllComponents();
        mainLayout.addComponent(layout);
    }
    return layout;
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) CssLayout(com.vaadin.ui.CssLayout) 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 29 with Component

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

the class WebWindowManager method createPreviousWindowTabShortcut.

public ShortcutListener createPreviousWindowTabShortcut(Window.TopLevelWindow topLevelWindow) {
    String previousTabShortcut = clientConfig.getPreviousTabShortcut();
    KeyCombination combination = KeyCombination.create(previousTabShortcut);
    return new ShortcutListener("onPreviousTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) {

        @Override
        public void handleAction(Object sender, Object target) {
            TabSheetBehaviour tabSheet = getConfiguredWorkArea(createWorkAreaContext(topLevelWindow)).getTabbedWindowContainer().getTabSheetBehaviour();
            if (tabSheet != null && !hasDialogWindows() && tabSheet.getComponentCount() > 1) {
                Component selectedTabComponent = tabSheet.getSelectedTab();
                String selectedTabId = tabSheet.getTab(selectedTabComponent);
                int tabPosition = tabSheet.getTabPosition(selectedTabId);
                int newTabPosition = (tabSheet.getComponentCount() + tabPosition - 1) % tabSheet.getComponentCount();
                String newTabId = tabSheet.getTab(newTabPosition);
                tabSheet.setSelectedTab(newTabId);
                moveFocus(tabSheet, newTabId);
            }
        }
    };
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component)

Example 30 with Component

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

the class WebAbstractActionsHolderComponent method addAction.

@Override
public void addAction(Action action, int index) {
    checkNotNullArgument(action, "action must be non null");
    int oldIndex = findActionById(actionList, action.getId());
    if (oldIndex >= 0) {
        removeAction(actionList.get(oldIndex));
        if (index > oldIndex) {
            index--;
        }
    }
    if (StringUtils.isNotEmpty(action.getCaption())) {
        ContextMenuButton contextMenuButton = createContextMenuButton();
        contextMenuButton.setStyleName("c-cm-button");
        contextMenuButton.setAction(action);
        contextMenuButtons.add(contextMenuButton);
        Component newVButton = WebComponentsHelper.unwrap(contextMenuButton);
        int visibleActionsIndex = 0;
        int i = 0;
        while (i < index && i < actionList.size()) {
            if (StringUtils.isNotEmpty(actionList.get(i).getCaption())) {
                visibleActionsIndex++;
            }
            i++;
        }
        contextMenuPopup.addComponent(newVButton, visibleActionsIndex);
    }
    actionList.add(index, action);
    shortcutsDelegate.addAction(null, action);
    attachAction(action);
    actionsPermissions.apply(action);
}
Also used : Component(com.vaadin.ui.Component)

Aggregations

Component (com.vaadin.ui.Component)96 HorizontalLayout (com.vaadin.ui.HorizontalLayout)11 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)10 VerticalLayout (com.vaadin.ui.VerticalLayout)10 Button (com.vaadin.ui.Button)9 Label (com.vaadin.ui.Label)9 Test (org.junit.Test)8 Window (com.haulmont.cuba.gui.components.Window)6 CssLayout (com.vaadin.ui.CssLayout)6 List (java.util.List)6 WebWindow (com.haulmont.cuba.web.gui.WebWindow)5 Item (com.vaadin.data.Item)5 ClickEvent (com.vaadin.ui.Button.ClickEvent)5 ClickListener (com.vaadin.ui.Button.ClickListener)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)4 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)4 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)4 CubaFileUpload (com.haulmont.cuba.web.toolkit.ui.CubaFileUpload)4 com.vaadin.ui (com.vaadin.ui)4 com.haulmont.cuba.web.toolkit.ui (com.haulmont.cuba.web.toolkit.ui)3