001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027
028package org.opends.guitools.controlpanel.ui;
029
030import static org.opends.messages.AdminToolMessages.*;
031
032import java.util.ArrayList;
033import javax.swing.JLabel;
034import javax.swing.JTextField;
035
036import org.opends.guitools.controlpanel.util.Utilities;
037import org.forgerock.i18n.LocalizableMessage;
038
039/**
040 * The panel to create a domain.
041 *
042 */
043public class NewDomainPanel extends NewOrganizationPanel
044{
045  private static final long serialVersionUID = -595396547491445219L;
046
047  /** {@inheritDoc} */
048  public LocalizableMessage getTitle()
049  {
050    return INFO_CTRL_NEW_DOMAIN_PANEL_TITLE.get();
051  }
052
053  /** {@inheritDoc} */
054  protected LocalizableMessage getProgressDialogTitle()
055  {
056    return INFO_CTRL_NEW_DOMAIN_PANEL_TITLE.get();
057  }
058
059  /** {@inheritDoc} */
060  protected void checkSyntax(ArrayList<LocalizableMessage> errors)
061  {
062    for (JLabel label : labels)
063    {
064      setPrimaryValid(label);
065    }
066
067    JTextField[] requiredFields = {name};
068    LocalizableMessage[] msgs = {ERR_CTRL_PANEL_NAME_OF_DOMAIN_REQUIRED.get()};
069    for (int i=0; i<requiredFields.length; i++)
070    {
071      String v = requiredFields[i].getText().trim();
072      if (v.length() == 0)
073      {
074        errors.add(msgs[i]);
075      }
076    }
077  }
078
079  /** {@inheritDoc} */
080  protected void updateDNValue()
081  {
082    String value = name.getText().trim();
083    if (value.length() > 0)
084    {
085       String rdn = Utilities.getRDNString("dc", value);
086          dn.setText(rdn+","+parentNode.getDN());
087    }
088    else
089    {
090      dn.setText(","+parentNode.getDN());
091    }
092  }
093
094  /** {@inheritDoc} */
095  protected String getLDIF()
096  {
097    StringBuilder sb = new StringBuilder();
098    sb.append("dn: ").append(dn.getText()).append("\n");
099    String[] attrNames = {"dc", "description"};
100    JTextField[] textFields = {name, description};
101    sb.append("objectclass: top\n");
102    sb.append("objectclass: domain\n");
103    for (int i=0; i<attrNames.length; i++)
104    {
105      String value = textFields[i].getText().trim();
106      if (value.length() > 0)
107      {
108        sb.append(attrNames[i]).append(": ").append(value).append("\n");
109      }
110    }
111    return sb.toString();
112  }
113}