private void enableHelp(Component menu, Command command) { HelpSys.enableHelp(menu, command.getHelpId()); }
@Override public String toString() { return getCommandID(); }
protected Object getProperty(String key) { return getAction().getValue(key); }
@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 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 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); } }
for (int i = 0; i < numCommands; i++) { final Command command = _commandManager.getCommandAt(i); final String commandID = command.getCommandID(); if (command.containsContext(context) && (command.isEnabled() || _showingDisabledMenuItems) && !existingCommands.contains(commandID)) { existingCommands.add(commandID); final JMenuItem item = command.createMenuItem(); String popupText = command.getPopupText(); if (popupText != null && popupText.length() > 0) { item.setText(popupText); if (command.isPlaceAtContextTop()) { popup.insert(item, 0); if (command.isSeparatorAfter()) { popup.insert(new JPopupMenu.Separator(), 1);
ArrayList<Command> betweenCommands = new ArrayList<>(commands); for (Command command : commands) { if (command.getPlaceFirst()) { firstCommands.add(command); betweenCommands.remove(command); } else if (command.getPlaceLast() || (command.getPlaceBefore() == null && command.getPlaceAfter() == null)) { lastCommands.add(command); betweenCommands.remove(command); commandMap.put(command.getCommandID(), command); for (Command command : commands) { String placeBefore = command.getPlaceBefore(); if (placeBefore != null) { int index = sortedCommands.indexOf(command); String placeAfter = command.getPlaceAfter(); if (placeAfter != null) { int index = sortedCommands.indexOf(command);
private static void insertCommandIntoMenu(Command newCommand, JMenu menu, CommandManager commandManager) { JMenuItem newMenuItem = newCommand.createMenuItem(); if (newMenuItem == null) { return; Map<String, JMenuItem> menuItemMap = new HashMap<>(); commandMap.put(newCommand.getCommandID(), newCommand); menuItemMap.put(newCommand.getCommandID(), newMenuItem); BeamLogManager.getSystemLogger().fine(String.format("Inserting command '%s' into menu '%s' with %d item(s)", newCommand.getCommandID(), menu.getName(), componentCount));
@Test public void testAddContextDependingMenuItems() { DefaultCommandManager manager = new DefaultCommandManager(); createCommand("com1", manager); createCommand("com2", manager); createCommand("com3", manager); manager.getCommandAt(0).setProperty(Command.ACTION_KEY_CONTEXT, "image"); manager.getCommandAt(1).setProperty(Command.ACTION_KEY_CONTEXT, "notImage"); manager.getCommandAt(2).setProperty(Command.ACTION_KEY_CONTEXT, "image"); manager.getCommandAt(2).setEnabled(false); DefaultCommandUIFactory uiFactory = new DefaultCommandUIFactory(); uiFactory.setCommandManager(manager); JPopupMenu menu = uiFactory.addContextDependentMenuItems("image", new JPopupMenu()); assertEquals(2, menu.getComponentCount()); menu = uiFactory.addContextDependentMenuItems("notImage", new JPopupMenu()); assertEquals(1, menu.getComponentCount()); }
public RoiMaskSelector(BindingContext bindingContext) { this(bindingContext, VisatApp.getApp().getCommandManager().getCommand("org.esa.beam.visat.toolviews.mask.MaskManagerToolView.showCmd").createToolBarButton()); }
@Override public void updateState(CommandEvent event) { final ProductNode node = VisatApp.getApp().getSelectedProductNode(); event.getCommand().setEnabled(node instanceof Band); }
protected final void insertCommandToolBarButtons(JToolBar toolbar) { String[] toolBarGroups = getToolBarGroups(); if (toolBarGroups == null) { return; } boolean toolAdded = false; for (String toolBarGroup : toolBarGroups) { if (toolAdded) { toolbar.addSeparator(); toolAdded = false; } for (int j = 0; j < commandManager.getNumCommands(); j++) { Command command = commandManager.getCommandAt(j); // @todo 2 nf/nf - ask whether location=toolbar or not if (command instanceof ExecCommand && command.getLargeIcon() != null) { String rootParent = findRootParent(command); if ((rootParent == null && toolBarGroup == null) || (rootParent != null && rootParent.equalsIgnoreCase(toolBarGroup))) { AbstractButton button = command.createToolBarButton(); if (button != null) { toolbar.add(button); } toolAdded = true; } } } } }
private String findRootParent(Command command) { String parent = command.getParent(); if (parent != null) { CommandGroup commandGroup = commandManager.getCommandGroup(parent); if (commandGroup != null) { return findRootParent(commandGroup); } } return parent; }
/** * Notify all listeners that have registered interest for notification on the 'update status' event type. The event * instance is lazily created using the parameters passed into the fire method. */ protected void fireUpdateState() { if (getEventListenerList() == null) { return; } // Guaranteed to return a non-null array Object[] listeners = getEventListenerList().getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event CommandEvent commandEvent = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == CommandListener.class || listeners[i] == CommandStateListener.class) { // Lazily create the event: if (commandEvent == null) { commandEvent = new CommandEvent(this, null, null, null); } ((CommandStateListener) listeners[i + 1]).updateState(commandEvent); } } }
/** * Creates a tool button for the tool-command with the given command ID. * <p/> * <p>A command with the given ID must already been registered using any of the <code>createToolCommand</code> * methods of VisatApp, or directly using the <code>createToolCommand</code> method of VISAT's {@link * CommandManager}. Otherwise an {@link IllegalArgumentException} will be thrown. * <p/> * <p>The new button is which is automatically added to VISAT's tool button group to ensure that a only single tool * is selected. * * @param commandID the command ID * @return a tool button which is automatically added to VISAT's tool button group. * @see #getCommandManager */ public AbstractButton createToolButton(final String commandID) { final Command command = getCommandManager().getCommand(commandID); Guardian.assertNotNull("command", command); return command.createToolBarButton(); }
@Override public void updateState(CommandEvent event) { event.getCommand().setEnabled(VisatApp.getApp().getSelectedProductSceneView() != null); }
protected final void insertCommandMenuItem(Command command) { JMenu menu = null; String parent = command.getParent(); if (parent != null) { menu = findMenu(parent); } if (menu == null) { menu = createNewMenu(parent); } if (menu != null) { commandMenuInserter.insertCommandIntoMenu(command, menu); } }
public void testCreateCommandWithConstraintsAndListener() { final CommandListener listener = new CommandListener() { public void actionPerformed(CommandEvent event) { } public void updateState(CommandEvent event) { } }; ExecCommand command = createCommand("test"); command.addCommandListener(listener); _manager.addCommand(command); final Command commandAt = _manager.getCommandAt(0); final CommandListener[] listeners = (CommandListener[]) commandAt.getEventListenerList().getListeners( CommandListener.class); assertEquals(1, listeners.length); assertSame(listener, listeners[0]); }
@Override public void actionPerformed(final CommandEvent event) { VisatApp.getApp().showPreferencesDialog(event.getCommand().getHelpId()); }