use of org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter in project che by eclipse.
the class TerminalContainer method addOrShowTerminal.
/**
* Adds terminal for current machine. Or if terminal already exist updates terminal.
*
* @param machine
* machine for which terminal will be added or updated
*/
public void addOrShowTerminal(MachineEntity machine) {
String machineId = machine.getId();
TerminalPresenter terminal = terminals.get(machineId);
if (terminal != null) {
terminal.connect();
view.showTerminal(terminal);
return;
}
TerminalPresenter newTerminal = terminalFactory.create(machine, this);
terminals.put(machineId, newTerminal);
view.addTerminal(newTerminal);
}
use of org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter 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 org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldShowTerminalWhenTerminalNodeSelected.
@Test
public void shouldShowTerminalWhenTerminalNodeSelected() throws Exception {
TerminalPresenter terminal = mock(TerminalPresenter.class);
presenter.terminals.put(PROCESS_ID, terminal);
ProcessTreeNode terminalNode = mock(ProcessTreeNode.class);
when(terminalNode.getId()).thenReturn(PROCESS_ID);
presenter.onTreeNodeSelected(terminalNode);
verify(view).showProcessOutput(eq(PROCESS_ID));
verify(view, never()).setStopButtonVisibility(PROCESS_ID, true);
}
use of org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter 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 org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter in project che by eclipse.
the class ProcessesPanelPresenterTest method shouldCloseTerminal.
@Test
public void shouldCloseTerminal() throws Exception {
ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
when(machineNode.getId()).thenReturn(MACHINE_ID);
TerminalPresenter terminal = mock(TerminalPresenter.class);
ProcessTreeNode terminalNode = mock(ProcessTreeNode.class);
when(terminalNode.getId()).thenReturn(PROCESS_ID);
List<ProcessTreeNode> children = new ArrayList<>();
children.add(machineNode);
presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children);
presenter.terminals.put(PROCESS_ID, terminal);
when(view.getNodeIndex(anyString())).thenReturn(0);
when(machineNode.getChildren()).thenReturn(children);
when(terminalNode.getParent()).thenReturn(machineNode);
presenter.onCloseTerminal(terminalNode);
verify(terminal).stopTerminal();
verify(terminalNode, times(3)).getId();
verify(terminalNode).getParent();
verify(view).getNodeIndex(eq(PROCESS_ID));
verify(view).hideProcessOutput(eq(PROCESS_ID));
verify(view).removeProcessNode(eq(terminalNode));
verify(view).setProcessesData(anyObject());
}
Aggregations