private void resfreshStopButtonState(String selectedNodeId) {
    if (selectedNodeId == null) {
      return;
    }

    for (Map.Entry<String, OutputConsole> entry : consoles.entrySet()) {
      String nodeId = entry.getKey();
      if (selectedNodeId.equals(nodeId) && !entry.getValue().isFinished()) {
        view.setStopButtonVisibility(selectedNodeId, true);
      } else {
        view.setStopButtonVisibility(nodeId, false);
      }
    }
  }
 @Override
 public void onConsoleOutput(OutputConsole console) {
   String command = consoleCommands.get(console);
   if (command != null) {
     view.markProcessHasOutput(command);
   }
 }
  @Test
  public void shouldCloseTerminal() throws Exception {
    TerminalPresenter terminal = mock(TerminalPresenter.class);
    ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
    ProcessTreeNode terminalNode = 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);
    presenter.terminals.put(PROCESS_ID, terminal);

    when(terminalNode.getId()).thenReturn(PROCESS_ID);
    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(2)).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());
  }
  @Override
  public void onTreeNodeSelected(@NotNull ProcessTreeNode node) {
    selectedTreeNode = node;

    view.showProcessOutput(node.getId());
    resfreshStopButtonState(node.getId());
  }
  @Test
  public void shouldCloseCommanOutputWhenCommandHasFinished() throws Exception {
    ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
    ProcessTreeNode commandNode = 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);

    when(outputConsole.isFinished()).thenReturn(true);
    presenter.consoles.put(PROCESS_ID, outputConsole);
    machineNode.getChildren().add(commandNode);

    when(commandNode.getId()).thenReturn(PROCESS_ID);
    when(view.getNodeIndex(anyString())).thenReturn(0);
    when(machineNode.getChildren()).thenReturn(children);
    when(commandNode.getParent()).thenReturn(machineNode);

    presenter.onCloseCommandOutputClick(commandNode);

    verify(commandNode, times(2)).getId();
    verify(commandNode).getParent();
    verify(view).getNodeIndex(eq(PROCESS_ID));
    verify(view).hideProcessOutput(eq(PROCESS_ID));
    verify(view).removeProcessNode(eq(commandNode));
    verify(view).setProcessesData(anyObject());
  }
  @Test
  public void shouldStopProcessWithoutCloseCommanOutput() throws Exception {
    ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
    ProcessTreeNode commandNode = 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);

    when(outputConsole.isFinished()).thenReturn(false);
    presenter.consoles.put(PROCESS_ID, outputConsole);
    //noinspection ConstantConditions
    machineNode.getChildren().add(commandNode);

    when(commandNode.getId()).thenReturn(PROCESS_ID);
    when(view.getNodeIndex(anyString())).thenReturn(0);
    when(machineNode.getChildren()).thenReturn(children);
    when(commandNode.getParent()).thenReturn(machineNode);

    presenter.onStopCommandProcess(commandNode);

    verify(outputConsole).stop();
    verify(view, never()).hideProcessOutput(eq(PROCESS_ID));
    verify(view, never()).removeProcessNode(eq(commandNode));
  }
 @Override
 public void onProcessFinished(ProcessFinishedEvent event) {
   for (Map.Entry<String, OutputConsole> entry : consoles.entrySet()) {
     if (entry.getValue().isFinished()) {
       view.setStopButtonVisibility(entry.getKey(), false);
     }
   }
 }
  @Override
  public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
    for (ProcessTreeNode processTreeNode : rootNode.getChildren()) {
      if (processTreeNode.getType() == MACHINE_NODE) {
        onCloseTerminal(processTreeNode);
        processTreeNode.setRunning(false);
        if (processTreeNode.getChildren() != null) {
          processTreeNode.getChildren().clear();
        }
      }
    }

    rootNode.getChildren().clear();
    rootChildren.clear();

    view.clear();
    view.selectNode(null);
    view.setProcessesData(rootNode);
  }
  private void onStopProcess(@NotNull ProcessTreeNode node) {
    String processId = node.getId();
    ProcessTreeNode parentNode = node.getParent();

    int processIndex = view.getNodeIndex(processId);
    if (processIndex < 0) {
      return;
    }

    int countWidgets = terminals.size() + consoles.size();
    if (countWidgets == 1) {
      view.hideProcessOutput(processId);
      removeChildFromMachineNode(node, parentNode);
      return;
    }

    int neighborIndex = processIndex > 0 ? processIndex - 1 : processIndex + 1;
    ProcessTreeNode neighborNode = view.getNodeByIndex(neighborIndex);
    String neighborNodeId = neighborNode.getId();

    removeChildFromMachineNode(node, parentNode);
    view.selectNode(neighborNode);
    resfreshStopButtonState(neighborNodeId);
    view.showProcessOutput(neighborNodeId);
    view.hideProcessOutput(processId);
  }
