From 438446523cb7fba189deb52f1312ac2a2ab9ee46 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 06 Jul 2007 18:12:40 +0000
Subject: [PATCH] Add the code required to update the list of steps that appear on the left of the wizard dynamically.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java                   |   23 +++++--
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java    |    6 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/InstallAndUpgrader.java |   33 ++++++++++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java |    5 +
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java                         |   15 +++++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java     |    7 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/StepsPanel.java                         |   17 +++++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ButtonName.java                            |   10 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java                     |   22 ++++++
 9 files changed, 122 insertions(+), 16 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ButtonName.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ButtonName.java
index 4ef471a..5bb1216 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ButtonName.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ButtonName.java
@@ -29,7 +29,7 @@
 
 /**
  * This enumeration defines the logical names of the buttons that appear on the
- * bottom of the wizard dialog.
+ * the wizard dialog.
  */
 public enum ButtonName
 {
@@ -60,5 +60,11 @@
   /**
    * The Launch Status Panel button.
    */
-  LAUNCH_STATUS_PANEL
+  LAUNCH_STATUS_PANEL,
+  /**
+   * Input panel button.  This is used to identify generic buttons inside
+   * the panels and the notifications are used for instance to update the
+   * visibility of the steps on the right.
+   */
+  INPUT_PANEL_BUTTON
 }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/InstallAndUpgrader.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/InstallAndUpgrader.java
index 278c852..cd6045a 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/InstallAndUpgrader.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/InstallAndUpgrader.java
@@ -310,7 +310,7 @@
   /**
    * {@inheritDoc}
    */
-  public boolean isVisible(WizardStep step)
+  public boolean isVisible(WizardStep step, UserData userData)
   {
     boolean isVisible;
     if (step == Step.WELCOME)
@@ -319,7 +319,8 @@
     }
     else
     {
-      isVisible = getDelegateApplication().isVisible(step) &&
+      isVisible = getDelegateApplication().isVisible(step,
+          getDelegateApplication().getUserData()) &&
       getDelegateApplication().getWizardSteps().contains(step);
     }
     return isVisible;
@@ -328,6 +329,34 @@
   /**
    * {@inheritDoc}
    */
