Search in sources :

Example 1 with KeyCombination

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

the class WebPickerFieldActionHandler method addAction.

public void addAction(com.haulmont.cuba.gui.components.Action action, int index) {
    actionList.add(index, action);
    updateOrderedShortcuts();
    KeyCombination combination = action.getShortcutCombination();
    if (combination != null) {
        int key = combination.getKey().getCode();
        int[] modifiers = KeyCombination.Modifier.codes(combination.getModifiers());
        ShortcutAction providedShortcut = new ShortcutAction(action.getCaption(), key, modifiers);
        shortcuts.add(providedShortcut);
        actionsMap.put(providedShortcut, action);
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination) ShortcutAction(com.vaadin.event.ShortcutAction)

Example 2 with KeyCombination

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

the class ShortcutsDelegate method addAction.

public void addAction(@Nullable Action oldAction, Action newAction) {
    KeyCombination newShortcut = newAction.getShortcutCombination();
    if (newShortcut != null) {
        if (oldAction != null) {
            KeyCombination oldShortcut = oldAction.getShortcutCombination();
            if (newShortcut.equals(oldShortcut)) {
                removeShortcut(oldAction);
            } else if (oldShortcut != null) {
                removeShortcut(oldAction);
                // find and assign alternative
                addAlternativeShortcut(oldShortcut);
            }
        }
        addShortcut(newAction.getId(), newShortcut);
    } else {
        if (oldAction != null) {
            KeyCombination oldShortcut = oldAction.getShortcutCombination();
            if (oldShortcut != null) {
                removeShortcut(oldAction);
                // find and assign alternative
                addAlternativeShortcut(oldShortcut);
            }
        }
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination)

Example 3 with KeyCombination

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

the class WebButton method setAction.

@Override
public void setAction(Action action) {
    if (action != this.action) {
        if (this.action != null) {
            this.action.removeOwner(this);
            this.action.removePropertyChangeListener(actionPropertyChangeListener);
            if (Objects.equals(this.action.getCaption(), getCaption())) {
                setCaption(null);
            }
            if (Objects.equals(this.action.getDescription(), getDescription())) {
                setDescription(null);
            }
            if (Objects.equals(this.action.getIcon(), getIcon())) {
                setIcon(null);
            }
        }
        this.action = action;
        if (action != null) {
            String caption = action.getCaption();
            if (caption != null && component.getCaption() == null) {
                component.setCaption(caption);
            }
            String description = action.getDescription();
            KeyCombination shortcutCombination = action.getShortcutCombination();
            if (shortcutCombination != null) {
                setShortcutCombination(shortcutCombination);
                if (description == null) {
                    description = shortcutCombination.format();
                }
            }
            if (description != null && component.getDescription() == null) {
                component.setDescription(description);
            }
            component.setEnabled(action.isEnabled());
            component.setVisible(action.isVisible());
            if (action.getIcon() != null && getIcon() == null) {
                setIcon(action.getIcon());
            }
            action.addOwner(this);
            actionPropertyChangeListener = evt -> {
                String propertyName = evt.getPropertyName();
                if (Action.PROP_ICON.equals(propertyName)) {
                    setIcon(this.action.getIcon());
                } else if (Action.PROP_CAPTION.equals(propertyName)) {
                    setCaption(this.action.getCaption());
                } else if (Action.PROP_DESCRIPTION.equals(propertyName)) {
                    setDescription(this.action.getDescription());
                } else if (Action.PROP_ENABLED.equals(propertyName)) {
                    setEnabled(this.action.isEnabled());
                } else if (Action.PROP_VISIBLE.equals(propertyName)) {
                    setVisible(this.action.isVisible());
                } else if (Action.PROP_SHORTCUT.equals(propertyName)) {
                    setShortcutCombination(this.action.getShortcutCombination());
                }
            };
            action.addPropertyChangeListener(actionPropertyChangeListener);
            if (component.getCubaId() == null) {
                AppUI ui = AppUI.getCurrent();
                if (ui != null && ui.isTestMode()) {
                    component.setCubaId(action.getId());
                }
            }
        }
        boolean primaryAction = action instanceof AbstractAction && ((AbstractAction) action).isPrimary();
        boolean primaryButton = getStyleName().contains(PRIMARY_ACTION_STYLENAME);
        if (primaryAction || primaryButton) {
            addStyleName(PRIMARY_ACTION_STYLENAME);
        } else {
            removeStyleName(PRIMARY_ACTION_STYLENAME);
        }
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination) AppUI(com.haulmont.cuba.web.AppUI) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 4 with KeyCombination

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

the class MenuBuilder method assignShortcut.

protected void assignShortcut(Window webWindow, AppMenu.MenuItem menuItem, MenuItem item) {
    KeyCombination itemShortcut = item.getShortcut();
    if (itemShortcut != null) {
        ShortcutListener shortcut = new MenuShortcutAction(menuItem, "shortcut_" + item.getId(), item.getShortcut());
        AbstractComponent windowImpl = webWindow.unwrap(AbstractComponent.class);
        windowImpl.addShortcutListener(shortcut);
        appMenu.setMenuItemShortcutCaption(menuItem, itemShortcut.format());
    }
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) MenuShortcutAction(com.haulmont.cuba.web.gui.MenuShortcutAction) AbstractComponent(com.vaadin.ui.AbstractComponent) KeyCombination(com.haulmont.cuba.gui.components.KeyCombination)

Example 5 with KeyCombination

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

the class SideMenuBuilder method assignShortcut.

protected void assignShortcut(Window webWindow, SideMenu.MenuItem menuItem, MenuItem item) {
    KeyCombination itemShortcut = item.getShortcut();
    if (itemShortcut != null) {
        ShortcutListener shortcut = new SideMenuShortcutListener(menuItem, item);
        AbstractComponent windowImpl = webWindow.unwrap(AbstractComponent.class);
        windowImpl.addShortcutListener(shortcut);
        if (Strings.isNullOrEmpty(menuItem.getBadgeText())) {
            menuItem.setDescription(itemShortcut.format());
        }
    }
}
Also used : ShortcutListener(com.vaadin.event.ShortcutListener) AbstractComponent(com.vaadin.ui.AbstractComponent) KeyCombination(com.haulmont.cuba.gui.components.KeyCombination)

Aggregations

KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)8 ShortcutListener (com.vaadin.event.ShortcutListener)2 AbstractComponent (com.vaadin.ui.AbstractComponent)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 Messages (com.haulmont.cuba.core.global.Messages)1 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)1 AppUI (com.haulmont.cuba.web.AppUI)1 MenuShortcutAction (com.haulmont.cuba.web.gui.MenuShortcutAction)1 CubaButton (com.haulmont.cuba.web.widgets.CubaButton)1 ShortcutAction (com.vaadin.event.ShortcutAction)1