Esempio n. 10
0
  /**
   * Adds command node to process tree and displays command output
   *
   * @param machineId id of machine in which the command will be executed
   * @param outputConsole the console for command output
   */
  public void addCommandOutput(@NotNull String machineId, @NotNull OutputConsole outputConsole) {
    ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
    if (machineTreeNode == null) {
      notificationManager.notify(
          localizationConstant.failedToExecuteCommand(),
          localizationConstant.machineNotFound(machineId),
          FAIL,
          FLOAT_MODE);
      Log.error(getClass(), localizationConstant.machineNotFound(machineId));
      return;
    }

    String commandId;
    String outputConsoleTitle = outputConsole.getTitle();
    ProcessTreeNode processTreeNode = getProcessTreeNodeByName(outputConsoleTitle, machineTreeNode);
    if (processTreeNode != null && isCommandStopped(processTreeNode.getId())) {
      commandId = processTreeNode.getId();
      view.hideProcessOutput(commandId);
    } else {
      ProcessTreeNode commandNode =
          new ProcessTreeNode(
              COMMAND_NODE,
              machineTreeNode,
              outputConsoleTitle,
              outputConsole.getTitleIcon(),
              null);
      commandId = commandNode.getId();
      view.addProcessNode(commandNode);
      addChildToMachineNode(commandNode, machineTreeNode);
    }

    updateCommandOutput(commandId, outputConsole);

    resfreshStopButtonState(commandId);
    workspaceAgent.setActivePart(this);
  }
Esempio n. 11
0
  @Override
  public void onMachineDestroyed(MachineStateEvent event) {
    String destroyedMachineId = event.getMachineId();

    ProcessTreeNode destroyedMachineNode = machineNodes.get(destroyedMachineId);
    if (destroyedMachineNode == null) {
      return;
    }

    rootChildren.remove(destroyedMachineNode);
    onCloseTerminal(destroyedMachineNode);
    onStopCommandProcess(destroyedMachineNode);

    view.setProcessesData(rootNode);
  }
Esempio n. 12
0
  private void addMachineToConsoles(MachineDto machine) {
    List<ProcessTreeNode> processTreeNodes = new ArrayList<ProcessTreeNode>();
    ProcessTreeNode machineNode =
        new ProcessTreeNode(MACHINE_NODE, rootNode, machine, null, processTreeNodes);
    machineNode.setRunning(true);

    if (rootChildren.contains(machineNode)) {
      rootChildren.remove(machineNode);
    }

    rootChildren.add(machineNode);
    view.setProcessesData(rootNode);

    String machineId = machine.getId();

    restoreState(machineId);

    machineNodes.put(machineId, machineNode);
  }
Esempio n. 13
0
 private void removeChildFromMachineNode(
     ProcessTreeNode childNode, ProcessTreeNode machineTreeNode) {
   view.removeProcessNode(childNode);
   machineTreeNode.getChildren().remove(childNode);
   view.setProcessesData(rootNode);
 }
Esempio n. 14
0
 private void addChildToMachineNode(ProcessTreeNode childNode, ProcessTreeNode machineTreeNode) {
   machineTreeNode.getChildren().add(childNode);
   view.setProcessesData(rootNode);
   view.selectNode(childNode);
 }
Esempio n. 15
0
 @Override
 public void setVisible(boolean visible) {
   view.setVisible(visible);
 }