From 43e9c7913fc664b725e167090fe6d389a4558315 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 08 Jun 2007 14:43:45 +0000
Subject: [PATCH] The following commit adds all the code necessary to be able to configure replication using the setup.

---
 opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 1 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
index 94e94b4..50276d2 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
@@ -248,7 +248,9 @@
   {
     final WizardStep cStep = getCurrentStep();
     application.nextClicked(cStep, this);
-    updateUserData(cStep);
+    BackgroundTask worker = new NextClickedBackgroundTask(cStep);
+    getDialog().workerStarted();
+    worker.startBackgroundTask();
   }
 
   private void updateUserData(final WizardStep cStep) {
@@ -278,7 +280,14 @@
             if (displayConfirmation(ude.getLocalizedMessage(),
                 getMsg("confirmation-title")))
             {
+              try
+              {
               setCurrentStep(application.getNextWizardStep(cStep));
+              }
+              catch (Throwable t)
+              {
+                t.printStackTrace();
+              }
             }
           }
           else
@@ -553,6 +562,29 @@
   }
 
   /**
+   * Displays a dialog asking the user to accept a certificate.
+   *
+   * @param ce
+   *          the certificate exception that occurred.
+   * @param title
+   *          the title of the dialog.
+   * @return <CODE>true</CODE> if the user confirms the message, or
+   * <CODE>false</CODE> if not.
+   */
+  private boolean askToAcceptCertificate(UserDataCertificateException ce)
+  {
+    boolean accept = false;
+    CertificateDialog dlg = new CertificateDialog(getDialog().getFrame(), ce);
+    dlg.pack();
+    dlg.setVisible(true);
+    if (dlg.isAccepted())
+    {
+      accept = true;
+    }
+    return accept;
+  }
+
+  /**
    * Gets the string value for a given field name.
    *
    * @param fieldName
@@ -650,4 +682,78 @@
   {
     return Utils.isWebStart();
   }
+
+  /**
+   * This is a class used when the user clicks on next and that extends
+   * BackgroundTask.
+   */
+  private class NextClickedBackgroundTask extends BackgroundTask
+  {
+    private WizardStep cStep;
+    public NextClickedBackgroundTask(WizardStep cStep)
+    {
+      this.cStep = cStep;
+    }
+
+    public Object processBackgroundTask() throws UserDataException {
+      try {
+        application.updateUserData(cStep, QuickSetup.this);
+      }
+      catch (UserDataException uide) {
+        throw uide;
+      }
+      catch (Throwable t) {
+        throw new UserDataException(cStep,
+                getThrowableMsg("bug-msg", t));
+      }
+      return null;
+    }
+
+    public void backgroundTaskCompleted(Object returnValue,
+                                        Throwable throwable) {
+      getDialog().workerFinished();
+
+      if (throwable != null)
+      {
+        if (!(throwable instanceof UserDataException))
+        {
+          LOG.log(Level.WARNING, "Unhandled exception.", throwable);
+        }
+        else
+        {
+          UserDataException ude = (UserDataException) throwable;
+          if (ude instanceof UserDataConfirmationException)
+          {
+            if (displayConfirmation(ude.getLocalizedMessage(),
+                getMsg("confirmation-title")))
+            {
+              setCurrentStep(application.getNextWizardStep(cStep));
+            }
+          }
+          else if (ude instanceof UserDataCertificateException)
+          {
+            final UserDataCertificateException ce =
+              (UserDataCertificateException)ude;
+            if (askToAcceptCertificate(ce))
+            {
+              /*
+               * Retry the click but now with the certificate accepted.
+               */
+              application.acceptCertificateForException(ce);
+              application.nextClicked(cStep, QuickSetup.this);
+              BackgroundTask worker = new NextClickedBackgroundTask(cStep);
+              getDialog().workerStarted();
+              worker.startBackgroundTask();
+            }
+          }
+          else
+          {
+            displayError(ude.getLocalizedMessage(), getMsg("error-title"));
+          }
+        }
+      } else {
+        setCurrentStep(application.getNextWizardStep(cStep));
+      }
+    }
+  }
 }

--
Gitblit v1.10.0