+  public boolean isVisible(WizardStep step, QuickSetup qs)
+  {
+    boolean isVisible;
+    if (step == Step.WELCOME)
+    {
+      isVisible = true;
+    }
+    else
+    {
+      GuiApplication appl;
+      Boolean isUpgrade = (Boolean)qs.getFieldValue(FieldName.IS_UPGRADE);
+      if (Boolean.TRUE.equals(isUpgrade))
+      {
+        appl = upgrader;
+      }
+      else
+      {
+        appl = installer;
+      }
+      isVisible = appl.isVisible(step, qs) &&
+      appl.getWizardSteps().contains(step);
+    }
+    return isVisible;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
   public boolean isSubStep(WizardStep step)
   {
     boolean isSubStep;
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
index 6f8099f..4dbe215 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installandupgrader/ui/WelcomePanel.java
@@ -28,8 +28,10 @@
 package org.opends.quicksetup.installandupgrader.ui;
 
 import org.opends.quicksetup.ui.*;
+import org.opends.quicksetup.ButtonName;
 import org.opends.quicksetup.UserData;
 import org.opends.quicksetup.event.BrowseActionListener;
+import org.opends.quicksetup.event.ButtonEvent;
 import org.opends.quicksetup.installandupgrader.InstallAndUpgradeUserData;
 import org.opends.quicksetup.installandupgrader.InstallAndUpgrader;
 import org.opends.server.util.DynamicConstants;
@@ -154,6 +156,9 @@
       public void actionPerformed(ActionEvent ev)
       {
         checkEnablingState();
+        ButtonEvent be = new ButtonEvent(ev.getSource(),
+            ButtonName.INPUT_PANEL_BUTTON);
+        notifyButtonListeners(be);
       }
     };
     rbInstall.addActionListener(l);
@@ -171,6 +176,7 @@
     gbc.insets.top = UIFactory.TOP_INSET_SECONDARY_FIELD;
     p.add(rbUpgrade, gbc);
     gbc.insets.left = UIFactory.LEFT_INSET_RADIO_SUBORDINATE;
+
     p.add(createUpgraderPanel(), gbc);
 
     gbc.insets.top = 0;
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index 5e2b427..d0b9333 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -253,17 +253,17 @@
   /**
    * {@inheritDoc}
    */
-  public boolean isVisible(WizardStep step)
+  public boolean isVisible(WizardStep step, UserData userData)
   {
     boolean isVisible;
     if (step == CREATE_GLOBAL_ADMINISTRATOR)
     {
-       isVisible = getUserData().mustCreateAdministrator();
+       isVisible = userData.mustCreateAdministrator();
     }
     else if (step == NEW_SUFFIX_OPTIONS)
     {
       SuffixesToReplicateOptions suf =
-        getUserData().getSuffixesToReplicateOptions();
+        userData.getSuffixesToReplicateOptions();
       if (suf != null)
       {
         isVisible = suf.getType() !=
@@ -276,8 +276,7 @@
     }
     else if (step == SUFFIXES_OPTIONS)
     {
-      DataReplicationOptions repl =
-        getUserData().getReplicationOptions();
+      DataReplicationOptions repl = userData.getReplicationOptions();
       if (repl != null)
       {
         isVisible =
@@ -291,9 +290,9 @@
     }
     else if (step == REMOTE_REPLICATION_PORTS)
     {
-      isVisible = isVisible(SUFFIXES_OPTIONS) &&
-      (getUserData().getRemoteWithNoReplicationPort().size() > 0) &&
-      (getUserData().getSuffixesToReplicateOptions().getType() ==
+      isVisible = isVisible(SUFFIXES_OPTIONS, userData) &&
+      (userData.getRemoteWithNoReplicationPort().size() > 0) &&
+      (userData.getSuffixesToReplicateOptions().getType() ==
         SuffixesToReplicateOptions.Type.REPLICATE_WITH_EXISTING_SUFFIXES);
     }
     else
@@ -306,6 +305,14 @@
   /**
    * {@inheritDoc}
    */
+  public boolean isVisible(WizardStep step, QuickSetup qs)
+  {
+    return isVisible(step, getUserData());
+  }
+
+  /**
+   * {@inheritDoc}
+   */
   public boolean finishClicked(final WizardStep cStep, final QuickSetup qs) {
     if (cStep == Step.REVIEW) {
         updateUserDataForReviewPanel(qs);
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
index c2b2394..17296fd 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/DataReplicationPanel.java
@@ -46,7 +46,9 @@
 import javax.swing.event.DocumentListener;
 import javax.swing.text.JTextComponent;
 
+import org.opends.quicksetup.ButtonName;
 import org.opends.quicksetup.UserData;
+import org.opends.quicksetup.event.ButtonEvent;
 import org.opends.quicksetup.installer.AuthenticationData;
 import org.opends.quicksetup.installer.DataReplicationOptions;
 import org.opends.quicksetup.ui.FieldName;
@@ -568,9 +570,12 @@
   {
     final ActionListener l = new ActionListener()
     {
-      public void actionPerformed(ActionEvent e)
+      public void actionPerformed(ActionEvent ev)
       {
         checkEnablingState();
+        ButtonEvent be = new ButtonEvent(ev.getSource(),
+            ButtonName.INPUT_PANEL_BUTTON);
+        notifyButtonListeners(be);
       }
     };
     rbReplicated.addActionListener(l);
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
index e0b179f..2d82764 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/ui/SuffixesToReplicatePanel.java
@@ -56,7 +56,9 @@
 import org.opends.admin.ads.ServerDescriptor;
 import org.opends.admin.ads.SuffixDescriptor;
 
+import org.opends.quicksetup.ButtonName;
 import org.opends.quicksetup.UserData;
+import org.opends.quicksetup.event.ButtonEvent;
 import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
 import org.opends.quicksetup.ui.FieldName;
 import org.opends.quicksetup.ui.GuiApplication;
@@ -343,6 +345,9 @@
       public void actionPerformed(ActionEvent ev)
       {
         checkEnablingState();
+        ButtonEvent be = new ButtonEvent(ev.getSource(),
+            ButtonName.INPUT_PANEL_BUTTON);
+        notifyButtonListeners(be);
       }
     };
     rbCreateNewSuffix.addActionListener(l);
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
index d63c477..57a3bf5 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
@@ -237,13 +237,31 @@
   }
 
   /**
-   * Indicates whether the provided <code>step</code> is visible or not.
+   * Indicates whether the provided <code>step</code> is visible or not
+   * depending on the contents of the UserData object that is provided.
    * @param step WizardStep for which the return value indicates whether
    * or not is visible.
+   * @param userData the UserData to be used to determine if the step is
+   * visible or not.
    * @return boolean where true indicates the provided <code>step</code> is
    * visible.
    */
-  public boolean isVisible(WizardStep step)
+  public boolean isVisible(WizardStep step, UserData userData)
+  {
+    return true;
+  }
+
+  /**
+   * Indicates whether the provided <code>step</code> is visible or not
+   * depending on the contents of the QuickSetup object that is provided.
+   * @param step WizardStep for which the return value indicates whether
+   * or not is visible.
+   * @param qs the QuickSetup to be used to determine if the step is
+   * visible or not.
+   * @return boolean where true indicates the provided <code>step</code> is
+   * visible.
+   */
+  public boolean isVisible(WizardStep step, QuickSetup qs)
   {
     return true;
   }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
index 19d7b75..1f06876 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
@@ -172,6 +172,10 @@
       launchStatusPanelClicked();
       break;
 
+    case INPUT_PANEL_BUTTON:
+      inputPanelButtonClicked();
+      break;
+
     default:
       throw new IllegalArgumentException("Unknown button name: "
           + ev.getButtonName());
@@ -445,6 +449,17 @@
   }
 
   /**
+   * This method tries to update the visibility of the steps panel.  The
+   * contents are updated because the user clicked in one of the buttons
+   * that could make the steps panel to change.
+   *
+   */
+  private void inputPanelButtonClicked()
+  {
+    getDialog().getStepsPanel().updateStepVisibility(this);
+  }
+
+  /**
    * Method called when we want to quit the setup (for instance when the user
    * clicks on 'Close' or 'Quit' buttons and has confirmed that (s)he wants to
    * quit the program.
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/StepsPanel.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/StepsPanel.java
index 67c0309..ead0388 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/StepsPanel.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/StepsPanel.java
@@ -96,7 +96,22 @@
               UIFactory.TextStyle.NOT_CURRENT_STEP);
         }
       }
-      setStepVisible(s, getApplication().isVisible(s));
+      setStepVisible(s, getApplication().isVisible(s, userData));
+    }
+  }
+
+  /**
+   * Updates the visiblitiy of the steps depending on the current contents
+   * of the panels (uses the QuickSetup to know what is displayed in the
+   * panels).
+   *
+   * @param qs the QuickSetup object.
+   */
+  public void updateStepVisibility(QuickSetup qs)
+  {
+    for (WizardStep s : getApplication().getWizardSteps())
+    {
+      setStepVisible(s, getApplication().isVisible(s, qs));
     }
   }
 

--
Gitblit v1.10.0