/** {@inheritDoc} */
  @Override
  public void onToggleSplitterClicked(boolean isShowSplitter) {
    terminalTab.setScopes(isShowSplitter ? EnumSet.allOf(State.class) : EnumSet.of(RUNNERS));

    if (isShowSplitter) {
      panelState.setSplitterState(SPLITTER_ON);

      view.setLeftPropertiesPanel(leftPropertiesContainer);
      view.setRightPropertiesPanel(rightPropertiesContainer);
    } else {
      panelState.setSplitterState(SPLITTER_OFF);

      view.setGeneralPropertiesPanel(rightPropertiesContainer);
    }

    if (TEMPLATE.equals(state)) {
      panelState.setState(TEMPLATE);

      leftTabContainer.showTab(locale.runnerTabTemplates());

      if (SPLITTER_OFF.equals(panelState.getSplitterState())) {
        rightPropertiesContainer.showTab(propertiesTab.getTitle());
      }
    }
  }
  private void selectHistoryTab() {
    state = RUNNERS;
    panelState.setState(RUNNERS);

    view.setEnableRunButton(runnerUtil.hasRunPermission());

    view.showOtherButtons();
  }
  private void updateRunnerTimer() {
    if (selectedRunner == null) {
      return;
    }
    view.setTimeout(selectedRunner.getTimeout());

    view.updateMoreInfoPopup(selectedRunner);
  }
  @NotNull
  private Runner launchRunner(@NotNull Runner runner) {
    if (runActionPermit.isAllowed()) {

      CurrentProject currentProject = appContext.getCurrentProject();

      if (currentProject == null) {
        throw new IllegalStateException(
            "Can't launch runner for current project. Current project is absent...");
      }

      selectedEnvironment = null;

      panelState.setState(RUNNERS);
      view.showOtherButtons();

      history.addRunner(runner);

      runnerInQueueTimer.schedule(ONE_SEC.getValue());

      CheckRamAndRunAction checkRamAndRunAction = actionFactory.createCheckRamAndRun();
      checkRamAndRunAction.perform(runner);

      runnerActions.put(runner, checkRamAndRunAction);

      runner.resetCreationTime();
      runnerTimer.schedule(ONE_SEC.getValue());
    } else {
      runActionDenyAccessDialog.show();
    }
    return runner;
  }
  /** {@inheritDoc} */
  @Override
  public void onStopButtonClicked() {
    terminalContainer.removeTerminalUrl(selectedRunner);

    stopRunner(selectedRunner);

    view.updateMoreInfoPopup(selectedRunner);
  }
  /**
   * Updates runner when runner state changed.
   *
   * @param runner runner which was changed
   */
  public void update(@NotNull Runner runner) {
    history.update(runner);

    if (runner.equals(selectedRunner) && history.isRunnerExist(runner)) {
      view.update(runner);
      changeURLDependingOnState(runner);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void onProjectClosed(@NotNull ProjectActionEvent projectActionEvent) {
    partStack.hidePart(this);

    selectionManager.setRunner(null);

    templateContainer.setVisible(false);

    view.setEnableRunButton(false);
    view.setEnableReRunButton(false);
    view.setEnableStopButton(false);
    view.setEnableLogsButton(false);

    view.setApplicationURl(null);
    view.setDebugPort(null);
    view.setTimeout(TIMER_STUB);

    history.clear();
    runnerActions.clear();

    runnerCounter.reset();
    terminalContainer.reset();
    consoleContainer.reset();
    propertiesContainer.reset();

    getRunningProcessAction.stop();
    propertiesContainer.show((Runner) null);
  }
  /** {@inheritDoc} */
  @Override
  public void onLogsButtonClicked() {
    Link logUrl = selectedRunner.getLogUrl();
    if (logUrl == null) {
      return;
    }

    view.showLog(logUrl.getHref());
  }
 private void changeURLDependingOnState(@NotNull Runner runner) {
   switch (runner.getStatus()) {
     case IN_PROGRESS:
       view.setApplicationURl(locale.uplAppWaitingForBoot());
       break;
     case IN_QUEUE:
       view.setApplicationURl(locale.uplAppWaitingForBoot());
       break;
     case STOPPED:
       view.setApplicationURl(locale.urlAppRunnerStopped());
       break;
     case FAILED:
       view.setApplicationURl(null);
       break;
     default:
       String url = runner.getApplicationURL();
       view.setApplicationURl(url == null ? locale.urlAppRunning() : url);
       setDebugPort(runner);
   }
 }
  /** {@inheritDoc} */
  @Override
  public void onProjectReady(@NotNull ProjectActionEvent projectActionEvent) {
    view.setEnableReRunButton(false);
    view.setEnableStopButton(false);
    view.setEnableLogsButton(false);

    templateContainer.setVisible(true);

    getRunningProcessAction = actionFactory.createGetRunningProcess();

    boolean isRunOperationAvailable = runnerUtil.hasRunPermission();
    view.setEnableRunButton(isRunOperationAvailable);

    if (!isRunOperationAvailable) {
      return;
    }

    templateContainer.showEnvironments();

    getRunningProcessAction.perform();
    getSystemEnvironmentsAction.perform();

    runnerTimer.schedule(ONE_SEC.getValue());
  }
 private void setDebugPort(Runner runner) {
   ApplicationProcessDescriptor runnerDescriptor = runner.getDescriptor();
   if (runnerDescriptor != null && runnerDescriptor.getDebugPort() != -1) {
     view.setDebugPort(String.valueOf(runnerDescriptor.getDebugPort()));
   }
 }
 /** {@inheritDoc} */
 @Override
 public void onMoreInfoBtnMouseOver() {
   view.showMoreInfoPopup(selectedRunner);
 }
  @Inject
  public RunnerManagerPresenter(
      final RunnerManagerView view,
      RunnerActionFactory actionFactory,
      ModelsFactory modelsFactory,
      AppContext appContext,
      DtoFactory dtoFactory,
      ChooseRunnerAction chooseRunnerAction,
      EventBus eventBus,
      final RunnerLocalizationConstant locale,
      @LeftPanel TabContainer leftTabContainer,
      @LeftPropertiesPanel TabContainer leftPropertiesContainer,
      @RightPropertiesPanel TabContainer rightPropertiesContainer,
      PanelState panelState,
      Provider<TabBuilder> tabBuilderProvider,
      final ConsoleContainer consoleContainer,
      TerminalContainer terminalContainer,
      PropertiesContainer propertiesContainer,
      HistoryPanel history,
      TemplatesContainer templateContainer,
      RunnerCounter runnerCounter,
      SelectionManager selectionManager,
      TimerFactory timerFactory,
      GetSystemEnvironmentsAction getSystemEnvironmentsAction,
      RunnerUtil runnerUtil,
      @Run ResourcesLockedActionPermit runActionPermit,
      @Run ActionDenyAccessDialog runActionDenyAccessDialog) {
    this.view = view;
    this.view.setDelegate(this);
    this.locale = locale;
    this.dtoFactory = dtoFactory;
    this.chooseRunnerAction = chooseRunnerAction;
    this.actionFactory = actionFactory;
    this.modelsFactory = modelsFactory;
    this.appContext = appContext;
    this.runnerCounter = runnerCounter;
    this.getSystemEnvironmentsAction = getSystemEnvironmentsAction;
    this.runnerUtil = runnerUtil;
    this.runActionPermit = runActionPermit;
    this.runActionDenyAccessDialog = runActionDenyAccessDialog;

    this.leftTabContainer = leftTabContainer;
    this.leftTabContainer.setLocation(PanelLocation.LEFT);
    this.leftPropertiesContainer = leftPropertiesContainer;
    this.leftPropertiesContainer.setLocation(PanelLocation.LEFT_PROPERTIES);
    this.rightPropertiesContainer = rightPropertiesContainer;
    this.rightPropertiesContainer.setLocation(RIGHT_PROPERTIES);

    this.selectionManager = selectionManager;
    this.selectionManager.addListener(this);

    this.history = history;

    this.panelState = panelState;

    this.consoleContainer = consoleContainer;
    this.templateContainer = templateContainer;
    this.terminalContainer = terminalContainer;
    this.propertiesContainer = propertiesContainer;

    this.runnerActions = new HashMap<>();

    this.runnerTimer =
        timerFactory.newInstance(
            new TimerFactory.TimerCallBack() {
              @Override
              public void onRun() {
                updateRunnerTimer();

                runnerTimer.schedule(ONE_SEC.getValue());
              }
            });

    this.runnerInQueueTimer =
        timerFactory.newInstance(
            new TimerFactory.TimerCallBack() {
              @Override
              public void onRun() {
                if (IN_QUEUE.equals(selectedRunner.getStatus())) {
                  consoleContainer.printInfo(selectedRunner, locale.messageRunnerInQueue());
                }
              }
            });

    eventBus.addHandler(ProjectActionEvent.TYPE, this);
    runnersId = new HashSet<>();

    initializeLeftPanel(panelState, tabBuilderProvider, history, templateContainer);

    initializeLeftPropertiesPanel(tabBuilderProvider);
    initializeRightPropertiesPanel(tabBuilderProvider);

    view.setLeftPanel(leftTabContainer);

    panelState.setSplitterState(SPLITTER_OFF);
    view.setGeneralPropertiesPanel(rightPropertiesContainer);
  }