use of com.google.gwt.user.client.ui.IsWidget in project che by eclipse.
the class ProcessesPanelPresenter method onAddTerminal.
/**
* Adds new terminal to the processes panel
*
* @param machineId
* id of machine in which the terminal will be added
*/
@Override
public void onAddTerminal(final String machineId, Object source) {
final MachineEntity machine = getMachine(machineId);
if (machine == null) {
notificationManager.notify(localizationConstant.failedToConnectTheTerminal(), localizationConstant.machineNotFound(machineId), FAIL, FLOAT_MODE);
Log.error(getClass(), localizationConstant.machineNotFound(machineId));
return;
}
final ProcessTreeNode machineTreeNode = provideMachineNode(machine, false);
final TerminalPresenter newTerminal = terminalFactory.create(machine, source);
final IsWidget terminalWidget = newTerminal.getView();
final String terminalName = getUniqueTerminalName(machineTreeNode);
final ProcessTreeNode terminalNode = new ProcessTreeNode(TERMINAL_NODE, machineTreeNode, terminalName, resources.terminalTreeIcon(), null);
addChildToMachineNode(terminalNode, machineTreeNode);
final String terminalId = terminalNode.getId();
terminals.put(terminalId, newTerminal);
view.addProcessNode(terminalNode);
terminalWidget.asWidget().ensureDebugId(terminalName);
view.addWidget(terminalId, terminalName, terminalNode.getTitleIcon(), terminalWidget, false);
refreshStopButtonState(terminalId);
workspaceAgent.setActivePart(this);
newTerminal.setVisible(true);
newTerminal.connect();
newTerminal.setListener(new TerminalPresenter.TerminalStateListener() {
@Override
public void onExit() {
String terminalId = terminalNode.getId();
if (terminals.containsKey(terminalId)) {
onStopProcess(terminalNode);
terminals.remove(terminalId);
}
view.hideProcessOutput(terminalId);
}
});
}
use of com.google.gwt.user.client.ui.IsWidget in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldAddMachineWhenMachineCreating.
@Test
public void shouldAddMachineWhenMachineCreating() throws Exception {
MachineEntity machine = mock(MachineEntity.class);
MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
OutputConsole outputConsole = mock(OutputConsole.class);
when(machineConfigDto.getName()).thenReturn(MACHINE_NAME);
when(machine.getConfig()).thenReturn(machineConfigDto);
when(appContext.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(commandConsoleFactory.create(eq(MACHINE_NAME))).thenReturn(outputConsole);
MachineStateEvent machineStateEvent = mock(MachineStateEvent.class);
when(machineStateEvent.getMachine()).thenReturn(machine);
verify(eventBus, times(8)).addHandler(anyObject(), machineStateHandlerCaptor.capture());
MachineStateEvent.Handler machineStateHandler = machineStateHandlerCaptor.getAllValues().get(0);
machineStateHandler.onMachineCreating(machineStateEvent);
verify(outputConsole).go(acceptsOneWidgetCaptor.capture());
IsWidget widget = mock(IsWidget.class);
acceptsOneWidgetCaptor.getValue().setWidget(widget);
verify(commandConsoleFactory).create(eq(MACHINE_NAME));
verify(view).addWidget(anyString(), anyString(), anyObject(), anyObject(), anyBoolean());
verify(view).setProcessesData(eq(presenter.rootNode));
}
use of com.google.gwt.user.client.ui.IsWidget in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldAddTerminal.
@Test
public void shouldAddTerminal() throws Exception {
MachineDto machineDto = mock(MachineDto.class);
MachineEntity machine = mock(MachineEntity.class);
when(machine.getId()).thenReturn(MACHINE_ID);
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<>(1);
machines.add(machineDto);
when(workspaceRuntime.getMachines()).thenReturn(machines);
when(entityFactory.createMachine(machineDto)).thenReturn(machine);
presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, new ArrayList<ProcessTreeNode>());
TerminalPresenter terminal = mock(TerminalPresenter.class);
when(terminalFactory.create(machine, presenter)).thenReturn(terminal);
IsWidget terminalWidget = mock(IsWidget.class);
when(terminal.getView()).thenReturn(terminalWidget);
when(terminalWidget.asWidget()).thenReturn(widget);
presenter.onAddTerminal(MACHINE_ID, presenter);
verify(terminalFactory).create(eq(machine), eq(presenter));
verify(workspaceAgent).setActivePart(presenter);
verify(terminal).getView();
verify(view, times(2)).setProcessesData(anyObject());
verify(view).selectNode(anyObject());
verify(view).addWidget(anyString(), anyString(), anyObject(), eq(terminalWidget), anyBoolean());
verify(view).addProcessNode(anyObject());
verify(terminal).setVisible(eq(true));
verify(terminal).connect();
verify(terminal).setListener(anyObject());
}
use of com.google.gwt.user.client.ui.IsWidget in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldDisplayStopProcessButtonAtAddingCommand.
@Test
public void shouldDisplayStopProcessButtonAtAddingCommand() throws Exception {
ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
when(machineNode.getId()).thenReturn(MACHINE_ID);
List<ProcessTreeNode> children = new ArrayList<>();
children.add(machineNode);
presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children);
ProcessTreeNode selectedCommandNode = new ProcessTreeNode(COMMAND_NODE, null, PROCESS_NAME, null, children);
children.add(selectedCommandNode);
when(outputConsole.isFinished()).thenReturn(false);
presenter.consoles.clear();
presenter.addCommandOutput(MACHINE_ID, outputConsole);
verify(view, never()).hideProcessOutput(anyString());
verify(outputConsole).go(acceptsOneWidgetCaptor.capture());
IsWidget widget = mock(IsWidget.class);
acceptsOneWidgetCaptor.getValue().setWidget(widget);
verify(view).addProcessNode(anyObject());
verify(view).addWidget(anyString(), anyString(), anyObject(), eq(widget), anyBoolean());
verify(view, times(2)).selectNode(anyObject());
verify(view).setProcessesData(anyObject());
verify(view).getNodeById(anyString());
verify(view).setStopButtonVisibility(anyString(), eq(true));
}
use of com.google.gwt.user.client.ui.IsWidget in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldHideStopProcessButtonAtAddingCommand.
@Test
public void shouldHideStopProcessButtonAtAddingCommand() throws Exception {
ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
when(machineNode.getId()).thenReturn(MACHINE_ID);
List<ProcessTreeNode> children = new ArrayList<>();
children.add(machineNode);
presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children);
ProcessTreeNode selectedCommandNode = new ProcessTreeNode(COMMAND_NODE, null, PROCESS_NAME, null, children);
children.add(selectedCommandNode);
when(outputConsole.isFinished()).thenReturn(true);
presenter.consoles.clear();
presenter.addCommandOutput(MACHINE_ID, outputConsole);
verify(view, never()).hideProcessOutput(anyString());
verify(outputConsole).go(acceptsOneWidgetCaptor.capture());
IsWidget widget = mock(IsWidget.class);
acceptsOneWidgetCaptor.getValue().setWidget(widget);
verify(view).addProcessNode(anyObject());
verify(view).addWidget(anyString(), anyString(), anyObject(), eq(widget), anyBoolean());
verify(view, times(2)).selectNode(anyObject());
verify(view).setProcessesData(anyObject());
verify(view).getNodeById(anyString());
verify(view).setStopButtonVisibility(anyString(), eq(false));
}
Aggregations