/** * 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; }
/** * 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 ShortcutAction(String shortcut, Consumer<ShortcutTriggeredEvent> handler) { this(KeyCombination.create(shortcut), handler); }
protected AbstractAction(String id, @Nullable String shortcut) { this(id); if (shortcut != null) { this.shortcut = KeyCombination.create(shortcut); } }
protected BaseAction(String id, @Nullable String shortcut) { // do not init messages in parent class super(); this.id = id; if (shortcut != null) { this.shortcut = KeyCombination.create(shortcut); } }
protected void loadShortcut(MenuItem menuItem, Element element) { String shortcut = element.attributeValue("shortcut"); if (shortcut == null || shortcut.isEmpty()) { return; } // If the shortcut string looks like a property, try to get it from the application properties if (shortcut.startsWith("${") && shortcut.endsWith("}")) { String property = AppContext.getProperty(shortcut.substring(2, shortcut.length() - 1)); if (!StringUtils.isEmpty(property)) shortcut = property; else return; } try { menuItem.setShortcut(KeyCombination.create(shortcut)); } catch (IllegalArgumentException e) { log.warn("Invalid menu shortcut value: '" + shortcut + "'"); } } }
@Override public void setShortcut(String shortcut) { if (shortcut != null) { setShortcutCombination(KeyCombination.create(shortcut)); } else { setShortcutCombination(null); } }
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 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) ); }
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 void initShortcuts() { String closeShortcut = clientConfig.getCloseShortcut(); KeyCombination closeCombination = KeyCombination.create(closeShortcut); window.addAction( new ShortcutListenerDelegate("Esc", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()) ).withHandler((sender, target) -> window.close() )); window.addAction(new ShortcutListenerDelegate("Enter", com.vaadin.event.ShortcutAction.KeyCode.ENTER, null) .withHandler((sender, target) -> window.close() )); } }
protected ShortcutListener createNextWindowTabShortcut(RootWindow topLevelWindow) { Configuration configuration = beanLocator.get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); String nextTabShortcut = clientConfig.getNextTabShortcut(); KeyCombination combination = KeyCombination.create(nextTabShortcut); return new ShortcutListenerDelegate( "onNextTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers()) ).withHandler((sender, target) -> { TabSheetBehaviour tabSheet = getTabbedWindowContainer().getTabSheetBehaviour(); if (tabSheet != null && !hasModalWindow() && tabSheet.getComponentCount() > 1) { com.vaadin.ui.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); } }); }
protected ShortcutListener createPreviousWindowTabShortcut(RootWindow topLevelWindow) { Configuration configuration = beanLocator.get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); String previousTabShortcut = clientConfig.getPreviousTabShortcut(); KeyCombination combination = KeyCombination.create(previousTabShortcut); return new ShortcutListenerDelegate("onPreviousTab", combination.getKey().getCode(), KeyCombination.Modifier.codes(combination.getModifiers()) ).withHandler((sender, target) -> { TabSheetBehaviour tabSheet = getTabbedWindowContainer().getTabSheetBehaviour(); if (tabSheet != null && !hasModalWindow() && tabSheet.getComponentCount() > 1) { com.vaadin.ui.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); } }); }
KeyCombination closeCombination = KeyCombination.create(closeShortcut);
KeyCombination closeCombination = KeyCombination.create(closeShortcut);