/**
  * Returns a representation of a base DN for a set of servers.
  *
  * @param baseDN the base DN.
  * @param servers the servers.
  * @return a representation of a base DN for a set of servers.
  */
 public static String getSuffixDisplay(String baseDN, Set<ServerDescriptor> servers) {
   StringBuilder sb = new StringBuilder();
   sb.append(baseDN);
   for (ServerDescriptor server : servers) {
     sb.append(Constants.LINE_SEPARATOR + "    ");
     sb.append(server.getHostPort(true));
   }
   return sb.toString();
 }
  /** {@inheritDoc} */
  public void beginDisplay(UserData data) {
    TreeSet<ServerDescriptor> array = orderServers(data.getRemoteWithNoReplicationPort().keySet());
    AuthenticationData authData = data.getReplicationOptions().getAuthenticationData();
    String newServerDisplay;
    if (authData != null) {
      newServerDisplay = authData.getHostName() + ":" + authData.getPort();
    } else {
      newServerDisplay = "";
    }
    if (!array.equals(orderedServers) || !newServerDisplay.equals(serverToConnectDisplay)) {
      serverToConnectDisplay = newServerDisplay;
      // Adds the required focus listeners to the fields.
      final FocusListener l =
          new FocusListener() {
            public void focusGained(FocusEvent e) {
              lastFocusComponent = e.getComponent();
            }

            public void focusLost(FocusEvent e) {}
          };
      lastFocusComponent = null;
      HashMap<String, String> hmOldValues = new HashMap<>();
      for (String id : hmFields.keySet()) {
        hmOldValues.put(id, hmFields.get(id).getText());
      }
      HashMap<String, Boolean> hmOldSecureValues = new HashMap<>();
      for (String id : hmCbs.keySet()) {
        hmOldSecureValues.put(id, hmCbs.get(id).isSelected());
      }
      orderedServers.clear();
      orderedServers.addAll(array);
      hmFields.clear();
      hmCbs.clear();
      hmLabels.clear();
      for (ServerDescriptor server : orderedServers) {
        String serverDisplay;
        if (server.getHostPort(false).equalsIgnoreCase(serverToConnectDisplay)) {
          serverDisplay = serverToConnectDisplay;
        } else {
          serverDisplay = server.getHostPort(true);
        }
        LabelFieldDescriptor desc =
            new LabelFieldDescriptor(
                LocalizableMessage.raw(serverDisplay),
                INFO_REPLICATION_PORT_TOOLTIP.get(),
                LabelFieldDescriptor.FieldType.TEXTFIELD,
                LabelFieldDescriptor.LabelType.PRIMARY,
                UIFactory.PORT_FIELD_SIZE);
        AuthenticationData auth = data.getRemoteWithNoReplicationPort().get(server);
        JTextComponent field = UIFactory.makeJTextComponent(desc, String.valueOf(auth.getPort()));
        String oldValue = hmOldValues.get(server.getId());
        if (oldValue != null) {
          field.setText(oldValue);
        }

        JLabel label = UIFactory.makeJLabel(desc);

        hmFields.put(server.getId(), field);
        label.setLabelFor(field);
        field.addFocusListener(l);
        if (lastFocusComponent == null) {
          lastFocusComponent = field;
        }

        hmLabels.put(server.getId(), label);

        JCheckBox cb =
            UIFactory.makeJCheckBox(
                INFO_SECURE_REPLICATION_LABEL.get(),
                INFO_SECURE_REPLICATION_TOOLTIP.get(),
                UIFactory.TextStyle.SECONDARY_FIELD_VALID);
        cb.setSelected(auth.useSecureConnection());
        Boolean oldSecureValue = hmOldSecureValues.get(server.getId());
        if (oldSecureValue != null) {
          cb.setSelected(oldSecureValue);
        }
        hmCbs.put(server.getId(), cb);
      }
      populateFieldsPanel();
    }
  }
 /** {@inheritDoc} */
 public int compare(ServerDescriptor desc1, ServerDescriptor desc2) {
   return desc1.getHostPort(true).compareTo(desc2.getHostPort(true));
 }