@Override public String toString() { return getCommandID(); }
/** * Gets the key for the given command command-ID and command property name name as used in the resource bundle for * this application. */ protected String createResourceKey(String commandPropertyName) { return String.format("command.%s.%s", getCommandID(), commandPropertyName); }
/** * Removes an existing command from this command manager. * * @param command the command to be removed */ @Override public void removeCommand(Command command) { String commandKey = command.getCommandID(); commandMap.remove(commandKey); commandList.remove(command); }
public void removeAction(String actionId) { for (int i = 0; i < actionList.size(); i++) { Command command = actionList.get(i); if (actionId.equals(command.getCommandID())) { actionList.remove(i); return; } } }
public void removeActionGroup(String actionGroupId) { for (int i = 0; i < actionGroupList.size(); i++) { Command command = actionGroupList.get(i); if (actionGroupId.equals(command.getCommandID())) { actionGroupList.remove(i); return; } } }
@Override public int compare(Command command1, Command command2) { if (command1.getText() == null || command2.getText() == null) { return command1.getCommandID().compareTo(command2.getCommandID()); } return command1.getText().compareTo(command2.getText()); } }
private void registerActions(ModuleContext moduleContext) { actionList = BeamCoreActivator.loadExecutableExtensions(moduleContext, "actions", "action", Command.class); HashMap<String, Command> actionMap = new HashMap<>(2 * actionList.size() + 1); for (Command action : new ArrayList<>(actionList)) { final String actionId = action.getCommandID(); final Command existingAction = actionMap.get(actionId); if (existingAction != null) { moduleContext.getLogger().warning(String.format("Action [%s] has been redeclared!\n", actionId)); actionMap.remove(actionId); actionList.remove(existingAction); } actionMap.put(actionId, action); } }
private static void repopulatePopMenu(JPopupMenu popupMenu, ArrayList<Command> commands, Map<String, JMenuItem> menuItemMap) { popupMenu.removeAll(); for (int i = 0; i < commands.size(); i++) { Command command = commands.get(i); JMenuItem menuItem = menuItemMap.get(command.getCommandID()); Assert.state(menuItem != null); int componentCount = popupMenu.getComponentCount(); if (command.isSeparatorBefore() && componentCount > 0 && !(popupMenu.getComponent(componentCount - 1) instanceof JSeparator)) { popupMenu.addSeparator(); } popupMenu.add(menuItem); if (command.isSeparatorAfter() && i < commands.size() - 1) { popupMenu.addSeparator(); } } }
private void loadCommands() { CommandManager commandManager = getCommandManager(); List<Command> commands = VisatActivator.getInstance().getCommands(); Map<String, Command> commandMap = new HashMap<>(commands.size() * 2 + 1); for (Command command : commands) { commandMap.put(command.getCommandID(), command); } for (Command command : commands) { addCommand(commandManager, command, commandMap); } setSelectToolSelectState(commandManager); }
private static void addCommand(CommandManager commandManager, Command command, Map<String, Command> commandMap) { String parentId = command.getParent(); if (parentId != null && commandManager.getCommandGroup(parentId) == null) { Command parentCommand = commandMap.get(parentId); if (parentCommand != null) { // solve dependencies to other command groups addCommand(commandManager, parentCommand, commandMap); } } Command existingCommand = commandManager.getCommand(command.getCommandID()); if (existingCommand == null) { commandManager.addCommand(command); } }
@Test public void testSortByAnchor_BeforeAndLast_3() { List<Command> commands = toList(createCommand("a", BEFORE, "c"), createCommand("b", BEFORE, "c"), createCommand("c", LAST)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_FirstOnly_3() { List<Command> commands = toList(createCommand("a", FIRST), createCommand("b", FIRST), createCommand("c", FIRST)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_LastOnly_3() { List<Command> commands = toList(createCommand("a", LAST), createCommand("b", LAST), createCommand("c", LAST)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_FirstAndAfter_3() { List<Command> commands = toList(createCommand("a", FIRST), createCommand("b", AFTER, "a"), createCommand("c", AFTER, "a")); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_NoneAndAfter_3() { List<Command> commands = toList(createCommand("a"), createCommand("b", AFTER, "a"), createCommand("c", AFTER, "b")); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_AllKinds_4() { List<Command> commands = toList(createCommand("a", FIRST), createCommand("b", AFTER, "a"), createCommand("c", BEFORE, "d"), createCommand("d", LAST, null)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); assertEquals("d", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_NoneAndAfter_5() { List<Command> commands = toList(createCommand("a"), createCommand("b", AFTER, "a"), createCommand("c", AFTER, "b"), createCommand("d", AFTER, "c"), createCommand("e", AFTER, "d")); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); assertEquals("c", commands.get(index++).getCommandID()); assertEquals("d", commands.get(index++).getCommandID()); assertEquals("e", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_FirstAndLast_2() { List<Command> commands = toList(createCommand("a", FIRST), createCommand("b", LAST)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_BeforeAndLast_2() { List<Command> commands = toList(createCommand("a", BEFORE, "b"), createCommand("b", LAST, null)); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); }
@Test public void testSortByAnchor_NoneAndAfter_2() { List<Command> commands = toList(createCommand("a"), createCommand("b", AFTER, "a")); reverseList(commands); sortCommandsByAnchor(commands); int index = 0; assertEquals("a", commands.get(index++).getCommandID()); assertEquals("b", commands.get(index++).getCommandID()); }