@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); }
@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); } } }
newName = newName + commandType.get().getDisplayName();
@Override public Promise<CommandImpl> createCommand( String goalId, String typeId, @Nullable String name, @Nullable String commandLine, Map<String, String> attributes, ApplicableContext context) { final Map<String, String> attr = new HashMap<>(attributes); attr.put(COMMAND_GOAL_ATTRIBUTE_NAME, goalId); final Optional<CommandType> commandType = commandTypeRegistry.getCommandTypeById(typeId); commandType.ifPresent( type -> attr.put( COMMAND_PREVIEW_URL_ATTRIBUTE_NAME, commandType.get().getPreviewUrlTemplate())); final String commandLineTemplate = commandType.map(CommandType::getCommandLineTemplate).orElse(""); return createCommand( new CommandImpl( commandNameGenerator.generate(typeId, name), commandLine != null ? commandLine : commandLineTemplate, typeId, attr, context)); }
/** 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())); }; }