From 6ba68335869125edfab5ebc453994d77ee93516c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 17 Nov 2008 02:02:49 +0000
Subject: [PATCH] Fix for issue 3588 (Control Panel : not all Base DN available for VLV index creation) Set the name of the backend that is being displayed in the 'Manage Index' window when the user clicks on 'New Index...' or 'New VLV Index...' buttons.

---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/IndexPanel.java            |    1 
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java         |    2 
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java      |   12 +++
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java    |   17 +++++
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java |   18 ++++--
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java      |   48 ++++++++++++---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewIndexPanel.java         |   25 +++++---
 7 files changed, 96 insertions(+), 27 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
index 2d884a1..e86358d 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
@@ -75,6 +75,15 @@
    */
   protected JLabel name = Utilities.createDefaultLabel();
   /**
+   * Backends label.
+   */
+  protected JLabel lBackend = Utilities.createPrimaryLabel(
+      INFO_CTRL_PANEL_BACKEND_LABEL.get());
+  /**
+   * Read-only backend name label.
+   */
+  protected JLabel backendName = Utilities.createDefaultLabel();
+  /**
    * Label for attribute.
    */
   protected JLabel lAttribute =
@@ -301,6 +310,14 @@
     gbc.gridy ++;
     gbc.insets.left = 0;
     gbc.gridx = 0;
+    c.add(lBackend, gbc);
+    gbc.insets.left = 10;
+    gbc.gridx = 1;
+    c.add(backendName, gbc);
+
+    gbc.gridy ++;
+    gbc.insets.left = 0;
+    gbc.gridx = 0;
     c.add(lEntryLimit, gbc);
     gbc.insets.left = 10;
     gbc.gridx = 1;
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
index 322f6bc..fa9588a 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
@@ -68,7 +68,6 @@
 import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
 import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.VLVSortOrder;
-import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
 import org.opends.guitools.controlpanel.ui.components.TitlePanel;
 import org.opends.guitools.controlpanel.ui.renderer.CustomListCellRenderer;
 import org.opends.guitools.controlpanel.ui.renderer.IndexComboBoxCellRenderer;
@@ -321,6 +320,15 @@
   }
 
   /**
+   * Sets the name of the backend where the index is defined or will be defined.
+   * @param backendID the ID of the backend.
+   */
+  public void setBackendName(String backendID)
+  {
+    backendName.setText(backendID);
+  }
+
+  /**
    * Returns the LDIF representing the new index.
    * @param indexName the name of the index.
    * @return the LDIF representing the new index.
@@ -419,15 +427,13 @@
 
 
   /**
-   * Updates the layout with the new changed configuration event.
-   * @param ev the configuration change event.
+   * Updates the layout with the provided server descriptor.
+   * @param desc the server descriptor.
    * @return <CODE>true</CODE> if an error has been displayed and
    * <CODE>false</CODE> otherwise.
    */
