@Override protected void initialize() { String goal = editedCommand.getGoal(); initialGoal = isNullOrEmpty(goal) ? goalRegistry.getDefaultGoal().getId() : goal; view.setAvailableGoals(goalRegistry.getAllGoals()); view.setGoal(initialGoal); }
private void refreshView() { final Map<CommandGoal, List<CommandImpl>> commandsByGoals = new HashMap<>(); // all predefined command goals must be shown in the view // so populate map by all registered command goals for (CommandGoal goal : goalRegistry.getAllPredefinedGoals()) { commandsByGoals.put(goal, new ArrayList<>()); } commandsByGoals.putAll(commandUtils.groupCommandsByGoal(commandManager.getCommands())); view.setCommands(commandsByGoals); } }
/** Set the specified goal name for the currently edited command. */ private void setGoal(String goalName) { editedCommand.setGoal(goalName); Set<CommandGoal> allGoals = goalRegistry.getAllGoals(); allGoals.add(goalRegistry.getGoalForId(goalName)); view.setAvailableGoals(allGoals); view.setGoal(goalName); notifyDirtyStateChanged(); }
/** * Groups the given {@code commands} by its goal. * * @return map that contains the given {@code commands} grouped by its goal */ public Map<CommandGoal, List<CommandImpl>> groupCommandsByGoal(List<CommandImpl> commands) { final Map<CommandGoal, List<CommandImpl>> commandsByGoal = new HashMap<>(); for (CommandImpl command : commands) { final String goalId = command.getGoal(); final CommandGoal commandGoal = goalRegistry.getGoalForId(goalId); commandsByGoal.computeIfAbsent(commandGoal, key -> new ArrayList<>()).add(command); } return commandsByGoal; }
/** * 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; }
/** 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; } }
final String newGoalName = value.trim(); final Set<CommandGoal> allGoals = goalRegistry.getAllGoals();
@Inject GoalPopUpGroup( @Assisted String goalId, ActionManager actionManager, CommandGoalRegistry goalRegistry, IconRegistry iconRegistry) { super(actionManager); this.iconRegistry = iconRegistry; commandGoal = goalRegistry.getGoalForId(goalId); setPopup(true); // set icon final SVGResource commandTypeIcon = getCommandGoalIcon(); if (commandTypeIcon != null) { getTemplatePresentation().setImageElement(new SVGImage(commandTypeIcon).getElement()); } }
/** * 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); } } } }