@Inject(optional = true) private void register(Set<CommandType> commandTypes) { for (CommandType type : commandTypes) { final String id = type.getId(); if (this.commandTypes.containsKey(id)) { Log.warn(getClass(), messages.typeRegistryMessageAlreadyRegistered(id)); } else { this.commandTypes.put(id, type); } } }
@Override public void setCommandTypes(List<CommandType> commandTypes) { typesList.clear(); commandTypesById.clear(); commandTypes.forEach( commandType -> { commandTypesById.put(commandType.getId(), commandType); typesList.addItem(commandType.getDisplayName(), commandType.getId()); }); typesList.setVisibleItemCount(commandTypes.size()); typesList.setSelectedIndex(0); }
/** Returns the icon for the given command type ID or {@code null} if none. */ @Nullable public SVGResource getCommandTypeIcon(String typeId) { final Optional<CommandType> commandType = commandTypeRegistry.getCommandTypeById(typeId); if (commandType.isPresent()) { final Icon icon = iconRegistry.getIconIfExist("command.type." + commandType.get().getId()); if (icon != null) { final SVGImage svgImage = icon.getSVGImage(); if (svgImage != null) { return icon.getSVGResource(); } } } return 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())); }; }