public static void setClickShortcut(Button button, String shortcut) { KeyCombination closeCombination = KeyCombination.create(shortcut); int[] closeModifiers = Modifier.codes(closeCombination.getModifiers()); int closeCode = closeCombination.getKey().getCode(); button.setClickShortcut(closeCode, closeModifiers); }
protected FilterHelper.ShortcutListener createFtsSearchShortcutListener() { return new FilterHelper.ShortcutListener("ftsSearch", new KeyCombination(Key.ENTER)) { @Override public void handleShortcutPressed() { applyFts(); } }; }
private void addShortcut(final String actionId, KeyCombination keyCombination) { if (!allowEnterShortcut && (keyCombination.getModifiers() == null || keyCombination.getModifiers().length == 0) && keyCombination.getKey() == KeyCombination.Key.ENTER) { return; } for (Action oldAction : getActions()) { if (keyCombination.equals(oldAction.getShortcutCombination())) { removeShortcut(oldAction); } } shortcuts.put(actionId, attachShortcut(actionId, keyCombination)); }
public MenuShortcutAction(AppMenu.MenuItem menuItem, String caption, KeyCombination key) { this(menuItem, caption, key.getKey().getCode(), KeyCombination.getShortcutModifiers(key.getModifiers())); }
protected Action getEnterAction() { for (Action action : getActions()) { KeyCombination kc = action.getShortcutCombination(); if (kc != null) { if ((kc.getModifiers() == null || kc.getModifiers().length == 0) && kc.getKey() == KeyCombination.Key.ENTER) { return action; } } } return null; }
/** * Set shortcut using fluent API method. * * @param shortcut shortcut * @return current instance of action */ public BaseAction withShortcut(String shortcut) { if (shortcut != null) { this.shortcut = KeyCombination.create(shortcut); } return this; }
protected void setContextMenuButtonCaption(CubaButton button, String caption, KeyCombination shortcutCombination) { if (!Strings.isNullOrEmpty(caption) && shortcutCombination != null) { caption = caption + " (" + shortcutCombination.format() + ")"; } button.setCaption(caption); }
private void addAlternativeShortcut(KeyCombination kc) { Action alternativeAction = null; for (Action action : getActions()) { // find last action with same shortcut if (kc.equals(action.getShortcutCombination())) { alternativeAction = action; } } if (alternativeAction != null) { addShortcut(alternativeAction.getId(), alternativeAction.getShortcutCombination()); } }
protected Action getEnterAction() { for (Action action : getActions()) { KeyCombination kc = action.getShortcutCombination(); if (kc != null) { if ((kc.getModifiers() == null || kc.getModifiers().length == 0) && kc.getKey() == KeyCombination.Key.ENTER) { return action; } } } return null; }
public SideMenuShortcutListener(SideMenu.MenuItem menuItem, MenuItem item) { super("shortcut_" + item.getId(), item.getShortcut().getKey().getCode(), getShortcutModifiers(item.getShortcut().getModifiers())); this.menuItem = menuItem; }
/** * Set shortcut using fluent API method. * * @param shortcut shortcut * @return current instance of action */ public ListAction withShortcut(String shortcut) { if (shortcut != null) { this.shortcut = KeyCombination.create(shortcut); } return this; }
public void setCaption(String caption) { if (action.getShortcutCombination() != null) { StringBuilder sb = new StringBuilder(); sb.append(caption); if (action.getShortcutCombination() != null) { sb.append(" (").append(action.getShortcutCombination().format()).append(")"); } caption = sb.toString(); } menuItem.setText(caption); } }
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); } } } }
protected ShortcutListener createCloseShortcut(RootWindow topLevelWindow) { Configuration configuration = beanLocator.get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); String closeShortcut = clientConfig.getCloseShortcut(); KeyCombination combination = KeyCombination.create(closeShortcut); return new ShortcutListenerDelegate("onClose", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers())) .withHandler((sender, target) -> closeWindowByShortcut(topLevelWindow) ); }
public ContainerShortcutActionWrapper(ShortcutAction action, ComponentContainer container, KeyCombination keyCombination) { super(null, keyCombination.getKey().getCode(), KeyCombination.Modifier.codes(keyCombination.getModifiers())); this.action = action; this.keyCombination = keyCombination; this.container = container; }
public ShortcutAction(String shortcut, Consumer<ShortcutTriggeredEvent> handler) { this(KeyCombination.create(shortcut), handler); }
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()); } } }
/** * Adds ESCAPE shortcut that invokes cancel() method. */ protected void initShortcuts() { ComponentContainer editBox = getEditBox(); if (editBox instanceof ShortcutNotifier) { ((ShortcutNotifier) editBox).addShortcutAction( new ShortcutAction(new KeyCombination(KeyCombination.Key.ESCAPE), shortcutTriggeredEvent -> cancel())); } }
protected void setupDialogShortcuts() { ClientConfig clientConfig = getClientConfig(); String closeShortcut = clientConfig.getCloseShortcut(); KeyCombination closeCombination = KeyCombination.create(closeShortcut); ShortcutListenerDelegate exitAction = new ShortcutListenerDelegate( "closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()) ); exitAction.withHandler(this::onCloseShortcutTriggered); dialogWindow.addActionHandler(new com.vaadin.event.Action.Handler() { @Override public com.vaadin.event.Action[] getActions(Object target, Object sender) { return new ShortcutAction[]{exitAction}; } @Override public void handleAction(com.vaadin.event.Action action, Object sender, Object target) { if (action == exitAction) { exitAction.handleAction(sender, target); } } }); }
protected com.vaadin.event.ShortcutAction createShortcutAction(com.haulmont.cuba.gui.components.Action action) { KeyCombination keyCombination = action.getShortcutCombination(); if (keyCombination != null) { return new com.vaadin.event.ShortcutAction( action.getCaption(), keyCombination.getKey().getCode(), KeyCombination.Modifier.codes(keyCombination.getModifiers()) ); } else { return null; } }