ExecuteDefaultCommandAction() { super("Execute default command of " + goal.getId() + " goal"); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof CommandGoal)) { return false; } CommandGoal other = (CommandGoal) o; return Objects.equals(getId(), other.getId()); }
@Override public String getName() { return getData().getId(); }
@Override public String getName() { return messages.guideItemLabel(goal.getId()); } }
@Inject(optional = true) private void register(Set<CommandGoal> goals) { for (CommandGoal goal : goals) { final String id = goal.getId(); if (!predefinedGoals.containsKey(id)) { predefinedGoals.put(id, goal); } else { Log.warn(getClass(), messages.messageGoalAlreadyRegistered(id)); } } }
@Override public void setAvailableGoals(Set<CommandGoal> goals) { goalsList.clear(); goals.forEach(g -> goalsList.addItem(g.getId())); goalsList.addItem(CREATE_GOAL_ITEM); }
/** Shows the guide of creating a command of the specified {@code goal}. */ public void guide(CommandGoal goal) { workspaceAgentProvider.get().setActivePart(commandsExplorerPresenterProvider.get()); commandManager .createCommand(goal.getId(), "custom") .then( command -> { editorAgentProvider.get().openEditor(nodeFactory.newCommandFileNode(command)); }); } }
private SVGResource getCommandGoalIcon() { final String goalId = commandGoal.getId(); final Icon icon = iconRegistry.getIconIfExist("command.goal." + goalId); if (icon != null) { final SVGImage svgImage = icon.getSVGImage(); if (svgImage != null) { return icon.getSVGResource(); } } return null; } }
/** Creates {@link ExecuteCommandButton} for the given goal and adds button to the panel. */ private void createButton(CommandGoal goal) { ExecuteCommandButton button = buttonFactory.newButton(goal, delegate, getKeyBinding(goal)); goalButtons.put(goal.getId(), button); button.updateTooltip(); buttonsPanel.add(button); }
ExecuteCommandButton( CommandGoal goal, SafeHtml icon, ExecuteCommandButtonItemsProvider itemsProvider, ToolbarMessages messages, ActionManager actionManager, KeyBindingAgent keyBindingAgent, @Nullable CharCodeWithModifiers keyBinding) { super(icon, itemsProvider); this.goal = goal; this.messages = messages; this.keyBinding = keyBinding; if (keyBinding != null) { actionManager.registerAction(ACTION_PREFIX + goal.getId(), new ExecuteDefaultCommandAction()); keyBindingAgent.getGlobal().addKey(keyBinding, ACTION_PREFIX + goal.getId()); } }
/** * Returns the action group which is appropriate for placing the action for executing the given * command. If appropriate action group doesn't exist it will be created and added to the right * place. */ private DefaultActionGroup getActionGroupForCommand(CommandImpl command) { String goalId = command.getGoal(); if (isNullOrEmpty(goalId)) { goalId = goalRegistry.getDefaultGoal().getId(); } DefaultActionGroup commandGoalPopUpGroup = goalPopUpGroups.get(goalId); if (commandGoalPopUpGroup == null) { commandGoalPopUpGroup = goalPopUpGroupFactory.create(goalId); actionManager.registerAction(GOAL_ACTION_GROUP_ID_PREFIX + goalId, commandGoalPopUpGroup); goalPopUpGroups.put(goalId, commandGoalPopUpGroup); commandsActionGroup.add(commandGoalPopUpGroup); } return commandGoalPopUpGroup; }
@Override public void updatePresentation(NodePresentation presentation) { presentation.setPresentableText(getName().toUpperCase() + " (" + commands.size() + ")"); presentation.setPresentableTextCss("font-weight: bold;"); final SVGResource goalIcon = commandUtils.getCommandGoalIcon(getData().getId()); if (goalIcon != null) { presentation.setPresentableIcon(goalIcon); } }
/** * Removes action for executing the given command and removes the appropriate action group in case * it's empty. */ private void removeAction(CommandImpl command) { Action commandAction = commandActions.remove(command.getName()); if (commandAction != null) { removeAction(commandAction); // remove action from it's action group String goalId = command.getGoal(); if (isNullOrEmpty(goalId)) { goalId = goalRegistry.getDefaultGoal().getId(); } DefaultActionGroup goalPopUpGroup = goalPopUpGroups.get(goalId); if (goalPopUpGroup != null) { goalPopUpGroup.remove(commandAction); } } } }
/** Returns the icon for the given command goal ID or {@code null} if none. */ @Nullable public SVGResource getCommandGoalIcon(String goalId) { final Optional<CommandGoal> goalOptional = goalRegistry.getPredefinedGoalById(goalId); if (goalOptional.isPresent()) { final Icon icon = iconRegistry.getIconIfExist("command.goal." + goalOptional.get().getId()); if (icon != null) { final SVGImage svgImage = icon.getSVGImage(); if (svgImage != null) { return icon.getSVGResource(); } } } return null; } }
@Override protected void initialize() { String goal = editedCommand.getGoal(); initialGoal = isNullOrEmpty(goal) ? goalRegistry.getDefaultGoal().getId() : goal; view.setAvailableGoals(goalRegistry.getAllGoals()); view.setGoal(initialGoal); }
@Override public void update(ActionEvent e) { if (getChildrenCount() > 0) { e.getPresentation().setText(commandGoal.getId() + " (" + getChildrenCount() + ")"); } else { e.getPresentation().setEnabledAndVisible(false); } }
/** Updates button's tooltip depending on it's state (what child elements it contains). */ public void updateTooltip() { final Optional<MenuItem> defaultItem = itemsProvider.getDefaultItem(); if (defaultItem.isPresent()) { MenuItem menuItem = defaultItem.get(); String message = ""; if (menuItem instanceof CommandItem) { message = messages.goalButtonTooltipExecute(menuItem.getName()); } else if (menuItem instanceof MachineItem) { MachineItem machineMenuItem = (MachineItem) menuItem; message = messages.goalButtonTooltipExecuteOnMachine( machineMenuItem.getCommand().getName(), machineMenuItem.getName()); } setTooltip(message, keyBinding); } else if (getItemsProvider().containsGuideItemOnly()) { setTooltip(messages.goalButtonTooltipNoCommand(goal.getId()), null); } else { setTooltip(messages.goalButtonTooltipChooseCommand(goal.getId()), null); } }
/** Returns an operation which creates a command with the given context. */ private Operation<CommandType> createCommand(ApplicableContext context) { return selectedCommandType -> { final CommandGoal selectedGoal = view.getSelectedGoal(); if (selectedGoal == null) { return; } commandManager .createCommand(selectedGoal.getId(), selectedCommandType.getId(), context) .then( command -> { refreshViewAndSelectCommand(command); editorAgentProvider.get().openEditor(nodeFactory.newCommandFileNode(command)); }) .catchError(showErrorNotification(messages.unableCreate())); }; }
button.ensureDebugId("command_toolbar-button_" + goal.getId());