mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
08.32.2015 2d3af58c2cee0a4a12390fae1eace3fdd15d9664
OPENDJ-2092 OPENDJ-2093 Code cleanup

* src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
** Extract methods to use super type and factorize code
** Autorefactor'ed file + Reformat
** Minor code cleanup
** Use straight return
** Use interface instead of concrete class for local variable which are collections
** Use ternary operator
** Format javadoc

* src/main/java/org/opends/guitools/controlpanel/ui/NewAttributePanel.java
** Autorefactor'ed file + Reformat
** Minor code cleanup
** Use interface instead of concrete class for local variable which are collections
** Use ternary operator

* src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
* src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
** Consequences of changes done in NewAttributePanel
3 files modified
928 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java 544 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewAttributePanel.java 377 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java 7 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
@@ -28,6 +28,7 @@
import static org.forgerock.util.Utils.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.server.types.CommonSchemaElements.*;
import java.io.File;
import java.util.ArrayList;
@@ -45,84 +46,79 @@
import javax.naming.directory.ModificationItem;
import javax.swing.SwingUtilities;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ModificationType;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
import org.opends.guitools.controlpanel.ui.ProgressDialog;
import org.opends.guitools.controlpanel.util.Utilities;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.config.ConfigConstants;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.AttributeType;
import org.opends.server.types.Attributes;
import org.opends.server.types.CommonSchemaElements;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.ExistingFileBehavior;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.Modification;
import org.forgerock.opendj.ldap.ModificationType;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.SchemaFileElement;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.LDIFWriter;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.StaticUtils;
import static org.opends.server.types.CommonSchemaElements.*;
/**
 * An abstract class used to re-factor some code between the different tasks
 * that create elements in the schema.
 *
 */
