From 60ffb9a7138362d45f6d3f0c2aebb123d5ee3b1d Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Thu, 09 Apr 2015 12:41:47 +0000
Subject: [PATCH] OPENDJ-1714 (CR-6595) UI setup backend type choice

---
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/FieldName.java                  |    3 +
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java                    |   17 +++++++-
 opendj-sdk/opendj-server-legacy/src/messages/org/opends/messages/quickSetup.properties                 |    7 ++-
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataOptionsPanel.java |   57 ++++++++++++++++++++++++++--
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java           |    9 ----
 5 files changed, 76 insertions(+), 17 deletions(-)

diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index 7cede49..adc5739 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -122,7 +122,6 @@
 import org.opends.quicksetup.util.FileManager;
 import org.opends.quicksetup.util.IncompatibleVersionException;
 import org.opends.quicksetup.util.Utils;
-import org.opends.server.tools.BackendTypeHelper;
 import org.opends.server.util.CertificateManager;
 import org.opends.server.util.DynamicConstants;
 import org.opends.server.util.SetupUtils;
@@ -873,13 +872,6 @@
     argList.add("-w");
     argList.add(getUserData().getDirectoryManagerPwd());
 
-    //FIXME Remove once graphical setup will allow backend type choice
-    if (getUserData().getBackendType() == null)
-    {
-      BackendTypeHelper helper = new BackendTypeHelper();
-      getUserData().setBackendType(helper.getBackendTypeNames().get(0));
-    }
-
     argList.add("--" + OPTION_LONG_BACKEND_TYPE);
     argList.add(getUserData().getBackendType());
 
@@ -3748,6 +3740,7 @@
 
     if (dataOptions != null)
     {
+      getUserData().setBackendType(ui.getFieldStringValue(FieldName.BACKEND_TYPE));
       getUserData().setNewSuffixOptions(dataOptions);
     }
 
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataOptionsPanel.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataOptionsPanel.java
index ac34991..4615583 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataOptionsPanel.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/DataOptionsPanel.java
@@ -40,7 +40,9 @@
 
 import javax.swing.Box;
 import javax.swing.ButtonGroup;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
+import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
@@ -58,6 +60,7 @@
 import org.opends.quicksetup.ui.QuickSetupStepPanel;
 import org.opends.quicksetup.ui.UIFactory;
 import org.opends.quicksetup.ui.Utilities;
