/** Shows the guide of creating a command of the specified {@code goal}. */ public void guide(CommandGoal goal) { workspaceAgentProvider.get().setActivePart(commandsExplorerPresenterProvider.get()); commandManager .createCommand(goal.getId(), "custom") .then( command -> { editorAgentProvider.get().openEditor(nodeFactory.newCommandFileNode(command)); }); } }
/** * Returns promise that resolves preview URL for the given process. Returns promise that rejects * with an error if preview URL isn't available. */ private Promise<String> getPreviewUrlByName(String name) { return commandManager .getCommand(name) .map(CommandImpl::getPreviewURL) .filter(it -> !it.isEmpty()) .map(s -> macroProcessorProvider.get().expandMacros(s)) .orElseGet(() -> promiseProvider.resolve(messages.previewsNotAvailableError())); }
/** * Fetch registered action from command manager and constructs actions which should be registered * in action manager and context menus. */ private void registerActions() { commandManagerProvider.get().getCommands().forEach(ExecuteCommandActionManager.this::addAction); }
@Override public void onCommandRemove(CommandImpl command) { dialogFactory .createConfirmDialog( messages.removeCommandConfirmationTitle(), messages.removeCommandConfirmationMessage(command.getName()), () -> commandManager .removeCommand(command.getName()) .catchError(showErrorNotification(messages.unableRemove())), null) .show(); }
@Override public void update(ActionEvent e) { e.getPresentation().setEnabledAndVisible(commandManager.isCommandApplicable(command)); }
.updateCommand(initialCommandName, editedCommand) .then( arg -> {
/** {@inheritDoc} */ @Override public void actionPerformed(ActionEvent e) { if (activePart instanceof CommandsExplorerPresenter) { CommandImpl command = ((CommandsExplorerView) commandsExplorer.getView()).getSelectedCommand(); if (command != null) { commandManager .removeCommand(command.getName()) .then(this::onSuccess) .catchError(this::onFailure); } } else { deleteResourceManager .delete(true, appContext.getResources()) .then(this::onSuccess) .catchError(this::onFailure); } }
@Override public Set<CommandGoal> getAllGoals() { Set<CommandGoal> goals = getAllPredefinedGoals(); goals.addAll( commandManagerProvider .get() .getCommands() .stream() .map(command -> getGoalForId(command.getGoal())) .collect(toSet())); return goals; }
@Override public void onReRunProcess(Process process) { commandManager .getCommand(process.getName()) .ifPresent( command -> commandExecutorProvider.get().executeCommand(command, process.getMachineName())); }
@Override public void onCommandDuplicate(CommandImpl command) { commandManager .createCommand(command) .then(this::refreshViewAndSelectCommand) .catchError(showErrorNotification(messages.unableDuplicate())); }
private void refreshView() { final Map<CommandGoal, List<CommandImpl>> commandsByGoals = new HashMap<>(); // all predefined command goals must be shown in the view // so populate map by all registered command goals for (CommandGoal goal : goalRegistry.getAllPredefinedGoals()) { commandsByGoals.put(goal, new ArrayList<>()); } commandsByGoals.putAll(commandUtils.groupCommandsByGoal(commandManager.getCommands())); view.setCommands(commandsByGoals); } }
Promise<Optional<VirtualFile>> getResource(String path) { if (path.startsWith("commands/")) { final String commandName = path.substring(path.lastIndexOf('/') + 1); final Optional<CommandImpl> command = commandManager.getCommand(commandName); if (command.isPresent()) { CommandFileNode node = nodeFactory.newCommandFileNode(command.get()); return promiseProvider.resolve(Optional.of(node)); } else { return promiseProvider.reject(new Exception("Command " + commandName + " not found")); } } else { return appContext .getWorkspaceRoot() .getFile(path) .then( (Function<com.google.common.base.Optional<File>, Optional<VirtualFile>>) arg -> ofNullable(arg.orNull())); } } }
/** 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())); }; }
@Override public void onFilterChanged(String filterValue) { final List<CommandImpl> filteredCommands = commandManager.getCommands(); if (!filterValue.isEmpty()) { filteredCommands.removeIf(command -> !containsIgnoreCase(command.getName(), filterValue)); } view.setCommands(commandUtils.groupCommandsByGoal(filteredCommands)); }
@Override public void actionPerformed(ActionEvent event) { if (event.getParameters() == null) { Log.error(getClass(), localizationConstant.runCommandEmptyParamsMessage()); return; } final String name = event.getParameters().get(NAME_PARAM_ID); if (name == null) { Log.error(getClass(), localizationConstant.runCommandEmptyNameMessage()); return; } wsAgentServerUtil .getWsAgentServerMachine() .ifPresent( m -> commandManager .getCommand(name) .ifPresent(command -> commandExecutor.executeCommand(command, m.getName()))); } }
private Promise<CommandImpl> addCommand(Project project, CommandDto commandDto) { final String name = project.getName() + ": " + commandDto.getName(); final String absoluteProjectPath = appContext.getProjectsRoot().append(project.getPath()).toString(); final String commandLine = commandDto.getCommandLine().replaceAll(PROJECT_PATH_MACRO_REGEX, absoluteProjectPath); final CommandImpl command = new CommandImpl( name, commandLine, commandDto.getType(), commandDto.getAttributes(), new ApplicableContext(project.getPath())); return commandManager.createCommand(command); }
commandManagerProvider .get() .getCommands() .stream() .map(CommandImpl::getName)
final String processName = process.getName(); final Optional<CommandImpl> commandOptional = commandManager.getCommand(processName);
public void showDialog() { view.showDialog(); view.setCommands(commandUtils.groupCommandsByGoal(commandManager.getCommands())); }
@Inject public ExecuteCommandPresenter( ExecuteCommandView view, CommandManager commandManager, Provider<CommandExecutor> commandExecutorProvider, CommandCreationGuide commandCreationGuide, RunGoal runGoal, DebugGoal debugGoal, EventBus eventBus) { this.view = view; this.commandExecutorProvider = commandExecutorProvider; this.commandCreationGuide = commandCreationGuide; view.setDelegate(this); goals = new HashSet<>(); goals.add(runGoal); goals.add(debugGoal); eventBus.addHandler( CommandsLoadedEvent.getType(), e -> commandManager.getCommands().forEach(view::addCommand)); eventBus.addHandler(CommandAddedEvent.getType(), e -> view.addCommand(e.getCommand())); eventBus.addHandler(CommandRemovedEvent.getType(), e -> view.removeCommand(e.getCommand())); eventBus.addHandler( CommandUpdatedEvent.getType(), e -> { view.removeCommand(e.getInitialCommand()); view.addCommand(e.getUpdatedCommand()); }); }