public class NewSchemaElementsTask extends Task
{
  LinkedHashSet<ObjectClass> ocsToAdd = new LinkedHashSet<>();
  LinkedHashSet<AttributeType> attrsToAdd = new LinkedHashSet<>();
  final Set<ObjectClass> ocsToAdd = new LinkedHashSet<>();
  final Set<AttributeType> attrsToAdd = new LinkedHashSet<>();
  /**
   * Constructor of the task.
   * @param info the control panel information.
   * @param dlg the progress dialog where the task progress will be displayed.
   * @param ocsToAdd the object classes that must be created in order.
   * @param attrsToAdd the attributes that must be created in order.
   *
   * @param info
   *          the control panel information.
   * @param dlg
   *          the progress dialog where the task progress will be displayed.
   * @param ocsToAdd
   *          the object classes that must be created in order.
   * @param attrsToAdd
   *          the attributes that must be created in order.
   */
  public NewSchemaElementsTask(ControlPanelInfo info, ProgressDialog dlg,
      LinkedHashSet<ObjectClass> ocsToAdd,
      LinkedHashSet<AttributeType> attrsToAdd)
  public NewSchemaElementsTask(
      ControlPanelInfo info, ProgressDialog dlg, Set<ObjectClass> ocsToAdd, Set<AttributeType> attrsToAdd)
  {
    super(info, dlg);
    this.ocsToAdd.addAll(ocsToAdd);
    this.attrsToAdd.addAll(attrsToAdd);
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getBackends()
  {
    return Collections.emptySet();
  }
  /** {@inheritDoc} */
  @Override
  public boolean canLaunch(Task taskToBeLaunched,
      Collection<LocalizableMessage> incompatibilityReasons)
  public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons)
  {
    boolean canLaunch = true;
    if (state == State.RUNNING &&
        (taskToBeLaunched.getType() == Task.Type.DELETE_SCHEMA_ELEMENT ||
         taskToBeLaunched.getType() == Task.Type.MODIFY_SCHEMA_ELEMENT ||
         taskToBeLaunched.getType() == Task.Type.NEW_SCHEMA_ELEMENT))
    {
      incompatibilityReasons.add(getIncompatibilityMessage(this,
            taskToBeLaunched));
      canLaunch = false;
      incompatibilityReasons.add(getIncompatibilityMessage(this, taskToBeLaunched));
      return false;
    }
    return canLaunch;
    return true;
  }
  /** {@inheritDoc} */
  @Override
  public void runTask()
  {
@@ -141,39 +137,27 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public Type getType()
  {
    return Type.NEW_SCHEMA_ELEMENT;
  }
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getTaskDescription()
  {
    if (attrsToAdd.size() == 1 && ocsToAdd.isEmpty())
    {
      String attributeName = attrsToAdd.iterator().next().getNameOrOID();
      return INFO_CTRL_PANEL_NEW_ATTRIBUTE_TASK_DESCRIPTION.get(attributeName);
      return INFO_CTRL_PANEL_NEW_ATTRIBUTE_TASK_DESCRIPTION.get(attrsToAdd.iterator().next().getNameOrOID());
    }
    else if (ocsToAdd.size() == 1 && attrsToAdd.isEmpty())
    {
      String ocName = ocsToAdd.iterator().next().getNameOrOID();
      return INFO_CTRL_PANEL_NEW_OBJECTCLASS_TASK_DESCRIPTION.get(ocName);
      return INFO_CTRL_PANEL_NEW_OBJECTCLASS_TASK_DESCRIPTION.get(ocsToAdd.iterator().next().getNameOrOID());
    }
    else
    {
      ArrayList<String> attrNames = new ArrayList<>();
      for (AttributeType attribute : attrsToAdd)
      {
        attrNames.add(attribute.getNameOrOID());
      }
      ArrayList<String> ocNames = new ArrayList<>();
      for (ObjectClass oc : ocsToAdd)
      {
        ocNames.add(oc.getNameOrOID());
      }
      final List<String> attrNames = getElementsNameOrOID(attrsToAdd);
      final List<String> ocNames = getElementsNameOrOID(ocsToAdd);
      if (ocNames.isEmpty())
      {
        return INFO_CTRL_PANEL_NEW_ATTRIBUTES_TASK_DESCRIPTION.get(joinAsString(", ", attrNames));
@@ -185,15 +169,26 @@
      else
      {
        return INFO_CTRL_PANEL_NEW_SCHEMA_ELEMENTS_TASK_DESCRIPTION.get(
            joinAsString(", ", attrNames),
            joinAsString(", ", ocNames));
            joinAsString(", ", attrNames), joinAsString(", ", ocNames));
      }
    }
  }
  private <T extends CommonSchemaElements> List<String> getElementsNameOrOID(final Set<T> schemaElements)
  {
    final List<String> nameOrOIDs = new ArrayList<>();
    for (CommonSchemaElements schemaElement : schemaElements)
    {
      nameOrOIDs.add(schemaElement.getNameOrOID());
    }
    return nameOrOIDs;
  }
  /**
   * Update the schema.
   * @throws OpenDsException if an error occurs.
   *
   * @throws OpenDsException
   *           if an error occurs.
   */
  private void updateSchema() throws OpenDsException
  {
@@ -207,85 +202,74 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  protected String getCommandLinePath()
  {
    return null;
  }
  /** {@inheritDoc} */
  @Override
  protected List<String> getCommandLineArguments()
  {
    return Collections.emptyList();
  }
  /**
   * Add the schema elements one by one: we are not sure that the server will
   * handle the adds sequentially if we only send one modification.
   *
   * @throws OpenDsException
   */
  private void updateSchemaOnline() throws OpenDsException
  {
    // Add the schema elements one by one: we are not sure that the server
    // will handle the adds sequentially if we only send one modification.
    for (AttributeType attr : attrsToAdd)
    {
      addAttributeOnline(attr);
      SwingUtilities.invokeLater(new Runnable()
      {
        @Override
        public void run()
        {
          getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>",
              ColorAndFontConstants.progressFont));
        }
      });
      appendNewLinesToProgress();
    }
    for (ObjectClass oc : ocsToAdd)
    {
      addObjectClassOnline(oc);
      SwingUtilities.invokeLater(new Runnable()
      {
        @Override
        public void run()
        {
          getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>",
              ColorAndFontConstants.progressFont));
        }
      });
      appendNewLinesToProgress();
    }
  }
  private void appendNewLinesToProgress()
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>", ColorAndFontConstants.progressFont));
      }
    });
  }
  private void updateSchemaOffline() throws OpenDsException
  {
    // Group the changes in the same schema file.
    LinkedHashMap<String, List<AttributeType>> hmAttrs = copy(attrsToAdd);
    LinkedHashMap<String, List<ObjectClass>> hmOcs = copy(ocsToAdd);
    LinkedHashSet<String> allFileNames = new LinkedHashSet<>();
    allFileNames.addAll(hmAttrs.keySet());
    final Map<String, List<AttributeType>> hmAttrs = copy(attrsToAdd);
    final Map<String, List<ObjectClass>> hmOcs = copy(ocsToAdd);
    final Set<String> allFileNames = new LinkedHashSet<>(hmAttrs.keySet());
    allFileNames.addAll(hmOcs.keySet());
    for (String fileName : allFileNames)
    {
      List<AttributeType> attrs = get(hmAttrs, fileName);
      List<ObjectClass> ocs = get(hmOcs, fileName);
      if (fileName.equals(""))
      if ("".equals(fileName))
      {
        fileName = null;
      }
      updateSchemaOffline(fileName, attrs, ocs);
      SwingUtilities.invokeLater(new Runnable()
      {
        @Override
        public void run()
        {
          getProgressDialog().appendProgressHtml(Utilities.applyFont("<br><br>",
              ColorAndFontConstants.progressFont));
        }
      });
      appendNewLinesToProgress();
    }
  }
  private <T extends SchemaFileElement> List<T> get(
      LinkedHashMap<String, List<T>> hmElems, String fileName)
  private <T extends SchemaFileElement> List<T> get(Map<String, List<T>> hmElems, String fileName)
  {
    List<T> elems = hmElems.get(fileName);
    if (elems != null)
@@ -295,10 +279,9 @@
    return Collections.emptyList();
  }
  private <T extends SchemaFileElement> LinkedHashMap<String, List<T>> copy(
      LinkedHashSet<T> elemsToAdd)
  private <T extends SchemaFileElement> Map<String, List<T>> copy(Set<T> elemsToAdd)
  {
    LinkedHashMap<String, List<T>> hmElems = new LinkedHashMap<>();
    Map<String, List<T>> hmElems = new LinkedHashMap<>();
    for (T elem : elemsToAdd)
    {
      String fileName = CommonSchemaElements.getSchemaFile(elem);
@@ -317,90 +300,48 @@
    return hmElems;
  }
  private void addAttributeOnline(final AttributeType attribute)
  throws OpenDsException
  private void addAttributeOnline(final AttributeType attribute) throws OpenDsException
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      /** {@inheritDoc} */
      @Override
      public void run()
      {
        printEquivalentCommandLineToAddOnline(attribute);
        getProgressDialog().appendProgressHtml(
            Utilities.getProgressWithPoints(
                INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(
                    attribute.getNameOrOID()),
                    ColorAndFontConstants.progressFont));
      }
    });
    try
    {
      BasicAttribute attr = new BasicAttribute(getAttributeName(attribute));
      attr.add(getValueOnline(attribute));
      ModificationItem mod = new ModificationItem(DirContext.ADD_ATTRIBUTE,
          attr);
      getInfo().getDirContext().modifyAttributes(
          ConfigConstants.DN_DEFAULT_SCHEMA_ROOT,
          new ModificationItem[]  { mod });
    }
    catch (NamingException ne)
    {
      throw new OnlineUpdateException(
          ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(ne), ne);
    }
    notifyConfigurationElementCreated(attribute);
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        getProgressDialog().appendProgressHtml(
            Utilities.getProgressDone(ColorAndFontConstants.progressFont));
      }
    });
    addSchemaElementOnline(attribute, INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attribute.getNameOrOID()));
  }
  private void addObjectClassOnline(final ObjectClass objectClass)
  throws OpenDsException
  private void addObjectClassOnline(final ObjectClass objectClass) throws OpenDsException
  {
    addSchemaElementOnline(objectClass, INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(objectClass.getNameOrOID()));
  }
  private void addSchemaElementOnline(final CommonSchemaElements schemaElement, final LocalizableMessage progressMsg)
      throws OpenDsException
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      /** {@inheritDoc} */
      @Override
      public void run()
      {
        printEquivalentCommandLineToAddOnline(objectClass);
        printEquivalentCommandLineToAddOnline(schemaElement);
        getProgressDialog().appendProgressHtml(
            Utilities.getProgressWithPoints(
                INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(
                    objectClass.getNameOrOID()),
                    ColorAndFontConstants.progressFont));
            Utilities.getProgressWithPoints(progressMsg, ColorAndFontConstants.progressFont));
      }
    });
    try
    {
      BasicAttribute attr = new BasicAttribute(getAttributeName(objectClass));
      attr.add(getValueOnline(objectClass));
      ModificationItem mod = new ModificationItem(DirContext.ADD_ATTRIBUTE,
          attr);
      final BasicAttribute attr = new BasicAttribute(getAttributeName(schemaElement));
      attr.add(getValueOnline(schemaElement));
      final ModificationItem mod = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
      getInfo().getDirContext().modifyAttributes(
          ConfigConstants.DN_DEFAULT_SCHEMA_ROOT,
          new ModificationItem[]  { mod });
          ConfigConstants.DN_DEFAULT_SCHEMA_ROOT, new ModificationItem[] { mod });
    }
    catch (NamingException ne)
    {
      throw new OnlineUpdateException(
          ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(ne), ne);
      throw new OnlineUpdateException(ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(ne), ne);
    }
    notifyConfigurationElementCreated(objectClass);
    notifyConfigurationElementCreated(schemaElement);
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        getProgressDialog().appendProgressHtml(
            Utilities.getProgressDone(ColorAndFontConstants.progressFont));
        getProgressDialog().appendProgressHtml(Utilities.getProgressDone(ColorAndFontConstants.progressFont));
      }
    });
  }