+import org.opends.server.tools.BackendTypeHelper;
 
 /**
  * This is the panel that contains the Data Options: the suffix dn, whether to
@@ -80,6 +83,8 @@
 
   private JButton ldifBrowseButton;
 
+  private JComboBox backendTypeComboBox;
+
   /**
    * Constructor of the panel.
    *
@@ -91,6 +96,7 @@
     super(application);
     this.defaultUserData = application.getUserData();
     populateComponentMaps();
+    createBackendTypeComboBox();
     addDocumentListeners();
     addFocusListeners();
     addActionListeners();
@@ -108,7 +114,10 @@
           return type;
         }
       }
-
+    }
+    else if (FieldName.BACKEND_TYPE == fieldName)
+    {
+      return backendTypeComboBox.getSelectedItem().toString();
     }
     else
     {
@@ -151,6 +160,7 @@
 
     GridBagConstraints gbc = new GridBagConstraints();
     // Add the server location widgets
+    addBackendTypeSection(panel, gbc);
     addBaseDNSection(panel, gbc);
 
     int h1 = getLabel(FieldName.DATA_OPTIONS).getPreferredSize().height;
@@ -175,14 +185,14 @@
     return panel;
   }
 
-  private void addBaseDNSection(final JPanel panel, final GridBagConstraints gbc)
+  private void addBackendTypeSection(final JPanel panel, final GridBagConstraints gbc)
   {
     gbc.gridwidth = GridBagConstraints.RELATIVE;
     gbc.weightx = 0.0;
     gbc.insets.top = 0;
     gbc.insets.left = 0;
     gbc.anchor = GridBagConstraints.WEST;
-    panel.add(getLabel(FieldName.DIRECTORY_BASE_DN), gbc);
+    panel.add(getLabel(FieldName.BACKEND_TYPE), gbc);
 
     JPanel auxPanel = new JPanel(new GridBagLayout());
     auxPanel.setOpaque(false);
@@ -190,7 +200,7 @@
     gbc.insets = UIFactory.getEmptyInsets();
     gbc.fill = GridBagConstraints.HORIZONTAL;
     gbc.weightx = 0.0;
-    auxPanel.add(getField(FieldName.DIRECTORY_BASE_DN), gbc);
+    auxPanel.add(backendTypeComboBox, gbc);
 
     gbc.gridwidth = GridBagConstraints.REMAINDER;
     gbc.insets.left = UIFactory.LEFT_INSET_BROWSE;
@@ -203,6 +213,35 @@
     gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
     gbc.gridwidth = GridBagConstraints.REMAINDER;
     panel.add(auxPanel, gbc);
+  }
+
+  private void addBaseDNSection(final JPanel panel, final GridBagConstraints gbc)
+  {
+    gbc.gridwidth = GridBagConstraints.RELATIVE;
+    gbc.weightx = 0.0;
+    gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
+    gbc.insets.left = 0;
+    gbc.anchor = GridBagConstraints.WEST;
+    panel.add(getLabel(FieldName.DIRECTORY_BASE_DN), gbc);
+
+    final JPanel auxPanel = new JPanel(new GridBagLayout());
+    auxPanel.setOpaque(false);
+    gbc.weightx = 1.0;
+    gbc.fill = GridBagConstraints.HORIZONTAL;
+    gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
+    gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
+    gbc.gridwidth = GridBagConstraints.REMAINDER;
+    panel.add(auxPanel, gbc);
+
+    gbc.gridwidth = GridBagConstraints.RELATIVE;
+    gbc.insets = UIFactory.getEmptyInsets();
+    gbc.weightx = 0.0;
+    auxPanel.add(getField(FieldName.DIRECTORY_BASE_DN), gbc);
+
+    gbc.gridwidth = GridBagConstraints.REMAINDER;
+    gbc.weightx = 1.0;
+    gbc.fill = GridBagConstraints.HORIZONTAL;
+    auxPanel.add(Box.createHorizontalGlue(), gbc);
 
     gbc.gridwidth = GridBagConstraints.RELATIVE;
     gbc.weightx = 0.0;
@@ -394,10 +433,20 @@
     final JLabel dataLabel = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON, INFO_DIRECTORY_DATA_LABEL.get(),
                                                   UIFactory.TextStyle.PRIMARY_FIELD_VALID);
     hmLabels.put(FieldName.DATA_OPTIONS, dataLabel);
+
+    final JLabel backendTypeLabel = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON, INFO_BACKEND_TYPE_LABEL.get(),
+                                                         UIFactory.TextStyle.PRIMARY_FIELD_VALID);
+    hmLabels.put(FieldName.BACKEND_TYPE, backendTypeLabel);
     createDirectoryDataChoiceRadioButton(dataLabel);
     checkEnablingState();
   }
 
+  private void createBackendTypeComboBox()
+  {
+    final BackendTypeHelper backendTypeHelper = new BackendTypeHelper();
+    backendTypeComboBox = new JComboBox(new DefaultComboBoxModel(backendTypeHelper.getBackendTypeNames().toArray()));
+  }
+
   private void createDirectoryDataChoiceRadioButton(final JLabel dataLabel)
   {
     final JRadioButton createBaseEntryRB = UIFactory.makeJRadioButton(
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/FieldName.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/FieldName.java
index 7d9a308..9d0d109 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/FieldName.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/FieldName.java
@@ -45,6 +45,9 @@
   /** The value associated with this is a data options.Type. */
   DATA_OPTIONS,
 
+  /** The value associated with this is a String. **/
+  BACKEND_TYPE,
+
   /** The value associated with this is a String. */
   DIRECTORY_BASE_DN,
 
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
index 6211a84..2e2ad0a 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
@@ -60,6 +60,8 @@
 import org.opends.server.util.SetupUtils;
 import org.opends.server.util.StaticUtils;
 
