/*
   * (non-Javadoc)
   *
   * @see com.intel.stl.ui.console.IConsoleEventListener#onConnect(boolean,
   * String)
   */
  @Override
  public void onConnect(boolean connected, String command) {

    if (connected) {
      consoleLogin.hideLogin();
      consoleControllers.put(consoleNum, console);

      LoginBean loginBean = console.getLoginInfo();
      console.updateInfoPanel(loginBean);

      // Revise the name of the console
      String cmd = (command == null) ? " " : command;

      if (loginBean != null) {
        console.setName(loginBean.getUserName() + "," + cmd);
        subpageView.updatePersonalizedTab(loginBean.getUserName(), cmd);

        Session session = loginBean.getSession();
        if (sessionMap.get(session) == null) {
          sessionMap.put(session, new AtomicInteger(1));
        } else {

          if (sessionMap.get(session) == null) {
            sessionMap.put(session, new AtomicInteger(1));
          } else {
            incrementSessionUsers(session);
          }
        }
      }
    }

    consoleLogin.killProgress();
    tabListener.enableNewTab(true);
    consoleTerminalView.enableCommanding(true);

    // Use the console initializer to issue a "history" command to the
    // remote host, capture the result, and display it in the command field
    // of the console view
    try {
      ConsoleTerminalController.ConsoleInitializer consoleInitializer =
          console.new ConsoleInitializer();
      consoleInitializer.initializeCommands(console.getLoginInfo());
    } catch (NumberFormatException e) {
    } catch (JSchException e) {
      e.printStackTrace();
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.intel.stl.ui.console.IConsoleEventListener#initializeConsole(com.
   * intel.stl.ui.console.LoginBean, java.lang.String)
   */
  @Override
  public void initializeConsole(LoginBean loginBean, String command) throws NumberFormatException {

    try {
      tabListener = subpageView.getNewTabView();
      tabListener.enableNewTab(false);
      consoleTerminalView.enableCommanding(false);
      if (command == null) {
        // Add new console with a new session
        console.initializeTerminal(loginBean);

      } else {
        console.initializeTerminal(loginBean, command);
      }
    } catch (NumberFormatException e) {
      throw e;
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.intel.stl.ui.console.IConsoleEventListener#onConnectFail(java.lang
   * .Exception)
   */
  @Override
  public void onConnectFail(ConsoleTerminalController console, int reason, Exception e) {

    if (e instanceof NumberFormatException) {
      consoleLogin.showMessage(
          UILabels.STL80002_INVALID_PORT_NUMBER.getDescription(defaultLoginBean.getPortNum()));

    } else if (e instanceof JSchException) {
      String msg = new String();
      if (e.getMessage().compareTo("Auth fail") == 0) {
        msg = UILabels.STL80003_AUTHENTICATION_FAILURE.getDescription();

      } else if (e.getMessage().startsWith("SSH_MSG_DISCONNECT")) {
        msg = e.getMessage();

      } else {
        msg =
            UILabels.STL80001_CONSOLE_CONNECTION_ERROR.getDescription()
                + " "
                + consoleLogin.getHostName()
                + ": "
                + e.getMessage();
      }
      consoleLogin.showMessage(msg);
    } else {
      consoleLogin.showMessage(StringUtils.getErrorMessage(e));
    }

    consoleLogin.killProgress();
    tabListener.enableNewTab(true);
    consoleTerminalView.enableCommanding(true);
    if ((console != null) && (reason == REASON_INIT)) {
      console.shutDownConsole();
      closeChannel(console);
      closeSession(console);
    }
  }