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);
}
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();
}
}
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;
}
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;
}
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;
}
}
Aggregations