@Override public boolean isDirty() { if (editedCommand == null) { return false; } return !(initialGoal.equals(editedCommand.getGoal())); }
/** * 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; }
@Override public Set<CommandGoal> getAllGoals() { Set<CommandGoal> goals = getAllPredefinedGoals(); goals.addAll( commandManagerProvider .get() .getCommands() .stream() .map(command -> getGoalForId(command.getGoal())) .collect(toSet())); return goals; }
@Override public void addCommand(CommandImpl command) { final ExecuteCommandButton button = goalButtons.get(command.getGoal()); if (button == null) { return; } ExecuteCommandButtonItemsProvider itemsProvider = button.getItemsProvider(); itemsProvider.addCommand(command); button.updateTooltip(); }
@Override public void removeCommand(CommandImpl command) { final ExecuteCommandButton button = goalButtons.get(command.getGoal()); if (button == null) { return; } ExecuteCommandButtonItemsProvider itemsProvider = button.getItemsProvider(); itemsProvider.removeCommand(command); button.updateTooltip(); }
/** * 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; }
/** * 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); } } } }
@Override protected void initialize() { String goal = editedCommand.getGoal(); initialGoal = isNullOrEmpty(goal) ? goalRegistry.getDefaultGoal().getId() : goal; view.setAvailableGoals(goalRegistry.getAllGoals()); view.setGoal(initialGoal); }