From e75584b1354e33c7c373ea13521d29bb5ac433d7 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 26 Mar 2008 17:23:37 +0000
Subject: [PATCH] Fix for issues 3086 and 3087 (Command uninstall --cli should not uninstall when the user have not answer "yes")

---
 opends/src/server/org/opends/server/util/cli/MenuBuilder.java |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/cli/MenuBuilder.java b/opends/src/server/org/opends/server/util/cli/MenuBuilder.java
index e6c6865..033db6d 100644
--- a/opends/src/server/org/opends/server/util/cli/MenuBuilder.java
+++ b/opends/src/server/org/opends/server/util/cli/MenuBuilder.java
@@ -145,13 +145,16 @@
     // The menu title.
     private final Message title;
 
-
+    // The maximum number of times we display the menu if the user provides
+    // bad input (-1 for unlimited).
+    private int nMaxTries;
 
     // Private constructor.
     private MenuImpl(ConsoleApplication app, Message title, Message prompt,
         TableBuilder ntable, TableBuilder ctable, TablePrinter printer,
         Map<String, MenuCallback<T>> callbacks, boolean allowMultiSelect,
-        MenuCallback<T> defaultCallback, Message defaultDescription) {
+        MenuCallback<T> defaultCallback, Message defaultDescription,
+        int nMaxTries) {
       this.app = app;
       this.title = title;
       this.prompt = prompt;
@@ -162,6 +165,7 @@
       this.allowMultiSelect = allowMultiSelect;
       this.defaultCallback = defaultCallback;
       this.defaultDescription = defaultDescription;
+      this.nMaxTries = nMaxTries;
     }
 
 
@@ -276,7 +280,16 @@
         }
 
         // Get the user's choice.
-        MenuCallback<T> choice = app.readValidatedInput(promptMsg, validator);
+        MenuCallback<T> choice;
+
+        if (nMaxTries != -1)
+        {
+          choice = app.readValidatedInput(promptMsg, validator, nMaxTries);
+        }
+        else
+        {
+          choice = app.readValidatedInput(promptMsg, validator);
+        }
 
         // Invoke the user's selected choice.
         MenuResult<T> result = choice.invoke(app);
@@ -371,7 +384,9 @@
   // The menu prompt.
   private Message prompt = null;
 
-
+  // The maximum number of times that we allow the user to provide an invalid
+  // answer (-1 if unlimited).
+  private int nMaxTries = -1;
 
   /**
    * Creates a new menu.
@@ -805,6 +820,18 @@
     }
 
     return new MenuImpl<T>(app, title, prompt, nbuilder, cbuilder, printer,
-        callbacks, allowMultiSelect, defaultCallback, defaultDescription);
+        callbacks, allowMultiSelect, defaultCallback, defaultDescription,
+        nMaxTries);
+  }
+
+  /**
+   * Sets the maximum number of tries that the user can provide an invalid
+   * value in the menu. -1 for unlimited tries (the default).  If this limit is
+   * reached a CLIException will be thrown.
+   * @param nTries the maximum number of tries.
+   */
+  public void setMaxTries(int nTries)
+  {
+    nMaxTries = nTries;
   }
 }

--
Gitblit v1.10.0