private void addSearchFields(TitledBorder borderDn) {
    searchPattern = entity.getSearch();
    if (searchPattern == null) {
      searchPattern = new SearchPattern();
    }

    borderDn.add(
        new TextField<String>(
            "searchFilter", new PropertyModel<String>(searchPattern, "searchFilter")));
    borderDn.add(
        new SchemaHelpBubble(
            "searchFilter.help", new SchemaHelpModel(searchPattern, "searchFilter")));

    borderDn.add(
        new TextField<String>(
            "searchBase", new PropertyModel<String>(searchPattern, "searchBase")));
    borderDn.add(
        new SchemaHelpBubble("searchBase.help", new SchemaHelpModel(searchPattern, "searchBase")));

    borderDn.add(
        new StyledCheckbox(
            "searchSubTree", new PropertyModel<Boolean>(searchPattern, "searchSubTree")));
    borderDn.add(
        new SchemaHelpBubble(
            "searchSubTree.help", new SchemaHelpModel(searchPattern, "searchSubTree")));

    borderDn.add(
        new TextField<String>("managerDn", new PropertyModel<String>(searchPattern, "managerDn")));
    borderDn.add(
        new SchemaHelpBubble("managerDn.help", new SchemaHelpModel(searchPattern, "managerDn")));

    PasswordTextField managerPasswordField =
        new PasswordTextField(
            "managerPassword", new PropertyModel<String>(searchPattern, "managerPassword"));
    managerPasswordField.setRequired(false);
    managerPasswordField.setResetPassword(false);
    borderDn.add(managerPasswordField);
    borderDn.add(
        new SchemaHelpBubble(
            "managerPassword.help", new SchemaHelpModel(searchPattern, "managerPassword")));
  }
  private void addTestConnectionFields() {
    TitledBorder borderTest = new TitledBorder("borderTest");
    form.add(borderTest);
    borderTest.add(
        new TextField<String>("testUsername", new PropertyModel<String>(this, "testUsername")));
    borderTest.add(new HelpBubble("testUsername.help", "Username to test the LDAP connection"));

    PasswordTextField testPasswordField =
        new PasswordTextField("testPassword", new PropertyModel<String>(this, "testPassword"));
    testPasswordField.setRequired(false);
    testPasswordField.setResetPassword(false);
    borderTest.add(testPasswordField);
    borderTest.add(new HelpBubble("testPassword.help", "Password to test the LDAP connection"));

    // Test connection button
    borderTest.add(createTestConnectionButton());
  }
  public LdapCreateUpdatePanel(CreateUpdateAction action, LdapSetting ldapDescriptor) {
    /**
     * Creating a local copy of the original descriptor so that we can fool around with it without
     * changing the original until we need to save
     */
    super(action, new LdapSetting(ldapDescriptor));
    originalDescriptor = ldapDescriptor;
    setWidth(500);

    add(form);

    TitledBorder border = new TitledBorder("border");
    form.add(border);

    // Ldap key
    RequiredTextField<String> ldapKeyField = new RequiredTextField<String>("key");
    setDefaultFocusField(ldapKeyField);
    ldapKeyField.setEnabled(isCreate()); // don't allow key update
    if (isCreate()) {
      ldapKeyField.add(new XsdNCNameValidator("Invalid LDAP key '%s'"));
      ldapKeyField.add(new UniqueXmlIdValidator(centralConfigService.getMutableDescriptor()));
    }
    border.add(ldapKeyField);
    border.add(new SchemaHelpBubble("key.help"));

    border.add(new StyledCheckbox("enabled"));

    TextField<String> ldapUrlField = new RequiredTextField<String>("ldapUrl");
    ldapUrlField.add(new UriValidator("ldap", "ldaps"));
    border.add(ldapUrlField);
    border.add(new SchemaHelpBubble("ldapUrl.help"));

    TitledBorder borderDn = new TitledBorder("borderDn");
    form.add(borderDn);
    borderDn.add(new TextField("userDnPattern"));
    borderDn.add(new TextField("emailAttribute"));
    borderDn.add(new SchemaHelpBubble("emailAttribute.help"));
    borderDn.add(new StyledCheckbox("autoCreateUser"));
    borderDn.add(new SchemaHelpBubble("autoCreateUser.help"));
    borderDn.add(new SchemaHelpBubble("userDnPattern.help"));

    addSearchFields(borderDn);

    addTestConnectionFields();

    // Cancel button
    form.add(new ModalCloseLink("cancel"));

    // Submit button
    TitledAjaxSubmitLink submitButton = createSubmitButton();
    form.add(submitButton);
    form.add(new DefaultButtonBehavior(submitButton));

    add(form);
  }