Search in sources :

Example 1 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class CubaFoldersPane method createSearchFoldersPane.

protected Component createSearchFoldersPane() {
    searchFoldersTree = new CubaTree();
    searchFoldersTree.setCubaId("searchFoldersTree");
    searchFoldersTree.setSelectable(true);
    searchFoldersTree.setItemStyleGenerator(new FolderTreeStyleProvider());
    searchFoldersTree.addShortcutListener(new ShortcutListener("applySearchFolder", ShortcutAction.KeyCode.ENTER, (int[]) null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == searchFoldersTree) {
                AbstractSearchFolder folder = (AbstractSearchFolder) searchFoldersTree.getValue();
                if (folder != null) {
                    openFolder(folder);
                }
            }
        }
    });
    List<SearchFolder> searchFolders = foldersService.loadSearchFolders();
    searchFoldersRoot = messages.getMainMessage("folders.searchFoldersRoot");
    searchFoldersTree.addItemClickListener(new FolderClickListener());
    searchFoldersTree.addActionHandler(new SearchFolderActionsHandler());
    if (!searchFolders.isEmpty()) {
        fillTree(searchFoldersTree, searchFolders, isNeedRootSearchFolder() ? searchFoldersRoot : null);
    }
    for (Object itemId : searchFoldersTree.rootItemIds()) {
        searchFoldersTree.expandItemsRecursively(itemId);
    }
    return searchFoldersTree;
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) CubaTree(com.haulmont.cuba.web.toolkit.ui.CubaTree)

Example 2 with ShortcutListener

use of com.vaadin.event.ShortcutListener 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 3 with ShortcutListener

use of com.vaadin.event.ShortcutListener 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 4 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class WebDataGrid method initComponent.

