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);
}
}
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);
}
}
}
}
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);
}
}
}
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());
}
}
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());
}
}
}
Aggregations