Search in sources :

Example 1 with IsWidget

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);
        }
    });
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) TerminalPresenter(org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter)

Example 2 with IsWidget

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));
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) MachineStateEvent(org.eclipse.che.ide.api.machine.events.MachineStateEvent) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Test(org.junit.Test)

Example 3 with IsWidget

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());
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) IsWidget(com.google.gwt.user.client.ui.IsWidget) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) ArrayList(java.util.ArrayList) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) TerminalPresenter(org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter) Test(org.junit.Test)

Example 4 with IsWidget

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));
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) ArrayList(java.util.ArrayList) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Test(org.junit.Test)

Example 5 with IsWidget

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));
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) ArrayList(java.util.ArrayList) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Test(org.junit.Test)

Aggregations

IsWidget (com.google.gwt.user.client.ui.IsWidget)15 ProcessTreeNode (org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)5 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)4 AcceptsOneWidget (com.google.gwt.user.client.ui.AcceptsOneWidget)3 TerminalPresenter (org.eclipse.che.ide.extension.machine.client.perspective.terminal.TerminalPresenter)3 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)2 UIObject (com.google.gwt.user.client.ui.UIObject)1 ReflectionException (com.googlecode.gwt.test.exceptions.ReflectionException)1 HashMap (java.util.HashMap)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 MachineStateEvent (org.eclipse.che.ide.api.machine.events.MachineStateEvent)1 OutputConsole (org.eclipse.che.ide.api.outputconsole.OutputConsole)1 CommandOutputConsole (org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole)1 Matchers.anyString (org.mockito.Matchers.anyString)1