@@ -413,72 +354,50 @@
  private String getValueOffline(CommonSchemaElements element)
  {
    final Map<String, List<String>> props = element.getExtraProperties();
    List<String> previousValues =
        props.get(ServerConstants.SCHEMA_PROPERTY_FILENAME);
    List<String> previousValues = props.get(ServerConstants.SCHEMA_PROPERTY_FILENAME);
    setExtraProperty(element, ServerConstants.SCHEMA_PROPERTY_FILENAME, null);
    String attributeWithoutFileDefinition = element.toString();
    if (previousValues != null && !previousValues.isEmpty())
    {
      ArrayList<String> vs = new ArrayList<>(previousValues);
      element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, vs);
      element.setExtraProperty(ServerConstants.SCHEMA_PROPERTY_FILENAME, new ArrayList<String>(previousValues));
    }
    return attributeWithoutFileDefinition;
  }
  private void printEquivalentCommandLineToAddOnline(
      CommonSchemaElements element)
  private void printEquivalentCommandLineToAddOnline(CommonSchemaElements element)
  {
    ArrayList<String> args = new ArrayList<>();
    List<String> args = new ArrayList<>();
    args.add("-a");
    args.addAll(getObfuscatedCommandLineArguments(
        getConnectionCommandLineArguments(true, true)));
    args.addAll(getObfuscatedCommandLineArguments(getConnectionCommandLineArguments(true, true)));
    args.add(getNoPropertiesFileArgument());
    String equiv = getEquivalentCommandLine(getCommandLinePath("ldapmodify"),
        args);
    StringBuilder sb = new StringBuilder();
    LocalizableMessage msg;
    if (element instanceof AttributeType)
    {
      msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_ATTRIBUTE_ONLINE.get(
          element.getNameOrOID());
    }
    else
    {
      msg = INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_OBJECTCLASS_ONLINE.get(
          element.getNameOrOID());
    }
    sb.append(msg).append("<br><b>");
    sb.append(equiv);
    sb.append("<br>");
    sb.append("dn: cn=schema<br>");
    sb.append("changetype: modify<br>");
    sb.append("add: ").append(getAttributeName(element)).append("<br>");
    sb.append(getAttributeName(element)).append(": ")
        .append(getValueOnline(element));
    sb.append("</b><br><br>");
    getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(),
        ColorAndFontConstants.progressFont));
    final String equivalentCmdLine = getEquivalentCommandLine(getCommandLinePath("ldapmodify"), args);
    final String elementID = element.getNameOrOID();
    final LocalizableMessage msg = element instanceof AttributeType ?
        INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_ATTRIBUTE_ONLINE.get(elementID)
      : INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_OBJECTCLASS_ONLINE.get(elementID);
    final StringBuilder sb = new StringBuilder();
    final String attName = getAttributeName(element);
    sb.append(msg).append("<br><b>")
      .append(equivalentCmdLine).append("<br>")
      .append("dn: cn=schema<br>")
      .append("changetype: modify<br>")
      .append("add: ").append(attName).append("<br>")
      .append(attName).append(": ").append(getValueOnline(element)).append("</b><br><br>");
    getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), ColorAndFontConstants.progressFont));
  }
  private String getAttributeName(CommonSchemaElements element)
  {
    if (element instanceof AttributeType)
    {
      return ConfigConstants.ATTR_ATTRIBUTE_TYPES;
    }
    else
    {
      return ConfigConstants.ATTR_OBJECTCLASSES;
    }
    return element instanceof AttributeType ? ConfigConstants.ATTR_ATTRIBUTE_TYPES : ConfigConstants.ATTR_OBJECTCLASSES;
  }
  private void updateSchemaOffline(String file,
      final List<AttributeType> attributes,
      final List<ObjectClass> objectClasses) throws OpenDsException
  private void updateSchemaOffline(
      String file, final List<AttributeType> attributes, final List<ObjectClass> objectClasses) throws OpenDsException
  {
    final List<CommonSchemaElements> schemaElements = new ArrayList<CommonSchemaElements>(attributes);
    schemaElements.addAll(objectClasses);
    if (file == null)
    {
      file = ConfigConstants.FILE_USER_SCHEMA_ELEMENTS;
@@ -486,88 +405,72 @@
    File f = new File(file);
    if (!f.isAbsolute())
    {
      f = new File(
        DirectoryServer.getEnvironmentConfig().getSchemaDirectory(),
        file);
      f = new File(DirectoryServer.getEnvironmentConfig().getSchemaDirectory(), file);
    }
    final String fileName = f.getAbsolutePath();
    final boolean isSchemaFileDefined = isSchemaFileDefined(fileName);
    SwingUtilities.invokeLater(new Runnable()
    {
      /** {@inheritDoc} */
      @Override
      public void run()
      {
        final ProgressDialog progressDialog = getProgressDialog();
        final String command = equivalentCommandToAddOffline(
            fileName, isSchemaFileDefined, attributes, objectClasses);
        progressDialog.appendProgressHtml(
            Utilities.applyFont(command,
                ColorAndFontConstants.progressFont));
        final String command = equivalentCommandToAddOffline(fileName, isSchemaFileDefined, schemaElements);
        progressDialog.appendProgressHtml(Utilities.applyFont(command, ColorAndFontConstants.progressFont));
        if (attributes.size() == 1 && objectClasses.isEmpty())
        {
          String attributeName = attributes.get(0).getNameOrOID();
          progressDialog.appendProgressHtml(
              Utilities.getProgressWithPoints(
                  INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attributeName),
                      ColorAndFontConstants.progressFont));
          progressDialog.appendProgressHtml(Utilities.getProgressWithPoints(
              INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attributeName), ColorAndFontConstants.progressFont));
        }
        else if (objectClasses.size() == 1 && attributes.isEmpty())
        {
          String ocName = objectClasses.get(0).getNameOrOID();
          progressDialog.appendProgressHtml(
              Utilities.getProgressWithPoints(
                  INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(ocName),
                      ColorAndFontConstants.progressFont));
          progressDialog.appendProgressHtml(Utilities.getProgressWithPoints(
              INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(ocName), ColorAndFontConstants.progressFont));
        }
        else
        {
          progressDialog.appendProgressHtml(
              Utilities.getProgressWithPoints(
                  INFO_CTRL_PANEL_UPDATING_SCHEMA_FILE_PROGRESS.get(fileName),
                      ColorAndFontConstants.progressFont));
          progressDialog.appendProgressHtml(Utilities.getProgressWithPoints(
              INFO_CTRL_PANEL_UPDATING_SCHEMA_FILE_PROGRESS.get(fileName), ColorAndFontConstants.progressFont));
        }
      }
    });
    updateSchemaFile(fileName, isSchemaFileDefined, attributes, objectClasses);
    for (AttributeType attr : attributes)
    if (isSchemaFileDefined)
    {
      notifyConfigurationElementCreated(attr);
      updateSchemaFile(fileName, schemaElements);
    }
    for (ObjectClass oc : objectClasses)
    else
    {
      notifyConfigurationElementCreated(oc);
      updateSchemaUndefinedFile(fileName, schemaElements);
    }
    for (CommonSchemaElements schemaElement : schemaElements)
    {
      notifyConfigurationElementCreated(schemaElement);
    }
    SwingUtilities.invokeLater(new Runnable()
    {
      @Override
      public void run()
      {
        getProgressDialog().appendProgressHtml(
            Utilities.getProgressDone(ColorAndFontConstants.progressFont));
        getProgressDialog().appendProgressHtml(Utilities.getProgressDone(ColorAndFontConstants.progressFont));
      }
    });
  }
  private String equivalentCommandToAddOffline(String schemaFile,
      boolean isSchemaFileDefined,
      List<AttributeType> attributes,
      List<ObjectClass> objectClasses)
  private String equivalentCommandToAddOffline(
      String schemaFile, boolean isSchemaFileDefined, List<CommonSchemaElements> schemaElements)
  {
    ArrayList<String> names = new ArrayList<>();
    for (AttributeType attr : attributes)
    List<String> names = new ArrayList<>();
    for (CommonSchemaElements schemaElement : schemaElements)
    {
      names.add(attr.getNameOrOID());
      names.add(schemaElement.getNameOrOID());
    }
    for (ObjectClass oc : objectClasses)
    {
      names.add(oc.getNameOrOID());
    }
    final String namesString = joinAsString(", ", names);
    final String namesString = joinAsString(", ", names);
    final StringBuilder sb = new StringBuilder();
    if (isSchemaFileDefined)
    {
@@ -585,59 +488,45 @@
      }
    }
    for (AttributeType attribute : attributes)
    for (CommonSchemaElements schemaElement : schemaElements)
    {
      sb.append(getAttributeName(attribute)).append(": ")
          .append(getValueOffline(attribute)).append("<br>");
    }
    for (ObjectClass oc : objectClasses)
    {
      sb.append(getAttributeName(oc)).append(": ")
          .append(getValueOffline(oc)).append("<br>");
      sb.append(getAttributeName(schemaElement)).append(": ").append(getValueOffline(schemaElement)).append("<br>");
    }
    sb.append("</b><br><br>");
    return sb.toString();
  }
  /**
   * Returns whether the file defined in the schema element exists or not.
   * @param schemaFile the path to the schema file.
   *
   * @param schemaFile
   *          the path to the schema file.
   * @return <CODE>true</CODE> if the schema file is defined and
   * <CODE>false</CODE> otherwise.
   *         <CODE>false</CODE> otherwise.
   */
  private boolean isSchemaFileDefined(String schemaFile)
  {
    boolean schemaDefined = false;
    LDIFReader reader = null;
    try
    try (LDIFReader reader = new LDIFReader(new LDIFImportConfig(schemaFile)))
    {
      reader = new LDIFReader(new LDIFImportConfig(schemaFile));
      Entry entry = reader.readEntry();
      if (entry != null)
      {
        schemaDefined = true;
      }
      return reader.readEntry() != null;
    }
    catch (Throwable t)
    {
      return false;
    }
    finally
    {
      StaticUtils.close(reader);
    }
    return schemaDefined;
  }
  /**
   * Returns the list of LDIF lines that are enough to create the entry
   * containing only the schema element associated with this task.
   *
   * @return the list of LDIF lines that are enough to create the entry
   * containing only the schema element associated with this task.
   *         containing only the schema element associated with this task.
   */
  private ArrayList<String> getSchemaEntryLines()
  private List<String> getSchemaEntryLines()
  {
    ArrayList<String> lines = new ArrayList<>();
    List<String> lines = new ArrayList<>();
    lines.add("dn: cn=schema");
    lines.add("objectClass: top");
    lines.add("objectClass: ldapSubentry");
@@ -645,96 +534,75 @@
    return lines;
  }
  /**
   * Updates the contents of the schema file.
   *
   * @param schemaFile the schema file.
   * @param isSchemaFileDefined whether the schema is defined or not.
   * @param attributes the attributes to add.
   * @param objectClasses the object classes to add.
   * @throws OpenDsException if an error occurs updating the schema file.
   * @param schemaFile
   *          the schema file.
   * @param isSchemaFileDefined
   *          whether the schema is defined or not.
   * @param attributes
   *          the attributes to add.
   * @param objectClasses
   *          the object classes to add.
   * @throws OpenDsException
   *           if an error occurs updating the schema file.
   */
  private void updateSchemaFile(String schemaFile,
      boolean isSchemaFileDefined,
      List<AttributeType> attributes,
      List<ObjectClass> objectClasses) throws OpenDsException
  private void updateSchemaFile(String schemaFile, List<CommonSchemaElements> schemaElements)
      throws OpenDsException
  {
    if (isSchemaFileDefined)
    try (final LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.OVERWRITE))
    {
      LDIFExportConfig exportConfig =
        new LDIFExportConfig(schemaFile,
                             ExistingFileBehavior.OVERWRITE);
      LDIFReader reader = null;
      LDIFWriter writer = null;
      try
      try (final LDIFReader reader = new LDIFReader(new LDIFImportConfig(schemaFile)))
      {
        reader = new LDIFReader(new LDIFImportConfig(schemaFile));
        Entry schemaEntry = reader.readEntry();
        for (AttributeType attribute : attributes)
        final Entry schemaEntry = reader.readEntry();
        addElementsToEntry(schemaElements, schemaEntry);
        try (final LDIFWriter writer = new LDIFWriter(exportConfig))
        {
          Modification mod = new Modification(ModificationType.ADD,
              Attributes.create(getAttributeName(attribute).toLowerCase(),
                  getValueOffline(attribute)));
          schemaEntry.applyModification(mod);
          writer.writeEntry(schemaEntry);
          exportConfig.getWriter().newLine();
        }
        for (ObjectClass oc : objectClasses)
        {
          Modification mod = new Modification(ModificationType.ADD,
              Attributes.create(getAttributeName(oc).toLowerCase(),
                  getValueOffline(oc)));
          schemaEntry.applyModification(mod);
        }
        writer = new LDIFWriter(exportConfig);
        writer.writeEntry(schemaEntry);
        exportConfig.getWriter().newLine();
      }
      catch (Throwable t)
      {
        throw new OfflineUpdateException(
            ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(t), t);
      }
      finally
      {
        StaticUtils.close(reader, exportConfig, writer);
      }
    }
    else
    {
      LDIFExportConfig exportConfig =
        new LDIFExportConfig(schemaFile,
                             ExistingFileBehavior.FAIL);
      try
      {
        ArrayList<String> lines = getSchemaEntryLines();
        for (AttributeType attribute : attributes)
        {
          lines.add(
              getAttributeName(attribute)+": "+getValueOffline(attribute));
        }
        for (ObjectClass oc : objectClasses)
        {
          lines.add(getAttributeName(oc)+": "+getValueOffline(oc));
        }
        for (String line : lines)
        {
          LDIFWriter.writeLDIFLine(new StringBuilder(line),
              exportConfig.getWriter(), exportConfig.getWrapColumn() > 1,
              exportConfig.getWrapColumn());
        }
        exportConfig.getWriter().newLine();
      }
      catch (Throwable t)
      {
        throw new OfflineUpdateException(
            ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(t), t);
      }
      finally
      {
        StaticUtils.close(exportConfig);
        throw new OfflineUpdateException(ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(t), t);
      }
    }
  }
  private void addElementsToEntry(List<CommonSchemaElements> schemaElements, Entry schemaEntry)
      throws DirectoryException
  {
    for (CommonSchemaElements schemaElement : schemaElements)
    {
      final Modification mod = new Modification(ModificationType.ADD,
          Attributes.create(getAttributeName(schemaElement).toLowerCase(), getValueOffline(schemaElement)));
      schemaEntry.applyModification(mod);
    }
  }
  private void updateSchemaUndefinedFile(String schemaFile, List<CommonSchemaElements> schemaElements)
      throws OfflineUpdateException
  {
    try (LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.FAIL))
    {
      List<String> lines = getSchemaEntryLines();
      for (final CommonSchemaElements schemaElement : schemaElements)
      {
        lines.add(getAttributeName(schemaElement) + ": " + getValueOffline(schemaElement));
      }
      for (String line : lines)
      {
        final boolean wrapLines = exportConfig.getWrapColumn() > 1;
        LDIFWriter.writeLDIFLine(
            new StringBuilder(line), exportConfig.getWriter(), wrapLines, exportConfig.getWrapColumn());
      }
      exportConfig.getWriter().newLine();
    }
    catch (Throwable t)
    {
      throw new OfflineUpdateException(ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(t), t);
    }
  }
}
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewAttributePanel.java
@@ -35,10 +35,12 @@
import java.awt.event.ItemListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -80,107 +82,90 @@
public class NewAttributePanel extends StatusGenericPanel
{
  private static final long serialVersionUID = 2340170241535771321L;
  private JLabel lName = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_NAME_LABEL.get());
  private JLabel lParent = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_PARENT_LABEL.get());
  private JLabel lOID = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_OID_LABEL.get());
  private JLabel lAliases = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_ALIASES_LABEL.get());
  private JLabel lOrigin = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_ORIGIN_LABEL.get());
  private JLabel lFile = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_FILE_LABEL.get());
  private JLabel lDescription = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_DESCRIPTION_LABEL.get());
  private JLabel lUsage = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_USAGE_LABEL.get());
  private JLabel lSyntax = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_SYNTAX_LABEL.get());
  private JLabel lApproximate = Utilities.createPrimaryLabel(
  private static final LocalizableMessage NO_PARENT = INFO_CTRL_PANEL_NO_PARENT_FOR_ATTRIBUTE.get();
  private static final LocalizableMessage NO_MATCHING_RULE = INFO_CTRL_PANEL_NO_MATCHING_RULE_FOR_ATTRIBUTE.get();
  private final JLabel lName = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_NAME_LABEL.get());
  private final JLabel lParent = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_PARENT_LABEL.get());
  private final JLabel lOID = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_OID_LABEL.get());
  private final JLabel lAliases = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_ALIASES_LABEL.get());
  private final JLabel lOrigin = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_ORIGIN_LABEL.get());
  private final JLabel lFile = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_FILE_LABEL.get());
  private final JLabel lDescription = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_DESCRIPTION_LABEL.get());
  private final JLabel lUsage = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_USAGE_LABEL.get());
  private final JLabel lSyntax = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_SYNTAX_LABEL.get());
  private final JLabel lApproximate = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_APPROXIMATE_MATCHING_RULE_LABEL.get());
  private JLabel lEquality = Utilities.createPrimaryLabel(
  private final JLabel lEquality = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_EQUALITY_MATCHING_RULE_LABEL.get());
  private JLabel lOrdering = Utilities.createPrimaryLabel(
  private final JLabel lOrdering = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_ORDERING_MATCHING_RULE_LABEL.get());
  private JLabel lSubstring = Utilities.createPrimaryLabel(
  private final JLabel lSubstring = Utilities.createPrimaryLabel(
      INFO_CTRL_PANEL_ATTRIBUTE_SUBSTRING_MATCHING_RULE_LABEL.get());
  private JLabel lType = Utilities.createPrimaryLabel();
  private final JLabel lType = Utilities.createPrimaryLabel();
  private JLabel[] labels = {lName, lParent, lOID, lAliases, lOrigin, lFile,
      lDescription, lUsage, lSyntax, lApproximate,
      lEquality, lOrdering, lSubstring, lType
  };
  private final JLabel[] labels = { lName, lParent, lOID, lAliases, lOrigin, lFile, lDescription, lUsage, lSyntax,
    lApproximate, lEquality, lOrdering, lSubstring, lType };
  private JTextField name = Utilities.createMediumTextField();
  private JComboBox parent = Utilities.createComboBox();
  private JTextField oid = Utilities.createMediumTextField();
  private JTextField aliases = Utilities.createLongTextField();
  private JTextField description = Utilities.createLongTextField();
  private JTextField origin = Utilities.createLongTextField();
  private JTextField file = Utilities.createLongTextField();
  private JComboBox usage = Utilities.createComboBox();
  private JComboBox syntax = Utilities.createComboBox();
  private JComboBox approximate = Utilities.createComboBox();
  private JComboBox equality = Utilities.createComboBox();
  private JComboBox ordering = Utilities.createComboBox();
  private JComboBox substring = Utilities.createComboBox();
  private JCheckBox nonModifiable = Utilities.createCheckBox(
  private final JTextField name = Utilities.createMediumTextField();
  private final JComboBox parent = Utilities.createComboBox();
  private final JTextField oid = Utilities.createMediumTextField();
  private final JTextField aliases = Utilities.createLongTextField();
  private final JTextField description = Utilities.createLongTextField();
  private final JTextField origin = Utilities.createLongTextField();
  private final JTextField file = Utilities.createLongTextField();
  private final JComboBox<AttributeUsage> usage = Utilities.createComboBox();
  private final JComboBox syntax = Utilities.createComboBox();
  private final JComboBox approximate = Utilities.createComboBox();
  private final JComboBox equality = Utilities.createComboBox();
  private final JComboBox ordering = Utilities.createComboBox();
  private final JComboBox substring = Utilities.createComboBox();
  private final JCheckBox nonModifiable = Utilities.createCheckBox(
      INFO_CTRL_PANEL_ATTRIBUTE_NON_MODIFIABLE_LABEL.get());
  private JCheckBox singleValued = Utilities.createCheckBox(
      INFO_CTRL_PANEL_ATTRIBUTE_SINGLE_VALUED_LABEL.get());
  private JCheckBox collective = Utilities.createCheckBox(
      INFO_CTRL_PANEL_ATTRIBUTE_COLLECTIVE_LABEL.get());
  private JCheckBox obsolete = Utilities.createCheckBox(
      INFO_CTRL_PANEL_ATTRIBUTE_OBSOLETE_LABEL.get());
  private final JCheckBox singleValued = Utilities.createCheckBox(INFO_CTRL_PANEL_ATTRIBUTE_SINGLE_VALUED_LABEL.get());
  private final JCheckBox collective = Utilities.createCheckBox(INFO_CTRL_PANEL_ATTRIBUTE_COLLECTIVE_LABEL.get());
  private final JCheckBox obsolete = Utilities.createCheckBox(INFO_CTRL_PANEL_ATTRIBUTE_OBSOLETE_LABEL.get());
  private Schema schema;
  private Component relativeComponent;
  private LocalizableMessage NO_PARENT = INFO_CTRL_PANEL_NO_PARENT_FOR_ATTRIBUTE.get();
  private LocalizableMessage NO_MATCHING_RULE =
    INFO_CTRL_PANEL_NO_MATCHING_RULE_FOR_ATTRIBUTE.get();
  private final Component relativeComponent;
  /**
   * Constructor of the new attribute panel.
   * @param relativeComponent the component relative to which the dialog
   * containing this panel must be centered.
   *
   * @param relativeComponent
   *          the component relative to which the dialog containing this panel
   *          must be centered.
   */
  public NewAttributePanel(Component relativeComponent)
  {
    super();
    this.relativeComponent = relativeComponent;
    createLayout();
  }
  /** {@inheritDoc} */
  @Override
  public LocalizableMessage getTitle()
  {
    return INFO_CTRL_PANEL_NEW_ATTRIBUTE_PANEL_TITLE.get();
  }
  /** {@inheritDoc} */
  @Override
  public Component getPreferredFocusComponent()
  {
    return name;
  }
  /** {@inheritDoc} */
  @Override
  public void configurationChanged(ConfigurationChangeEvent ev)
  {
    ArrayList<Syntax> newSyntaxes = new ArrayList<>();
    List<Syntax> newSyntaxes = new ArrayList<>();
    final ServerDescriptor desc = ev.getNewDescriptor();
    Schema s = desc.getSchema();
    final boolean firstSchema = schema == null;
    final boolean[] repack = {firstSchema};
    final boolean[] error = {false};
    final boolean[] repack = { firstSchema };
    final boolean[] error = { false };
    boolean schemaChanged;
    if (schema != null && s != null)
@@ -202,8 +187,7 @@
    if (schemaChanged)
    {
      schema = s;
      HashMap<String, Syntax> syntaxNameMap = new HashMap<>();
      Map<String, Syntax> syntaxNameMap = new HashMap<>();
      for (String key : schema.getSyntaxes().keySet())
      {
@@ -224,7 +208,7 @@
      }
      updateComboBoxModel(newSyntaxes, (DefaultComboBoxModel) syntax.getModel());
      HashMap<String, AttributeType> attributeNameMap = new HashMap<>();
      Map<String, AttributeType> attributeNameMap = new HashMap<>();
      for (String key : schema.getAttributeTypes().keySet())
      {
        AttributeType attr = schema.getAttributeType(key);
@@ -232,7 +216,7 @@
      }
      orderedKeys.clear();
      orderedKeys.addAll(attributeNameMap.keySet());
      ArrayList<Object> newParents = new ArrayList<>();
      List<Object> newParents = new ArrayList<>();
      for (String key : orderedKeys)
      {
        newParents.add(attributeNameMap.get(key));
@@ -240,12 +224,11 @@
      newParents.add(0, NO_PARENT);
      updateComboBoxModel(newParents, (DefaultComboBoxModel) parent.getModel());
      ArrayList<MatchingRule> approximateElements = new ArrayList<>();
      ArrayList<MatchingRule> equalityElements = new ArrayList<>();
      ArrayList<MatchingRule> orderingElements = new ArrayList<>();
      ArrayList<MatchingRule> substringElements = new ArrayList<>();
      HashMap<String, MatchingRule> matchingRuleNameMap = new HashMap<>();
      List<MatchingRule> approximateElements = new ArrayList<>();
      List<MatchingRule> equalityElements = new ArrayList<>();
      List<MatchingRule> orderingElements = new ArrayList<>();
      List<MatchingRule> substringElements = new ArrayList<>();
      Map<String, MatchingRule> matchingRuleNameMap = new HashMap<>();
      for (String key : schema.getMatchingRules().keySet())
      {
        MatchingRule rule = schema.getMatchingRule(key);
@@ -274,24 +257,17 @@
          substringElements.add(matchingRule);
        }
      }
      JComboBox[] combos = {approximate, equality, ordering, substring};
      ArrayList<ArrayList<MatchingRule>> ruleNames = new ArrayList<>();
      JComboBox[] combos = { approximate, equality, ordering, substring };
      List<List<MatchingRule>> ruleNames = new ArrayList<>();
      ruleNames.add(approximateElements);
      ruleNames.add(equalityElements);
      ruleNames.add(orderingElements);
      ruleNames.add(substringElements);
      for (int i=0; i<combos.length; i++)
      for (int i = 0; i < combos.length; i++)
      {
        DefaultComboBoxModel model = (DefaultComboBoxModel)combos[i].getModel();
        ArrayList<Object> el = new ArrayList<Object>(ruleNames.get(i));
        if (model.getSize() == 0)
        {
          el.add(0, NO_MATCHING_RULE);
        }
        else
        {
          el.add(0, model.getElementAt(0));
        }
        DefaultComboBoxModel model = (DefaultComboBoxModel) combos[i].getModel();
        List<Object> el = new ArrayList<Object>(ruleNames.get(i));
        el.add(0, model.getSize() == 0 ? NO_MATCHING_RULE : model.getElementAt(0));
        updateComboBoxModel(el, model);
      }
    }
@@ -307,7 +283,6 @@
    }
    SwingUtilities.invokeLater(new Runnable()
    {
      /** {@inheritDoc} */
      @Override
      public void run()
      {
@@ -315,9 +290,9 @@
        errorPane.setVisible(error[0]);
        if (firstSchema)
        {
          for (int i=0; i<syntax.getModel().getSize(); i++)
          for (int i = 0; i < syntax.getModel().getSize(); i++)
          {
            Syntax syn = (Syntax)syntax.getModel().getElementAt(i);
            Syntax syn = (Syntax) syntax.getModel().getElementAt(i);
            if ("DirectoryString".equals(syn.getName()))
            {
              syntax.setSelectedIndex(i);
@@ -335,9 +310,7 @@
          packParentDialog();
          if (relativeComponent != null)
          {
            Utilities.centerGoldenMean(
                Utilities.getParentDialog(NewAttributePanel.this),
                relativeComponent);
            Utilities.centerGoldenMean(Utilities.getParentDialog(NewAttributePanel.this), relativeComponent);
          }
        }
      }
@@ -345,17 +318,15 @@
    if (!error[0])
    {
      updateErrorPaneAndOKButtonIfAuthRequired(desc,
          isLocal() ?
     INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_TO_CREATE_ATTRIBUTE_SUMMARY.get() :
     INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
          isLocal() ? INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_TO_CREATE_ATTRIBUTE_SUMMARY.get()
                    : INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
    }
  }
  /** {@inheritDoc} */
  @Override
  public void okClicked()
  {
    ArrayList<LocalizableMessage> errors = new ArrayList<>();
    List<LocalizableMessage> errors = new ArrayList<>();
    for (JLabel label : labels)
    {
      setPrimaryValid(label);
@@ -429,30 +400,26 @@
    }
    setPrimaryValid(lUsage);
    if (nonModifiable.isSelected()
        && AttributeUsage.USER_APPLICATIONS.equals(usage.getSelectedItem()))
    if (nonModifiable.isSelected() && AttributeUsage.USER_APPLICATIONS.equals(usage.getSelectedItem()))
    {
      errors.add(ERR_NON_MODIFIABLE_CANNOT_BE_USER_APPLICATIONS.get());
      setPrimaryInvalid(lUsage);
    }
    ProgressDialog dlg = new ProgressDialog(
        Utilities.createFrame(),
        Utilities.getParentDialog(this),
    ProgressDialog dlg = new ProgressDialog(Utilities.createFrame(), Utilities.getParentDialog(this),
        INFO_CTRL_PANEL_NEW_ATTRIBUTE_PANEL_TITLE.get(), getInfo());
    NewSchemaElementsTask newTask = null;
    if (errors.isEmpty())
    {
      LinkedHashSet<AttributeType> attributes = new LinkedHashSet<>();
      Set<AttributeType> attributes = new LinkedHashSet<>();
      attributes.add(getAttribute());
      LinkedHashSet<ObjectClass> ocs = new LinkedHashSet<>(0);
      Set<ObjectClass> ocs = new LinkedHashSet<>(0);
      newTask = new NewSchemaElementsTask(getInfo(), dlg, ocs, attributes);
      for (Task task : getInfo().getTasks())
      {
        task.canLaunch(newTask, errors);
      }
      for (ConfigurationElementCreatedListener listener :
        getConfigurationElementCreatedListeners())
      for (ConfigurationElementCreatedListener listener : getConfigurationElementCreatedListeners())
      {
        newTask.addConfigurationElementCreatedListener(listener);
      }
@@ -461,13 +428,13 @@
    {
      String attrName = getAttributeName();
      launchOperation(newTask,
          INFO_CTRL_PANEL_CREATING_ATTRIBUTE_SUMMARY.get(attrName),
          INFO_CTRL_PANEL_CREATING_ATTRIBUTE_COMPLETE.get(),
          INFO_CTRL_PANEL_CREATING_ATTRIBUTE_SUCCESSFUL.get(attrName),
          ERR_CTRL_PANEL_CREATING_ATTRIBUTE_ERROR_SUMMARY.get(),
          ERR_CTRL_PANEL_CREATING_ATTRIBUTE_ERROR_DETAILS.get(attrName),
          null,
          dlg);
                      INFO_CTRL_PANEL_CREATING_ATTRIBUTE_SUMMARY.get(attrName),
                      INFO_CTRL_PANEL_CREATING_ATTRIBUTE_COMPLETE.get(),
                      INFO_CTRL_PANEL_CREATING_ATTRIBUTE_SUCCESSFUL.get(attrName),
                      ERR_CTRL_PANEL_CREATING_ATTRIBUTE_ERROR_SUMMARY.get(),
                      ERR_CTRL_PANEL_CREATING_ATTRIBUTE_ERROR_DETAILS.get(attrName),
                      null,
                      dlg);
      dlg.setVisible(true);
      name.setText("");
      oid.setText("");
@@ -484,8 +451,11 @@
  /**
   * Returns the message representing the schema element type.
   * @param name the name of the schema element.
   * @param schema the schema.
   *
   * @param name
   *          the name of the schema element.
   * @param schema
   *          the schema.
   * @return the message representing the schema element type.
   */
  static LocalizableMessage getSchemaElementType(String name, Schema schema)
@@ -528,10 +498,7 @@
    return null;
  }
  /**
   * Creates the layout of the panel (but the contents are not populated here).
   */
  /** Creates the layout of the panel (but the contents are not populated here). */
  private void createLayout()
  {
    GridBagConstraints gbc = new GridBagConstraints();
@@ -541,7 +508,7 @@
    gbc.gridy = 0;
    addErrorPane(gbc);
    gbc.gridy ++;
    gbc.gridy++;
    gbc.gridwidth = 1;
    gbc.weighty = 0.0;
    gbc.gridx = 1;
@@ -551,27 +518,23 @@
    gbc.insets.bottom = 10;
    add(requiredLabel, gbc);
    gbc.gridy ++;
    gbc.gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets.bottom = 0;
    JComboBox[] comboBoxes = {parent, syntax, approximate,
        equality, ordering, substring};
    LocalizableMessage[] defaultValues = {NO_PARENT, LocalizableMessage.EMPTY, NO_MATCHING_RULE,
        NO_MATCHING_RULE, NO_MATCHING_RULE, NO_MATCHING_RULE
    };
    SchemaElementComboBoxCellRenderer renderer = new
    SchemaElementComboBoxCellRenderer(syntax);
    for (int i=0; i<comboBoxes.length; i++)
    JComboBox[] comboBoxes = { parent, syntax, approximate, equality, ordering, substring };
    LocalizableMessage[] defaultValues =
        { NO_PARENT, LocalizableMessage.EMPTY, NO_MATCHING_RULE, NO_MATCHING_RULE, NO_MATCHING_RULE, NO_MATCHING_RULE };
    SchemaElementComboBoxCellRenderer renderer = new SchemaElementComboBoxCellRenderer(syntax);
    for (int i = 0; i < comboBoxes.length; i++)
    {
      DefaultComboBoxModel model = new DefaultComboBoxModel(
          new Object[]{defaultValues[i]});
      DefaultComboBoxModel model = new DefaultComboBoxModel(new Object[] { defaultValues[i] });
      comboBoxes[i].setModel(model);
      comboBoxes[i].setRenderer(renderer);
    }
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    DefaultComboBoxModel<AttributeUsage> model = new DefaultComboBoxModel<AttributeUsage>();
    for (AttributeUsage us : AttributeUsage.values())
    {
      model.addElement(us);
@@ -580,44 +543,32 @@
    usage.setSelectedItem(AttributeUsage.USER_APPLICATIONS);
    usage.setRenderer(renderer);
    Component[] basicComps = {name, oid, description,
        syntax};
    JLabel[] basicLabels = {lName, lOID, lDescription, lSyntax};
    JLabel[] basicInlineHelp = new JLabel[] {null, null, null,
        Utilities.createInlineHelpLabel(
            INFO_CTRL_PANEL_SYNTAX_INLINE_HELP.get())};
    Component[] basicComps = { name, oid, description, syntax };
    JLabel[] basicLabels = { lName, lOID, lDescription, lSyntax };
    JLabel[] basicInlineHelp = new JLabel[] {
      null, null, null, Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_SYNTAX_INLINE_HELP.get()) };
    add(basicLabels, basicComps, basicInlineHelp, this, gbc);
    BasicExpander[] expanders = new BasicExpander[] {
        new BasicExpander(INFO_CTRL_PANEL_EXTRA_OPTIONS_EXPANDER.get()),
        new BasicExpander(
            INFO_CTRL_PANEL_ATTRIBUTE_TYPE_OPTIONS_EXPANDER.get()),
        new BasicExpander(INFO_CTRL_PANEL_MATCHING_RULE_OPTIONS_EXPANDER.get())
    };
          new BasicExpander(INFO_CTRL_PANEL_EXTRA_OPTIONS_EXPANDER.get()),
          new BasicExpander(INFO_CTRL_PANEL_ATTRIBUTE_TYPE_OPTIONS_EXPANDER.get()),
          new BasicExpander(INFO_CTRL_PANEL_MATCHING_RULE_OPTIONS_EXPANDER.get()) };
    Component[][] comps = {{parent, aliases, origin, file},
        {usage, singleValued, nonModifiable, collective, obsolete},
        {approximate, equality, ordering, substring}};
    JLabel[][] labels = {{lParent, lAliases, lOrigin, lFile},
        {lUsage, lType, null, null, null},
        {lApproximate, lEquality, lOrdering, lSubstring}};
    JLabel[][] inlineHelps = {{null,
      Utilities.createInlineHelpLabel(
          INFO_CTRL_PANEL_SEPARATED_WITH_COMMAS_HELP.get()), null,
      Utilities.createInlineHelpLabel(
          INFO_CTRL_PANEL_SCHEMA_FILE_ATTRIBUTE_HELP.get(File.separator))},
      {null, null, null, null, null, null},
      {Utilities.createInlineHelpLabel(
          INFO_CTRL_PANEL_MATCHING_RULE_APPROXIMATE_HELP.get()),
        Utilities.createInlineHelpLabel(
            INFO_CTRL_PANEL_MATCHING_RULE_EQUALITY_HELP.get()),
        Utilities.createInlineHelpLabel(
            INFO_CTRL_PANEL_MATCHING_RULE_ORDERING_HELP.get()),
        Utilities.createInlineHelpLabel(
            INFO_CTRL_PANEL_MATCHING_RULE_SUBSTRING_HELP.get())
      }
    };
    for (int i=0; i<expanders.length; i++)
    Component[][] comps = { { parent, aliases, origin, file },
                            { usage, singleValued, nonModifiable, collective, obsolete },
                            { approximate, equality, ordering, substring } };
    JLabel[][] labels ={ { lParent, lAliases, lOrigin, lFile },
                         { lUsage, lType, null, null, null },
                         { lApproximate, lEquality, lOrdering, lSubstring } };
    JLabel[][] inlineHelps = {
          { null, Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_SEPARATED_WITH_COMMAS_HELP.get()), null,
            Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_SCHEMA_FILE_ATTRIBUTE_HELP.get(File.separator)) },
          { null, null, null, null, null, null },
          { Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_MATCHING_RULE_APPROXIMATE_HELP.get()),
            Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_MATCHING_RULE_EQUALITY_HELP.get()),
            Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_MATCHING_RULE_ORDERING_HELP.get()),
            Utilities.createInlineHelpLabel(INFO_CTRL_PANEL_MATCHING_RULE_SUBSTRING_HELP.get()) } };
    for (int i = 0; i < expanders.length; i++)
    {
      gbc.gridwidth = 2;
      gbc.gridx = 0;
@@ -625,9 +576,9 @@
      add(expanders[i], gbc);
      final JPanel p = new JPanel(new GridBagLayout());
      gbc.insets.left = 15;
      gbc.gridy ++;
      gbc.gridy++;
      add(p, gbc);
      gbc.gridy ++;
      gbc.gridy++;
      p.setOpaque(false);
      GridBagConstraints gbc1 = new GridBagConstraints();
@@ -638,7 +589,6 @@
      final BasicExpander expander = expanders[i];
      ChangeListener changeListener = new ChangeListener()
      {
        /** {@inheritDoc} */
        @Override
        public void stateChanged(ChangeEvent e)
        {
@@ -653,7 +603,6 @@
    ItemListener itemListener = new ItemListener()
    {
      /** {@inheritDoc} */
      @Override
      public void itemStateChanged(ItemEvent ev)
      {
@@ -672,29 +621,26 @@
    file.setText(ConfigConstants.FILE_USER_SCHEMA_ELEMENTS);
  }
  private void updateDefaultMatchingRuleNames()
  {
    Syntax syn = (Syntax)syntax.getSelectedItem();
    Syntax syn = (Syntax) syntax.getSelectedItem();
    if (syn != null)
    {
      MatchingRule[] rules = {syn.getApproximateMatchingRule(),
          syn.getSubstringMatchingRule(),
          syn.getEqualityMatchingRule(),
          syn.getOrderingMatchingRule()};
      JComboBox[] combos = {approximate, substring, equality, ordering};
      for (int i=0; i<rules.length; i++)
      MatchingRule[] rules = { syn.getApproximateMatchingRule(), syn.getSubstringMatchingRule(),
        syn.getEqualityMatchingRule(), syn.getOrderingMatchingRule() };
      JComboBox[] combos = { approximate, substring, equality, ordering };
      for (int i = 0; i < rules.length; i++)
      {
        DefaultComboBoxModel model = (DefaultComboBoxModel)combos[i].getModel();
        DefaultComboBoxModel model = (DefaultComboBoxModel) combos[i].getModel();
        int index = combos[i].getSelectedIndex();
        if (model.getSize() > 0)
        {
          model.removeElementAt(0);
        }
        final LocalizableMessage msg = rules[i] != null
            ? INFO_CTRL_PANEL_DEFAULT_DEFINED_IN_SYNTAX.get(rules[i].getNameOrOID())
            : NO_MATCHING_RULE;
        final LocalizableMessage msg =
            rules[i] != null ? INFO_CTRL_PANEL_DEFAULT_DEFINED_IN_SYNTAX.get(rules[i].getNameOrOID())
                             : NO_MATCHING_RULE;
        model.insertElementAt(msg, 0);
        combos[i].setSelectedIndex(index);
      }
@@ -711,14 +657,14 @@
    String o = oid.getText().trim();
    if (o.length() == 0)
    {
      o = getAttributeName()+"-oid";
      o = getAttributeName() + "-oid";
    }
    return o;
  }
  private ArrayList<String> getAliases()
  private List<String> getAliases()
  {
    ArrayList<String> al = new ArrayList<>();
    List<String> al = new ArrayList<>();
    String s = aliases.getText().trim();
    if (s.length() > 0)
    {
@@ -731,9 +677,9 @@
    return al;
  }
  private ArrayList<String> getAllNames()
  private List<String> getAllNames()
  {
    ArrayList<String> al = new ArrayList<>();
    List<String> al = new ArrayList<>();
    al.add(getAttributeName());
    al.addAll(getAliases());
    return al;
@@ -780,24 +726,22 @@
  private Map<String, List<String>> getExtraProperties()
  {
    Map<String, List<String>> map = new HashMap<>();
    String f = file.getText().trim();
    if (f.length() > 0)
    {
      ArrayList<String> list = new ArrayList<>();
      list.add(f);
      map.put(ServerConstants.SCHEMA_PROPERTY_FILENAME, list);
    }
    String or = origin.getText().trim();
    if (or.length() > 0)
    {
      ArrayList<String> list = new ArrayList<>();
      list.add(or);
      map.put(ServerConstants.SCHEMA_PROPERTY_ORIGIN, list);
    }
    final Map<String, List<String>> map = new HashMap<>();
    addExtraPropertyFromTextField(file, ServerConstants.SCHEMA_PROPERTY_FILENAME, map);
    addExtraPropertyFromTextField(origin, ServerConstants.SCHEMA_PROPERTY_ORIGIN, map);
    return map;
  }
  private void addExtraPropertyFromTextField(
      final JTextField value, final String key, final Map<String, List<String>> map)
  {
    final String trimmedValue = value.getText().trim();
    if (!trimmedValue.trim().isEmpty())
    {
      map.put(key, Arrays.asList(trimmedValue));
    }
  }
  private String getDescription()
  {
    return description.getText().trim();
@@ -805,19 +749,22 @@
  private AttributeType getAttribute()
  {
    return new AttributeType("", getAttributeName(),
        getAllNames(),
        getOID(),
        getDescription(),
        getSuperior(),
        (Syntax)syntax.getSelectedItem(),
        getApproximateMatchingRule(),
        getEqualityMatchingRule(),
        getOrderingMatchingRule(),
        getSubstringMatchingRule(),
        (AttributeUsage)usage.getSelectedItem(),
        collective.isSelected(), nonModifiable.isSelected(),
        obsolete.isSelected(), singleValued.isSelected(),
        getExtraProperties());
    return new AttributeType("",
                             getAttributeName(),
                             getAllNames(),
                             getOID(),
                             getDescription(),
                             getSuperior(),
                             (Syntax) syntax.getSelectedItem(),
                             getApproximateMatchingRule(),
                             getEqualityMatchingRule(),
                             getOrderingMatchingRule(),
                             getSubstringMatchingRule(),
                             (AttributeUsage) usage.getSelectedItem(),
                             collective.isSelected(),
                             nonModifiable.isSelected(),
                             obsolete.isSelected(),
                             singleValued.isSelected(),
                             getExtraProperties());
  }
}
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -170,11 +170,14 @@
  /**
   * Creates a combo box.
   *
   * @param <T>
   *          The combo box data type.
   * @return a combo box.
   */
  public static JComboBox createComboBox()
  public static <T> JComboBox<T> createComboBox()
  {
    JComboBox combo = new JComboBox();
    JComboBox<T> combo = new JComboBox<>();
    if (isMacOS())
    {
      combo.setOpaque(false);