Search in sources :

Example 1 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class SelectCommandComboBox method selectLastUsedCommand.

/** Selects last used command. */
private void selectLastUsedCommand() {
    if (commands.isEmpty()) {
        setEmptyCommand();
    } else {
        // for now, we always select first command
        final CommandImpl command = commands.get(0);
        commandsListWidget.selectElement(command.getName(), command.getName());
    }
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl)

Example 2 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class SelectCommandComboBox method setCommands.

/**
     * Sets commands to the widget.
     *
     * @param commands
     *         commands to set
     * @param commandToSelect
     *         command that should be selected or {@code null} if none
     */
private void setCommands(List<CommandImpl> commands, @Nullable CommandImpl commandToSelect) {
    this.commands.clear();
    commandActions.removeAll();
    final DefaultActionGroup commandsList = (DefaultActionGroup) actionManager.getAction(GROUP_COMMANDS_LIST);
    if (commandsList != null) {
        commandActions.addAll(commandsList);
    }
    Collections.sort(commands, new Comparator<CommandImpl>() {

        @Override
        public int compare(CommandImpl o1, CommandImpl o2) {
            return o1.getType().compareTo(o2.getType());
        }
    });
    CommandImpl prevCommand = null;
    for (CommandImpl command : commands) {
        if (prevCommand == null || !command.getType().equals(prevCommand.getType())) {
            CommandType commandType = commandTypeRegistry.getCommandTypeById(command.getType());
            commandActions.addSeparator(commandType.getDisplayName());
        }
        commandActions.add(commandsListWidget.createAction(command.getName(), command.getName()));
        prevCommand = command;
    }
    this.commands.addAll(commands);
    if (commandToSelect != null) {
        setSelectedCommand(commandToSelect);
    } else {
        selectLastUsedCommand();
    }
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) CommandType(org.eclipse.che.ide.api.command.CommandType) DefaultActionGroup(org.eclipse.che.ide.api.action.DefaultActionGroup)

Example 3 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class CommandManagerImpl method executeCommand.

@Override
public void executeCommand(final CommandImpl command, final Machine machine) {
    final String name = command.getName();
    final String type = command.getType();
    final String commandLine = command.getCommandLine();
    final Map<String, String> attributes = command.getAttributes();
    macroProcessor.expandMacros(commandLine).then(new Operation<String>() {

        @Override
        public void apply(String expandedCommandLine) throws OperationException {
            CommandImpl expandedCommand = new CommandImpl(name, expandedCommandLine, type, attributes);
            final CommandOutputConsole console = commandConsoleFactory.create(expandedCommand, machine);
            final String machineId = machine.getId();
            processesPanelPresenter.addCommandOutput(machineId, console);
            execAgentCommandManager.startProcess(machineId, expandedCommand).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessDiedEvent(console.getProcessDiedOperation()).thenIfProcessStdOutEvent(console.getStdOutOperation()).thenIfProcessStdErrEvent(console.getStdErrOperation());
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class CommandManagerImpl method update.

@Override
public Promise<CommandImpl> update(final String commandName, final CommandImpl command) {
    final String name;
    if (commandName.equals(command.getName())) {
        name = commandName;
    } else {
        name = getUniqueCommandName(command.getType(), command.getName());
    }
    final CommandDto commandDto = dtoFactory.createDto(CommandDto.class).withName(name).withCommandLine(command.getCommandLine()).withType(command.getType()).withAttributes(command.getAttributes());
    return workspaceServiceClient.updateCommand(appContext.getWorkspaceId(), commandName, commandDto).then(new Function<WorkspaceDto, CommandImpl>() {

        @Override
        public CommandImpl apply(WorkspaceDto arg) throws FunctionException {
            final CommandImpl updatedCommand = new CommandImpl(commandDto.getName(), command.getCommandLine(), command.getType(), command.getAttributes());
            commands.remove(commandName);
            commands.put(updatedCommand.getName(), updatedCommand);
            fireCommandUpdated(updatedCommand);
            return updatedCommand;
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) FunctionException(org.eclipse.che.api.promises.client.FunctionException) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)

Example 5 with CommandImpl

use of org.eclipse.che.ide.api.command.CommandImpl in project che by eclipse.

the class EditCommandsPresenter method onSaveClicked.

@Override
public void onSaveClicked() {
    final CommandImpl selectedCommand = view.getSelectedCommand();
    if (selectedCommand == null) {
        return;
    }
    updateCommand(selectedCommand).then(new Operation<CommandImpl>() {

        @Override
        public void apply(CommandImpl arg) throws OperationException {
            commandProcessingCallback = getCommandProcessingCallback();
            refreshView();
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

CommandImpl (org.eclipse.che.ide.api.command.CommandImpl)28 OperationException (org.eclipse.che.api.promises.client.OperationException)9 CommandType (org.eclipse.che.ide.api.command.CommandType)6 ArrayList (java.util.ArrayList)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 Test (org.junit.Test)5 TestResult (org.eclipse.che.api.testing.shared.TestResult)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Operation (org.eclipse.che.api.promises.client.Operation)3 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)3 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)3 Matchers.anyString (org.mockito.Matchers.anyString)3 MatchResult (com.google.gwt.regexp.shared.MatchResult)2 Machine (org.eclipse.che.api.core.model.machine.Machine)2 ChoiceDialog (org.eclipse.che.ide.api.dialogs.ChoiceDialog)2 URL (com.google.gwt.http.client.URL)1 RegExp (com.google.gwt.regexp.shared.RegExp)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1