Search in sources :

Example 1 with CommandType

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

the class ProcessesPanelPresenterTest method commandShouldBeRestoredWhenWsAgentIsStarted.

@Test
public void commandShouldBeRestoredWhenWsAgentIsStarted() throws Exception {
    WsAgentStateEvent event = mock(WsAgentStateEvent.class);
    MachineEntity machineEntity = mock(MachineEntity.class);
    MachineDto machine = mock(MachineDto.class);
    when(machineEntity.getId()).thenReturn(MACHINE_ID);
    when(machineEntity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(entityFactory.createMachine(machine)).thenReturn(machineEntity);
    MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
    when(machine.getConfig()).thenReturn(machineConfigDto);
    when(machineConfigDto.isDev()).thenReturn(true);
    when(machine.getStatus()).thenReturn(MachineStatus.RUNNING);
    List<MachineDto> machines = new ArrayList<>(2);
    machines.add(machine);
    when(workspaceRuntime.getMachines()).thenReturn(machines);
    MachineProcessDto machineProcessDto = mock(MachineProcessDto.class);
    when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL);
    when(machineProcessDto.getPid()).thenReturn(PID);
    List<MachineProcessDto> processes = new ArrayList<>(1);
    processes.add(machineProcessDto);
    CommandOutputConsole outputConsole = mock(CommandOutputConsole.class);
    CommandType commandType = mock(CommandType.class);
    when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType);
    when(commandConsoleFactory.create(anyObject(), any(org.eclipse.che.api.core.model.machine.Machine.class))).thenReturn(outputConsole);
    presenter.onWsAgentStarted(event);
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) ArrayList(java.util.ArrayList) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) MachineProcessDto(org.eclipse.che.api.machine.shared.dto.MachineProcessDto) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) CommandType(org.eclipse.che.ide.api.command.CommandType) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) Test(org.junit.Test)

Example 2 with CommandType

use of org.eclipse.che.ide.api.command.CommandType 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 CommandType

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

the class EditCommandsViewImpl method createCategoryHeaderForCommandType.

private SpanElement createCategoryHeaderForCommandType(final String commandTypeId) {
    final SpanElement categoryHeaderElement = Document.get().createSpanElement();
    categoryHeaderElement.setClassName(commandResources.getCss().categoryHeader());
    final SpanElement iconElement = Document.get().createSpanElement();
    categoryHeaderElement.appendChild(iconElement);
    final SpanElement nameElement = Document.get().createSpanElement();
    categoryHeaderElement.appendChild(nameElement);
    final CommandType currentCommandType = getTypeById(commandTypeId);
    nameElement.setInnerText(currentCommandType != null ? currentCommandType.getDisplayName() : commandTypeId);
    final SpanElement buttonElement = Document.get().createSpanElement();
    buttonElement.appendChild(commandResources.addCommandButton().getSvg().getElement());
    categoryHeaderElement.appendChild(buttonElement);
    Event.sinkEvents(buttonElement, Event.ONCLICK);
    Event.setEventListener(buttonElement, new EventListener() {

        @Override
        public void onBrowserEvent(Event event) {
            if (Event.ONCLICK == event.getTypeInt()) {
                event.stopPropagation();
                namePanel.setVisible(true);
                previewUrlPanel.setVisible(true);
                selectedType = commandTypeId;
                delegate.onAddClicked();
                resetFilter();
            }
        }
    });
    final Icon icon = iconRegistry.getIconIfExist(commandTypeId + ".commands.category.icon");
    if (icon != null) {
        final SVGImage iconSVG = icon.getSVGImage();
        if (iconSVG != null) {
            iconElement.appendChild(iconSVG.getElement());
            return categoryHeaderElement;
        }
    }
    return categoryHeaderElement;
}
Also used : SpanElement(com.google.gwt.dom.client.SpanElement) CommandType(org.eclipse.che.ide.api.command.CommandType) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyboardEvent(elemental.events.KeyboardEvent) EventListener(com.google.gwt.user.client.EventListener) Icon(org.eclipse.che.ide.api.icon.Icon) SVGImage(org.vectomatic.dom.svg.ui.SVGImage)

Example 4 with CommandType

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

the class CommandManagerImpl method getUniqueCommandName.

private String getUniqueCommandName(String customType, String customName) {
    final CommandType commandType = commandTypeRegistry.getCommandTypeById(customType);
    final Set<String> commandNames = commands.keySet();
    final String newCommandName;
    if (customName == null || customName.isEmpty()) {
        newCommandName = "new" + commandType.getDisplayName();
    } else {
        if (!commandNames.contains(customName)) {
            return customName;
        }
        newCommandName = customName + " copy";
    }
    if (!commandNames.contains(newCommandName)) {
        return newCommandName;
    }
    for (int count = 1; count < 1000; count++) {
        if (!commandNames.contains(newCommandName + "-" + count)) {
            return newCommandName + "-" + count;
        }
    }
    return newCommandName;
}
Also used : CommandType(org.eclipse.che.ide.api.command.CommandType)

Example 5 with CommandType

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

the class EditCommandsPresenter method refreshView.

private void refreshView() {
    reset();
    List<CommandImpl> allCommands = commandManager.getCommands();
    Map<CommandType, List<CommandImpl>> typeToCommands = new HashMap<>();
    for (CommandType type : commandTypeRegistry.getCommandTypes()) {
        final List<CommandImpl> commandsOfType = new ArrayList<>();
        for (CommandImpl command : allCommands) {
            if (type.getId().equals(command.getType())) {
                commandsOfType.add(command);
            }
        }
        Collections.sort(commandsOfType, commandsComparator);
        typeToCommands.put(type, commandsOfType);
    }
    view.setData(typeToCommands);
    view.setFilterState(!allCommands.isEmpty());
    if (commandProcessingCallback != null) {
        commandProcessingCallback.onCompleted();
        commandProcessingCallback = null;
    }
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) HashMap(java.util.HashMap) CommandType(org.eclipse.che.ide.api.command.CommandType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CommandType (org.eclipse.che.ide.api.command.CommandType)9 CommandImpl (org.eclipse.che.ide.api.command.CommandImpl)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 SpanElement (com.google.gwt.dom.client.SpanElement)1 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1 Event (com.google.gwt.user.client.Event)1 EventListener (com.google.gwt.user.client.EventListener)1 KeyboardEvent (elemental.events.KeyboardEvent)1 List (java.util.List)1 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)1 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 MachineProcessDto (org.eclipse.che.api.machine.shared.dto.MachineProcessDto)1 DefaultActionGroup (org.eclipse.che.ide.api.action.DefaultActionGroup)1 Icon (org.eclipse.che.ide.api.icon.Icon)1 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)1 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)1