org.opends.server.util.cli
Class MenuBuilder<T>

java.lang.Object
  extended by org.opends.server.util.cli.MenuBuilder<T>
Type Parameters:
T - The type of value returned by the call-backs. Use Void if the call-backs do not return a value.

public final class MenuBuilder<T>
extends java.lang.Object

An interface for incrementally building a command-line menu.


Constructor Summary
MenuBuilder(ConsoleApplication app)
          Creates a new menu.
 
Method Summary
 void addBackOption(boolean isDefault)
          Creates a "back" menu option.
 void addCancelOption(boolean isDefault)
          Creates a "cancel" menu option.
 void addCharOption(Message c, Message description, MenuCallback<T> callback)
          Adds a menu choice to the menu which will have a single letter as its key.
 void addCharOption(Message c, Message description, MenuResult<T> result)
          Adds a menu choice to the menu which will have a single letter as its key and which returns the provided result.
 void addHelpOption(HelpCallback callback)
          Creates a "help" menu option which will use the provided help call-back to display help relating to the other menu options.
 int addNumberedOption(Message description, MenuCallback<T> callback, Message... extraFields)
          Adds a menu choice to the menu which will have a numeric key.
 int addNumberedOption(Message description, MenuResult<T> result, Message... extraFields)
          Adds a menu choice to the menu which will have a numeric key and which returns the provided result.
 void addQuitOption()
          Creates a "quit" menu option.
 void setAllowMultiSelect(boolean allowMultiSelect)
          Sets the flag which indicates whether or not the menu will permit multiple numeric options to be selected at once.
 void setColumnHeadings(Message... headings)
          Sets the optional column headings.
 void setColumnWidths(java.lang.Integer... widths)
          Sets the optional column widths.
 void setDefault(Message description, MenuCallback<T> callback)
          Sets the optional default action for this menu.
 void setDefault(Message description, MenuResult<T> result)
          Sets the optional default action for this menu.
 void setMaxTries(int nTries)
          Sets the maximum number of tries that the user can provide an invalid value in the menu.
 void setMultipleColumnThreshold(int threshold)
          Sets the number of numeric options required to trigger multiple-column display.
 void setPrompt(Message prompt)
          Sets the optional menu prompt.
 void setTitle(Message title)
          Sets the optional menu title.
 Menu<T> toMenu()
          Creates a menu from this menu builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBuilder

public MenuBuilder(ConsoleApplication app)
Creates a new menu.

Parameters:
app - The application console.
Method Detail

addBackOption

public void addBackOption(boolean isDefault)
Creates a "back" menu option. When invoked, this option will return a MenuResult.cancel() result.

Parameters:
isDefault - Indicates whether this option should be made the menu default.

addCancelOption

public void addCancelOption(boolean isDefault)
Creates a "cancel" menu option. When invoked, this option will return a MenuResult.cancel() result.

Parameters:
isDefault - Indicates whether this option should be made the menu default.

addCharOption

public void addCharOption(Message c,
                          Message description,
                          MenuCallback<T> callback)
Adds a menu choice to the menu which will have a single letter as its key.

Parameters:
c - The single-letter message which will be used as the key for this option.
description - The menu option description.
callback - The call-back associated with this option.

addCharOption

public void addCharOption(Message c,
                          Message description,
                          MenuResult<T> result)
Adds a menu choice to the menu which will have a single letter as its key and which returns the provided result.

Parameters:
c - The single-letter message which will be used as the key for this option.
description - The menu option description.
result - The menu result which should be returned by this menu choice.

addHelpOption

public void addHelpOption(HelpCallback callback)
Creates a "help" menu option which will use the provided help call-back to display help relating to the other menu options. When the help menu option is selected help will be displayed and then the user will be shown the menu again and prompted to enter a choice.

Parameters:
callback - The help call-back.

addNumberedOption

public int addNumberedOption(Message description,
                             MenuCallback<T> callback,
                             Message... extraFields)
Adds a menu choice to the menu which will have a numeric key.

Parameters:
description - The menu option description.
callback - The call-back associated with this option.
extraFields - Any additional fields associated with this menu option.
Returns:
Returns the number associated with menu choice.

addNumberedOption

public int addNumberedOption(Message description,
                             MenuResult<T> result,
                             Message... extraFields)
Adds a menu choice to the menu which will have a numeric key and which returns the provided result.

Parameters:
description - The menu option description.
result - The menu result which should be returned by this menu choice.
extraFields - Any additional fields associated with this menu option.
Returns:
Returns the number associated with menu choice.

addQuitOption

public void addQuitOption()
Creates a "quit" menu option. When invoked, this option will return a MenuResult.quit() result.


setAllowMultiSelect

public void setAllowMultiSelect(boolean allowMultiSelect)
Sets the flag which indicates whether or not the menu will permit multiple numeric options to be selected at once. Users specify multiple choices by separating them with a comma. The default is false.

Parameters:
allowMultiSelect - Indicates whether or not the menu will permit multiple numeric options to be selected at once.

setColumnHeadings

public void setColumnHeadings(Message... headings)
Sets the optional column headings. The column headings will be displayed above the menu options.

Parameters:
headings - The optional column headings.

setColumnWidths

public void setColumnWidths(java.lang.Integer... widths)
Sets the optional column widths. A value of zero indicates that the column should be expandable, a value of null indicates that the column should use its default width.

Parameters:
widths - The optional column widths.

setDefault

public void setDefault(Message description,
                       MenuCallback<T> callback)
Sets the optional default action for this menu. The default action call-back will be invoked if the user does not specify an option and just presses enter.

Parameters:
description - A short description of the default action.
callback - The call-back associated with the default action.

setDefault

public void setDefault(Message description,
                       MenuResult<T> result)
Sets the optional default action for this menu. The default action call-back will be invoked if the user does not specify an option and just presses enter.

Parameters:
description - A short description of the default action.
result - The menu result which should be returned by default.

setMultipleColumnThreshold

public void setMultipleColumnThreshold(int threshold)
Sets the number of numeric options required to trigger multiple-column display. A negative value (the default) indicates that the numeric options will always be displayed in a single column. A value of 0 indicates that numeric options will always be displayed in multiple columns.

Parameters:
threshold - The number of numeric options required to trigger multiple-column display.

setPrompt

public void setPrompt(Message prompt)
Sets the optional menu prompt. The prompt will be displayed above the menu. Menus do not have a prompt by default.

Parameters:
prompt - The menu prompt, or null if there is not prompt.

setTitle

public void setTitle(Message title)
Sets the optional menu title. The title will be displayed above the menu prompt. Menus do not have a title by default.

Parameters:
title - The menu title, or null if there is not title.

toMenu

public Menu<T> toMenu()
Creates a menu from this menu builder.

Returns:
Returns the new menu.

setMaxTries

public void setMaxTries(int nTries)
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.

Parameters:
nTries - the maximum number of tries.