/** Creates copy of the given {@code command}. */ public CommandImpl(CommandImpl command) { this( command.getName(), command.getCommandLine(), command.getType(), new HashMap<>(command.getAttributes()), new ApplicableContext(command.getApplicableContext())); }
@Inject ExecuteCommandAction( @Assisted CommandImpl command, CommandUtils commandUtils, CommandExecutor commandExecutor, CommandManager commandManager) { super(command.getName()); this.command = command; this.commandExecutor = commandExecutor; this.commandManager = commandManager; final SVGResource commandIcon = commandUtils.getCommandTypeIcon(command.getType()); if (commandIcon != null) { getTemplatePresentation().setImageElement(new SVGImage(commandIcon).getElement()); } }
@Override public Path getLocation() { return Path.valueOf("commands/" + getData().getType() + "/" + getData().getName()); }
@Override public void updatePresentation(NodePresentation presentation) { presentation.setPresentableText(getName()); final SVGResource commandTypeIcon = commandUtils.getCommandTypeIcon(getData().getType()); if (commandTypeIcon != null) { presentation.setPresentableIcon(commandTypeIcon); } }
/** Updates the specified {@code project} with the given {@code commands}. */ private Promise<Void> updateProject(Project project, List<CommandImpl> commands) { MutableProjectConfig config = new MutableProjectConfig(project); Map<String, List<String>> attributes = config.getAttributes(); List<String> attrValue = new ArrayList<>(attributes.size()); for (CommandImpl command : commands) { CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(command.getName()) .withType(command.getType()) .withCommandLine(command.getCommandLine()) .withAttributes(command.getAttributes()); attrValue.add(dtoFactory.toJson(commandDto)); } attributes.put(COMMANDS_ATTRIBUTE_NAME, attrValue); return project.update().withBody(config).send().then((Function<Project, Void>) arg -> null); }
@Nullable @Override public SVGResource getTitleImage() { final VirtualFile file = getEditorInput().getFile(); if (file instanceof CommandFileNode) { final CommandImpl command = ((CommandFileNode) file).getData(); final Icon icon = iconRegistry.getIconIfExist("command.type." + command.getType()); if (icon != null) { final SVGImage svgImage = icon.getSVGImage(); if (svgImage != null) { return icon.getSVGResource(); } } } return input.getSVGResource(); }
newCommand.setName(commandNameGenerator.generate(command.getType(), command.getName()));
/** * Adds command to workspace * * @param wsId workspace ID * @param newCommand the new workspace command * @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error */ public Promise<WorkspaceImpl> addCommand(String wsId, CommandImpl newCommand) { final String url = baseHttpUrl + '/' + wsId + "/command"; final CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(newCommand.getName()) .withCommandLine(newCommand.getCommandLine()) .withType(newCommand.getType()) .withAttributes(newCommand.getAttributes()); return asyncRequestFactory .createPostRequest(url, commandDto) .header(ACCEPT, APPLICATION_JSON) .header(CONTENT_TYPE, APPLICATION_JSON) .loader(loaderFactory.newLoader("Adding command...")) .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)) .then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new); }
/** * Updates command. * * @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error */ public Promise<WorkspaceImpl> updateCommand( String wsId, String commandName, CommandImpl commandUpdate) { final String url = baseHttpUrl + '/' + wsId + "/command/" + URL.encodePathSegment(commandName); final CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(commandUpdate.getName()) .withCommandLine(commandUpdate.getCommandLine()) .withType(commandUpdate.getType()) .withAttributes(commandUpdate.getAttributes()); return asyncRequestFactory .createRequest(PUT, url, commandDto, false) .header(ACCEPT, APPLICATION_JSON) .header(CONTENT_TYPE, APPLICATION_JSON) .loader(loaderFactory.newLoader("Updating command...")) .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)) .then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new); }