Beispiel #1
0
  private DynamicForm getConnectionForm() {
    connectionForm = new DynamicForm();
    connectionForm.setNumCols(4);
    connectionForm.setWrapItemTitles(false);
    connectionForm.setColWidths("130", "450", "110");
    connectionForm.setExtraSpace(15);
    connectionForm.setWidth(790);
    connectionForm.setPadding(5);
    connectionForm.setIsGroup(true);
    connectionForm.setGroupTitle(MSG.view_remoteAgentInstall_connInfo());
    final int textFieldWidth = 440;

    TextItem host = new TextItem("host", MSG.common_title_host());
    host.setRequired(true);
    host.setWidth(textFieldWidth);
    host.setPrompt(MSG.view_remoteAgentInstall_promptHost());
    host.setHoverWidth(300);
    host.setEndRow(true);
    host.addChangedHandler(
        new ChangedHandler() {
          @Override
          public void onChanged(ChangedEvent event) {
            hostAuthorized =
                false; // if the host changes, we need to make sure the user authorizes it if needed
          }
        });

    TextItem port = new TextItem("port", MSG.common_title_port());
    port.setRequired(false);
    port.setWidth(textFieldWidth);
    port.setPrompt(MSG.view_remoteAgentInstall_promptPort());
    port.setHoverWidth(300);
    port.setEndRow(true);
    IntegerRangeValidator portValidator = new IntegerRangeValidator();
    portValidator.setMin(1);
    portValidator.setMax(65535);
    port.setValidators(new IsIntegerValidator(), portValidator);

    TextItem username = new TextItem("username", MSG.common_title_user());
    username.setRequired(
        false); // if not specified, the server will attempt to use the default ssh user defined in
                // system settings
    username.setWidth(textFieldWidth);
    username.setPrompt(MSG.view_remoteAgentInstall_promptUser());
    username.setHoverWidth(300);
    username.setEndRow(true);

    PasswordItem password = new PasswordItem("password", MSG.common_title_password());
    password.setRequired(
        false); // if not specified, the server will attempt to use the default ssh pw defined in
                // system settings
    password.setWidth(textFieldWidth);
    password.setPrompt(MSG.view_remoteAgentInstall_promptPassword());
    password.setHoverWidth(300);
    password.setEndRow(true);
    password.setAttribute("autocomplete", "off");

    rememberMeCheckbox = new CheckboxItem("rememberme", MSG.view_remoteAgentInstall_rememberMe());
    rememberMeCheckbox.setRequired(false);
    rememberMeCheckbox.setPrompt(MSG.view_remoteAgentInstall_promptRememberMe());
    rememberMeCheckbox.setHoverWidth(300);
    rememberMeCheckbox.setColSpan(2);
    rememberMeCheckbox.setEndRow(true);

    agentInstallPath = new TextItem("agentInstallPath", MSG.view_remoteAgentInstall_installPath());
    agentInstallPath.setWidth(textFieldWidth);
    agentInstallPath.setPrompt(MSG.view_remoteAgentInstall_promptInstallPath());
    agentInstallPath.setHoverWidth(300);
    agentInstallPath.setStartRow(true);
    agentInstallPath.setEndRow(false);
    agentInstallPath.setValidators(
        absPathValidator); // we will "turn this on" when needed - this is to ensure we create paths
                           // properly and it doesn't go in places user isn't expecting

    findAgentInstallPathButton =
        new ButtonItem("findAgentInstallPathButton", MSG.view_remoteAgentInstall_buttonFindAgent());
    findAgentInstallPathButton.setStartRow(false);
    findAgentInstallPathButton.setEndRow(true);
    if (findAgentInstallPathButton.getTitle().length() < 15) { // i18n may prolong the title
      findAgentInstallPathButton.setWidth(100);
    }
    findAgentInstallPathButton.addClickHandler(
        new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
          public void onClick(
              com.smartgwt.client.widgets.form.fields.events.ClickEvent clickEvent) {
            // we only want to validate host
            if (connectionForm.getValueAsString("host") == null
                || connectionForm.getValueAsString("host").trim().isEmpty()) {
              final HashMap<String, String> errors = new HashMap<String, String>(1);
              errors.put("host", CoreGUI.getSmartGwtMessages().validator_requiredField());
              connectionForm.setErrors(errors, true);
              return;
            }

            new CheckSSHConnectionCallback() {
              @Override
              protected void doActualWork() {
                findAgentInstallPath();
              }
            }.execute();
          }
        });

    createAgentStatusTextItem();

    statusCheckButton = new ButtonItem("updateStatus", MSG.common_title_updateStatus());
    statusCheckButton.setStartRow(false);
    statusCheckButton.setEndRow(true);
    if (findAgentInstallPathButton.getTitle().length() < 15) { // i18n may prolong the title
      statusCheckButton.setWidth(100);
    }
    statusCheckButton.addClickHandler(
        new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
          public void onClick(
              com.smartgwt.client.widgets.form.fields.events.ClickEvent clickEvent) {
            if (connectionForm.validate()) {
              new CheckSSHConnectionCallback() {
                @Override
                protected void doActualWork() {
                  agentStatusCheck();
                }
              }.execute();
            }
          }
        });

    if (initialAgentInstall != null) {
      host.setValue(initialAgentInstall.getSshHost());
      if (initialAgentInstall.getSshPort() != null) {
        port.setValue(String.valueOf(initialAgentInstall.getSshPort()));
      }
      username.setValue(initialAgentInstall.getSshUsername());
      password.setValue(initialAgentInstall.getSshPassword());
      agentInstallPath.setValue(initialAgentInstall.getInstallLocation());
      // if it was already saved, assume they want it to stay remembered
      // however, because the uninstall page is getting rid of the agent, we don't need or want to
      // remember the credentials anymore
      if (!this.showUninstallButton) {
        rememberMeCheckbox.setValue(initialAgentInstall.getSshPassword() != null);
      }
    }

    // disable some form elements if we don't want the user changing them - they should have been
    // filled in by who ever created this view
    if (this.showUninstallButton || this.showStartButton || this.showStopButton) {
      host.setDisabled(true);
      port.setDisabled(true);
      agentInstallPath.setDisabled(true);
      findAgentInstallPathButton.setDisabled(true);
    }

    if (this.showUninstallButton) {
      // don't show rememberMe checkbox - we're getting rid of this agent so there won't be a record
      // to store the creds
      connectionForm.setFields(
          host,
          port,
          username,
          password,
          agentInstallPath,
          findAgentInstallPathButton,
          agentStatusText,
          statusCheckButton);
    } else {
      connectionForm.setFields(
          host,
          port,
          username,
          password,
          rememberMeCheckbox,
          agentInstallPath,
          findAgentInstallPathButton,
          agentStatusText,
          statusCheckButton);
    }

    return connectionForm;
  }