-  protected boolean updateLayout(ConfigurationChangeEvent ev)
+  protected boolean updateLayout(final ServerDescriptor desc)
   {
-    final ServerDescriptor desc = ev.getNewDescriptor();
-
     Schema schema = desc.getSchema();
     BackendDescriptor backend = getBackend();
     final boolean[] repack = {false};
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java
index 3c5bbad..8f2fb37 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/BrowseIndexPanel.java
@@ -115,7 +115,9 @@
   private JMenuItem deleteMenuItem;
 
   private GenericDialog newIndexDialog;
+  private NewIndexPanel newIndexPanel;
   private GenericDialog newVLVIndexDialog;
+  private NewVLVIndexPanel newVLVIndexPanel;
 
   private boolean ignoreSelectionEvents;
 
@@ -772,16 +774,16 @@
 
   private void newIndexClicked()
   {
-    if (newIndexDialog == null)
+    if (newIndexPanel == null)
     {
-      NewIndexPanel panel =
+      newIndexPanel =
         new NewIndexPanel((String)backends.getSelectedItem(),
           Utilities.getParentDialog(this));
-      panel.setInfo(getInfo());
-      newIndexDialog = new GenericDialog(null, panel);
+      newIndexPanel.setInfo(getInfo());
+      newIndexDialog = new GenericDialog(null, newIndexPanel);
       Utilities.centerGoldenMean(newIndexDialog,
           Utilities.getParentDialog(this));
-      panel.addConfigurationElementCreatedListener(
+      newIndexPanel.addConfigurationElementCreatedListener(
           new ConfigurationElementCreatedListener()
           {
             public void elementCreated(ConfigurationElementCreatedEvent ev)
@@ -794,21 +796,34 @@
             }
           });
     }
+    else if (!newIndexDialog.isVisible())
+    {
+      String backendID = (String)backends.getSelectedItem();
+      for (BackendDescriptor backend :
+        getInfo().getServerDescriptor().getBackends())
+      {
+        if (backend.getBackendID().equalsIgnoreCase(backendID))
+        {
+          newIndexPanel.update(backend);
+          break;
+        }
+      }
+    }
     newIndexDialog.setVisible(true);
   }
 
   private void newVLVIndexClicked()
   {
-    if (newVLVIndexDialog == null)
+    if (newVLVIndexPanel == null)
     {
-      NewVLVIndexPanel panel =
+      newVLVIndexPanel =
         new NewVLVIndexPanel((String)backends.getSelectedItem(),
           Utilities.getParentDialog(this));
-      panel.setInfo(getInfo());
-      newVLVIndexDialog = new GenericDialog(null, panel);
+      newVLVIndexPanel.setInfo(getInfo());
+      newVLVIndexDialog = new GenericDialog(null, newVLVIndexPanel);
       Utilities.centerGoldenMean(newVLVIndexDialog,
           Utilities.getParentDialog(this));
-      panel.addConfigurationElementCreatedListener(
+      newVLVIndexPanel.addConfigurationElementCreatedListener(
           new ConfigurationElementCreatedListener()
           {
             /**
@@ -824,6 +839,19 @@
             }
           });
     }
+    else if (!newVLVIndexDialog.isVisible())
+    {
+      String backendID = (String)backends.getSelectedItem();
+      for (BackendDescriptor backend :
+        getInfo().getServerDescriptor().getBackends())
+      {
+        if (backend.getBackendID().equalsIgnoreCase(backendID))
+        {
+          newVLVIndexPanel.update(backend);
+          break;
+        }
+      }
+    }
     newVLVIndexDialog.setVisible(true);
   }
 
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/IndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/IndexPanel.java
index e7fa86f..11a11a8 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/IndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/IndexPanel.java
@@ -432,6 +432,7 @@
     setPrimaryValid(lEntryLimit);
     setPrimaryValid(lType);
     name.setText(index.getName());
+    backendName.setText(index.getBackend().getBackendID());
     titlePanel.setDetails(Message.raw(index.getName()));
     entryLimit.setText(String.valueOf(index.getEntryLimit()));
     approximate.setSelected(false);
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
index 091d09f..a3c82f7 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -87,8 +87,6 @@
 {
   private static final long serialVersionUID = -3516011638125862137L;
 
-  private String backendName;
-
   private Component relativeComponent;
 
   private Schema schema;
@@ -104,7 +102,7 @@
   public NewIndexPanel(String backendName, Component relativeComponent)
   {
     super();
-    this.backendName = backendName;
+    this.backendName.setText(backendName);
     this.relativeComponent = relativeComponent;
     createLayout();
   }
@@ -126,6 +124,15 @@
   }
 
   /**
+   * Updates the contents of the panel with the provided backend.
+   * @param backend the backend where the index will be created.
+   */
+  public void update(BackendDescriptor backend)
+  {
+    backendName.setText(backend.getBackendID());
+  }
+
+  /**
    * {@inheritDoc}
    */
   public void configurationChanged(ConfigurationChangeEvent ev)
@@ -146,7 +153,7 @@
       BackendDescriptor backend = null;
       for (BackendDescriptor b : getInfo().getServerDescriptor().getBackends())
       {
-        if (b.getBackendID().equalsIgnoreCase(backendName))
+        if (b.getBackendID().equalsIgnoreCase(backendName.getText()))
         {
           backend = b;
           break;
@@ -403,7 +410,7 @@
     {
       super(info, dlg);
       backendSet = new HashSet<String>();
-      backendSet.add(backendName);
+      backendSet.add(backendName.getText());
       attributeName = getAttributeName();
       entryLimitValue = Integer.parseInt(entryLimit.getText());
       indexTypes = getTypes();
@@ -431,7 +438,7 @@
     public Message getTaskDescription()
     {
       return INFO_CTRL_PANEL_NEW_INDEX_TASK_DESCRIPTION.get(
-          attributeName, backendName);
+          attributeName, backendName.getText());
     }
 
     /**
@@ -557,7 +564,7 @@
     private String getIndexLDIF()
     {
       String dn = Utilities.getRDNString(
-          "ds-cfg-backend-id", backendName)+",cn=Backends,cn=config";
+          "ds-cfg-backend-id", backendName.getText())+",cn=Backends,cn=config";
       ArrayList<String> lines = new ArrayList<String>();
       lines.add("dn: "+Utilities.getRDNString("ds-cfg-attribute",
           attributeName)+
@@ -712,7 +719,7 @@
         for (BackendDescriptor backend :
           getInfo().getServerDescriptor().getBackends())
         {
-          if (backend.getBackendID().equalsIgnoreCase(backendName))
+          if (backend.getBackendID().equalsIgnoreCase(backendName.getText()))
           {
             newIndex = new IndexDescriptor(attributeName,
                 schema.getAttributeType(attributeName.toLowerCase()), backend,
@@ -748,7 +755,7 @@
       ArrayList<String> args = new ArrayList<String>();
       args.add("create-local-db-index");
       args.add("--backend-name");
-      args.add(backendName);
+      args.add(backendName.getText());
       args.add("--type");
       args.add("generic");
 
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
index 786537f..26764ef 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
@@ -110,7 +110,7 @@
    */
   public void configurationChanged(ConfigurationChangeEvent ev)
   {
-    if (updateLayout(ev))
+    if (updateLayout(ev.getNewDescriptor()))
     {
       updateErrorPaneAndOKButtonIfAuthRequired(ev.getNewDescriptor(),
           INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_NEW_VLV.get());
@@ -118,6 +118,16 @@
   }
 
   /**
+   * Updates the contents of the panel with the provided backend.
+   * @param backend the backend where the index will be created.
+   */
+  public void update(BackendDescriptor backend)
+  {
+    updateBaseDNCombo(backend);
+    backendName.setText(backend.getBackendID());
+  }
+
+  /**
    * {@inheritDoc}
    */
   public void okClicked()
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
index 347cb91..f623fc0 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
@@ -144,7 +144,7 @@
    */
   public void configurationChanged(final ConfigurationChangeEvent ev)
   {
-    if (updateLayout(ev))
+    if (updateLayout(ev.getNewDescriptor()))
     {
       updateErrorPaneIfAuthRequired(ev.getNewDescriptor(),
           INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_VLV_INDEX_EDITING.get());

--
Gitblit v1.10.0