+import com.forgerock.opendj.cli.ArgumentConstants;
+
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.OperatingSystem.*;
 
@@ -1379,6 +1381,7 @@
 
     final DataReplicationOptions repl = userInstallData.getReplicationOptions();
     final SuffixesToReplicateOptions suf = userInstallData.getSuffixesToReplicateOptions();
+    final String backendType = userInstallData.getBackendType();
 
     boolean createSuffix = repl.getType() == DataReplicationOptions.Type.FIRST_IN_TOPOLOGY
         || repl.getType() == DataReplicationOptions.Type.STANDALONE
@@ -1417,11 +1420,12 @@
       }
       else if (options.getBaseDns().size() > 1)
       {
-        msg = INFO_REVIEW_CREATE_SUFFIX.get(joinAsString(Constants.LINE_SEPARATOR, options.getBaseDns()), arg2);
+        msg = INFO_REVIEW_CREATE_SUFFIX.get(
+            backendType, joinAsString(Constants.LINE_SEPARATOR, options.getBaseDns()), arg2);
       }
       else
       {
-        msg = INFO_REVIEW_CREATE_SUFFIX.get(options.getBaseDns().getFirst(), arg2);
+        msg = INFO_REVIEW_CREATE_SUFFIX.get(backendType, options.getBaseDns().getFirst(), arg2);
       }
     }
     else
@@ -1631,7 +1635,14 @@
     cmdLine.add(getInstallDir(userData) + getSetupFilename());
     cmdLine.add("--cli");
 
-    for (final String baseDN : getBaseDNs(userData))
+    final List<String> baseDNs = getBaseDNs(userData);
+    if (!baseDNs.isEmpty())
+    {
+      cmdLine.add("--" + ArgumentConstants.OPTION_LONG_BACKEND_TYPE);
+      cmdLine.add(userData.getBackendType());
+    }
+
+    for (final String baseDN : baseDNs)
     {
       cmdLine.add("--baseDN");
       cmdLine.add(baseDN);
diff --git a/opendj-sdk/opendj-server-legacy/src/messages/org/opends/messages/quickSetup.properties b/opendj-sdk/opendj-server-legacy/src/messages/org/opends/messages/quickSetup.properties
index 3885cae..07084a7 100644
--- a/opendj-sdk/opendj-server-legacy/src/messages/org/opends/messages/quickSetup.properties
+++ b/opendj-sdk/opendj-server-legacy/src/messages/org/opends/messages/quickSetup.properties
@@ -20,7 +20,7 @@
 # CDDL HEADER END
 #
 #      Copyright 2006-2010 Sun Microsystems, Inc.
-#      Portions Copyright 2010-2014 ForgeRock AS
+#      Portions Copyright 2010-2015 ForgeRock AS
 
 
 
@@ -670,7 +670,7 @@
  replication updates between this server and the other servers.
 INFO_RUNTIME_OPTIONS_LABEL=Runtime Options:
 INFO_REVIEW_CREATE_BASE_ENTRY_LABEL=Only Create Base Entry (%s)
-INFO_REVIEW_CREATE_SUFFIX=Create New Base DN %s.%nBase DN Data: %s
+INFO_REVIEW_CREATE_SUFFIX=Backend Type: %s%nCreate New Base DN %s%nBase DN Data: %s
 INFO_REVIEW_CREATE_NO_SUFFIX=Do not Create a Base DN
 INFO_REVIEW_IMPORT_AUTOMATICALLY_GENERATED=Import Automatically-Generated \
  Data (%s Entries)
@@ -984,3 +984,6 @@
  volume of data. It is recommended to increase the maximum memory allowed for \
  the server runtime.<br><br>Check the documentation for more information \
  about how to tune the server.
+INFO_BACKEND_TYPE_LABEL=Backend Type:
+INFO_BACKEND_TYPE_TOOLTIP=Select the type of backend in which you want to \
+ store your data

--
Gitblit v1.10.0