protected void loadStandardActionProperties(Action instance, Element element) { String enable = element.attributeValue("enable"); if (StringUtils.isNotEmpty(enable)) { instance.setEnabled(Boolean.parseBoolean(enable)); } String visible = element.attributeValue("visible"); if (StringUtils.isNotEmpty(visible)) { instance.setVisible(Boolean.parseBoolean(visible)); } String caption = element.attributeValue("caption"); if (caption != null) { instance.setCaption(loadResourceString(caption)); } String description = element.attributeValue("description"); if (StringUtils.isNotEmpty(description)) { instance.setDescription(loadResourceString(description)); } String icon = element.attributeValue("icon"); if (StringUtils.isNotEmpty(icon)) { instance.setIcon(getIconPath(icon)); } }
protected void setPickerButtonAction(CubaButton button, Action action) { String description = action.getDescription(); if (description == null && action.getShortcutCombination() != null) { description = action.getShortcutCombination().format(); } if (description != null) { button.setDescription(description); } button.setEnabled(action.isEnabled()); button.setVisible(action.isVisible()); if (action.getIcon() != null) { setPickerButtonIcon(button, action.getIcon()); } AppUI ui = AppUI.getCurrent(); if (ui != null && ui.isTestMode()) { button.setCubaId(action.getId()); } action.addPropertyChangeListener(actionPropertyChangeListener); button.setClickHandler(event -> { this.focus(); action.actionPerform(this); }); }
protected void attachAction(Action action) { action.refreshState(); }
@Override public void handleAction(com.vaadin.event.Action actionImpl, Object sender, Object target) { Action cubaAction = getAction(actionImpl); if (cubaAction != null && cubaAction.isEnabled() && cubaAction.isVisible()) { cubaAction.actionPerform(actionSource); } } }
protected void setContextMenuButtonAction(CubaButton button, Action action) { setContextMenuButtonIcon(button, showIconsForPopupMenuActions ? action.getIcon() : null); setContextMenuButtonCaption(button, action.getCaption(), action.getShortcutCombination()); button.setDescription(action.getDescription()); button.setEnabled(action.isEnabled()); button.setVisible(action.isVisible()); action.addPropertyChangeListener(actionPropertyChangeListener); button.setClickHandler(event -> { beforeContextMenuButtonHandlerPerformed(); action.actionPerform(WebAbstractActionsHolderComponent.this); }); }
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()); } }
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); String caption = action.getCaption(); if (caption != null && component.getCaption() == null) { component.setCaption(caption); String description = action.getDescription(); if (description == null && action.getShortcutCombination() != null) { description = action.getShortcutCombination().format(); component.setEnabled(action.isEnabled()); component.setVisible(action.isVisible()); if (action.getIcon() != null && getIcon() == null) { setIcon(action.getIcon()); action.addOwner(this);
protected void actionPropertyChanged(PropertyChangeEvent evt) { Action action = (Action) evt.getSource(); CubaButton button = actionButtons.get(action); if (Action.PROP_ICON.equals(evt.getPropertyName())) { setContextMenuButtonIcon(button, showIconsForPopupMenuActions ? action.getIcon() : null); } else if (Action.PROP_CAPTION.equals(evt.getPropertyName())) { setContextMenuButtonCaption(button, action.getCaption(), action.getShortcutCombination()); } else if (Action.PROP_DESCRIPTION.equals(evt.getPropertyName())) { button.setDescription(action.getDescription()); } else if (Action.PROP_ENABLED.equals(evt.getPropertyName())) { button.setEnabled(action.isEnabled()); } else if (Action.PROP_VISIBLE.equals(evt.getPropertyName())) { button.setVisible(action.isVisible()); } }
@Override public void setSelectHandler(Consumer<Collection<T>> selectHandler) { this.selectHandler = selectHandler; Component lookupActionsLayout = getLookupActionsLayout(); if (lookupActionsLayout != null) { lookupActionsLayout.setVisible(true); Component lookupComponent = getLookupComponent(); if (lookupComponent instanceof LookupSelectionChangeNotifier) { LookupSelectionChangeNotifier selectionNotifier = (LookupSelectionChangeNotifier) lookupComponent; Action commitAction = getWindow().getAction(LOOKUP_SELECT_ACTION_ID); if (commitAction != null) { //noinspection unchecked selectionNotifier.addLookupValueChangeListener(valueChangeEvent -> commitAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty())); commitAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty()); } } } }
@Override @Nullable public Action getAction(String id) { for (Action action : actions) { if (Objects.equals(id, action.getId())) { return action; } } return null; }
public void setAction(Action action) { if (this.action != action) { if (this.action != null) { this.action.removePropertyChangeListener(actionPropertyChangeListener); String caption = action.getCaption(); if (!StringUtils.isEmpty(caption)) { setCaption(caption); menuItem.setEnabled(action.isEnabled()); menuItem.setVisible(action.isVisible()); if (action.getIcon() != null) { setIcon(action.getIcon()); setIcon(this.action.getIcon()); } else if (Action.PROP_CAPTION.equals(evt.getPropertyName())) { setCaption(this.action.getCaption()); } else if (Action.PROP_ENABLED.equals(evt.getPropertyName())) { setEnabled(this.action.isEnabled()); } else if (Action.PROP_VISIBLE.equals(evt.getPropertyName())) { setVisible(this.action.isVisible()); action.addPropertyChangeListener(actionPropertyChangeListener);
action.setCaption(""); action.setIcon("icons/trash.png");
public void addAction(Action action, int index) { int oldIndex = findActionById(actionList, action.getId()); if (oldIndex >= 0) { removeAction(actionList.get(oldIndex)); if (index > oldIndex) { index--; } } if (action.getShortcutCombination() != null) { actions.put(createShortcutAction(action), action); } actionList.add(index, action); action.addPropertyChangeListener(actionPropertyChangeListener); }
@Override public void performAction(Action action) { action.actionPerform(WebAbstractDataGrid.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); } }
protected void handleClickAction() { Action action = getItemClickAction(); if (action == null) { action = getEnterPressAction(); if (action == null) { action = getAction("edit"); if (action == null) { action = getAction("view"); } } } if (action != null && action.isEnabled()) { action.actionPerform(this); } }
@Override public void addAction(Action action, int index) { checkNotNullArgument(action, "action must be non null"); int oldIndex = findActionById(actionList, action.getId()); if (oldIndex >= 0) { removeAction(actionList.get(oldIndex)); if (index > oldIndex) { index--; } } if (StringUtils.isNotEmpty(action.getCaption())) { CubaButton contextMenuButton = createContextMenuButton(); initContextMenuButton(contextMenuButton, action); int visibleActionsIndex = 0; int i = 0; while (i < index && i < actionList.size()) { if (StringUtils.isNotEmpty(actionList.get(i).getCaption())) { visibleActionsIndex++; } i++; } contextMenuPopup.addComponent(contextMenuButton, visibleActionsIndex); actionButtons.put(action, contextMenuButton); } actionList.add(index, action); shortcutsDelegate.addAction(null, action); attachAction(action); actionsPermissions.apply(action); }
@Override public void initLookupLayout() { Action selectAction = getAction(LOOKUP_SELECT_ACTION_ID); if (selectAction != null && selectAction.getOwner() == null) { Fragments fragments = UiControllerUtils.getScreenContext(this).getFragments(); ScreenFragment lookupWindowActions = fragments.create(this, "lookupWindowActions"); lookupWindowActions.getFragment().setId("lookupWindowActions"); lookupWindowActions.getFragment().setVisible(false); getFrame().add(lookupWindowActions.getFragment()); lookupWindowActions.init(); } Element element = ((Component.HasXmlDescriptor) getFrame()).getXmlDescriptor(); if (element != null) { String lookupComponent = element.attributeValue("lookupComponent"); if (StringUtils.isNotEmpty(lookupComponent)) { Component component = getFrame().getComponent(lookupComponent); setLookupComponent(component); } } Component lookupComponent = getLookupComponent(); if (lookupComponent instanceof LookupSelectionChangeNotifier) { LookupSelectionChangeNotifier selectionNotifier = (LookupSelectionChangeNotifier) lookupComponent; if (selectAction != null) { //noinspection unchecked selectionNotifier.addLookupValueChangeListener(valueChangeEvent -> selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty())); selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty()); } } }
button.setClickHandler(mouseEventDetails -> { try { action.actionPerform(ui.getTopLevelWindow()); } finally { ui.removeWindow(window); button.setCubaId("optionDialog_" + action.getId()); button.setId(ui.getTestIdManager().getTestId("optionDialog_" + action.getId()));