protected void initComponent(CubaGrid component) {
    setSelectionMode(SelectionMode.SINGLE);
    component.setImmediate(true);
    component.setColumnReorderingAllowed(true);
    containerWrapper = new GeneratedPropertyContainer(component.getContainerDataSource());
    component.setContainerDataSource(containerWrapper);
    component.addSelectionListener(e -> {
        if (datasource == null) {
            return;
        }
        final Set<E> selected = getSelected();
        if (selected.isEmpty()) {
            Entity dsItem = datasource.getItemIfValid();
            // noinspection unchecked
            datasource.setItem(null);
            if (dsItem == null) {
                // in this case item change event will not be generated
                refreshActionsState();
            }
        } else {
            // reset selection and select new item
            if (isMultiSelect()) {
                // noinspection unchecked
                datasource.setItem(null);
            }
            Entity newItem = selected.iterator().next();
            Entity dsItem = datasource.getItemIfValid();
            // noinspection unchecked
            datasource.setItem(newItem);
            if (Objects.equals(dsItem, newItem)) {
                // in this case item change event will not be generated
                refreshActionsState();
            }
        }
        LookupSelectionChangeEvent selectionChangeEvent = new LookupSelectionChangeEvent(this);
        getEventRouter().fireEvent(LookupSelectionChangeListener.class, LookupSelectionChangeListener::lookupValueChanged, selectionChangeEvent);
        if (getEventRouter().hasListeners(SelectionListener.class)) {
            List<E> addedItems = getItemsByIds(e.getAdded());
            List<E> removedItems = getItemsByIds(e.getRemoved());
            List<E> selectedItems = getItemsByIds(e.getSelected());
            SelectionEvent<E> event = new SelectionEvent<>(WebDataGrid.this, addedItems, removedItems, selectedItems);
            // noinspection unchecked
            getEventRouter().fireEvent(SelectionListener.class, SelectionListener::selected, event);
        }
    });
    component.addShortcutListener(new ShortcutListener("dataGridEnter", KeyCode.ENTER, null) {

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == WebDataGrid.this.component) {
                if (WebDataGrid.this.isEditorEnabled()) {
                    // since it's the default shortcut to open editor
                    return;
                }
                if (enterPressAction != null) {
                    enterPressAction.actionPerform(WebDataGrid.this);
                } else {
                    handleDoubleClickAction();
                }
            }
        }
    });
    component.addItemClickListener(e -> {
        if (e.isDoubleClick() && e.getItem() != null && !WebDataGrid.this.isEditorEnabled()) {
            // note: for now Grid doesn't send double click if editor is enabled,
            // but it's better to handle it manually
            handleDoubleClickAction();
        }
        if (getEventRouter().hasListeners(ItemClickListener.class)) {
            MouseEventDetails mouseEventDetails = WebWrapperUtils.toMouseEventDetails(e);
            // noinspection unchecked
            E item = (E) datasource.getItem(e.getItemId());
            if (item == null) {
                // datasource, so we don't want to send such event because it's useless
                return;
            }
            Column column = getColumnByPropertyId(e.getPropertyId());
            ItemClickEvent<E> event = new ItemClickEvent<>(WebDataGrid.this, mouseEventDetails, item, e.getItemId(), column != null ? column.getId() : null);
            // noinspection unchecked
            getEventRouter().fireEvent(ItemClickListener.class, ItemClickListener::onItemClick, event);
        }
    });
    component.addColumnReorderListener(e -> {
        if (e.isUserOriginated()) {
            // Grid doesn't know about columns hidden by security permissions,
            // so we need to return them back to they previous positions
            columnsOrder = restoreColumnsOrder(getColumnsOrderInternal());
            if (getEventRouter().hasListeners(ColumnReorderListener.class)) {
                ColumnReorderEvent event = new ColumnReorderEvent(WebDataGrid.this);
                getEventRouter().fireEvent(ColumnReorderListener.class, ColumnReorderListener::columnReordered, event);
            }
        }
    });
    componentComposition = new GridComposition();
    componentComposition.setPrimaryStyleName("c-data-grid-composition");
    componentComposition.setGrid(component);
    componentComposition.addComponent(component);
    componentComposition.setWidthUndefined();
    component.setSizeUndefined();
    component.setHeightMode(HeightMode.UNDEFINED);
    component.setRowStyleGenerator(createRowStyleGenerator());
    component.setCellStyleGenerator(createCellStyleGenerator());
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) ShortcutListener(com.vaadin.event.ShortcutListener) GeneratedPropertyContainer(com.vaadin.data.util.GeneratedPropertyContainer)

Example 5 with ShortcutListener

use of com.vaadin.event.ShortcutListener in project cuba by cuba-platform.

the class WebMaskedField method addEnterPressListener.

@Override
public void addEnterPressListener(EnterPressListener listener) {
    getEventRouter().addListener(EnterPressListener.class, listener);
    if (enterShortcutListener == null) {
        enterShortcutListener = new ShortcutListener("enter", KeyCode.ENTER, null) {

            @Override
            public void handleAction(Object sender, Object target) {
                EnterPressEvent event = new EnterPressEvent(WebMaskedField.this);
                getEventRouter().fireEvent(EnterPressListener.class, EnterPressListener::enterPressed, event);
            }
        };
        component.addShortcutListener(enterShortcutListener);
    }
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener)

Aggregations

ShortcutListener (com.vaadin.event.ShortcutListener)14 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)3 Component (com.vaadin.ui.Component)3 KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)2 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)2 ShortcutsDelegate (com.haulmont.cuba.gui.components.sys.ShortcutsDelegate)2 ShowInfoAction (com.haulmont.cuba.gui.components.sys.ShowInfoAction)2 ShortcutListenerDelegate (com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate)2 AbstractComponent (com.vaadin.ui.AbstractComponent)2 CssLayout (com.vaadin.ui.CssLayout)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 Entity (com.haulmont.cuba.core.entity.Entity)1 DialogParams (com.haulmont.cuba.gui.DialogParams)1 Window (com.haulmont.cuba.gui.components.Window)1 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)1 MenuShortcutAction (com.haulmont.cuba.web.gui.MenuShortcutAction)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1 WebButton (com.haulmont.cuba.web.gui.components.WebButton)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)1