com.gridsystems.config.tools.console
Class AbstractConsoleView

java.lang.Object
  extended by com.gridsystems.config.tools.console.AbstractConsoleView
All Implemented Interfaces:
ConfiguratorView, ConsoleConfiguratorView, ErrorListener
Direct Known Subclasses:
JVMConsoleView, TomcatConsoleView

public abstract class AbstractConsoleView
extends java.lang.Object
implements ConsoleConfiguratorView, ErrorListener

Base implementation for console views.

Version:
1.0
Author:
Rodrigo Ruiz Aguayo

Field Summary
protected  java.util.ResourceBundle bundle
          Resource bundle to use for message I18N.
protected  int width
          Width of the console view.
 
Constructor Summary
AbstractConsoleView(Configurator config)
          Creates a new instance with default with and the specified Configuration instance.
AbstractConsoleView(Configurator config, int width)
          Creates a new instance.
 
Method Summary
 void addKeyMapping(ConsoleViewAction action)
          Registers action with its own key mapping.
 void addKeyMapping(GroupField group)
          Registers the keymappings of all actions in the specified group field.
 void addKeyMapping(java.lang.String key, ConsoleViewAction action)
          Registers a string with a ConsoleViewAction instance.
protected  java.lang.Object[] buildForm()
          Creates the contents of the "view box".
 void clearErrors()
          The listener should remove all stored data about errors.
protected  BoolField createBoolField(java.lang.String linePattern)
          Creates a BoolField that will share the same bundle as this instance.
protected  ConstantField createConstantField(java.lang.String linePattern, java.lang.String value)
          Creates a password field that will share the same bundle as this instance.
protected  PasswordField createPasswordField(java.lang.String linePattern)
          Creates a password field that will share the same bundle as this instance.
protected  SelectionField createSelectionField(java.lang.String linePattern, java.lang.String valuePattern, java.lang.String[] values)
          Creates a SelectionField that will share the same bundle as this instance.
protected  ValueField createValueField(java.lang.String linePattern, java.lang.String valuePattern)
          Creates a ValueField that will share the same bundle as this instance.
 void execute()
          Performs the view execution.
 Configurator getConfigurator()
          Gets the configurator this view is associated to.
protected abstract  void getContents(java.util.List<java.lang.Object> list)
          Gets an array with the items conforming the contents of the "view box".
 java.lang.String getString(java.lang.String key)
          Gets a localized string, using the found string as a pattern to be used by a MessageFormat instance.
 java.lang.String getString(java.lang.String key, java.lang.Object[] params)
          Gets a localized string, using the found string as a pattern to be used by a MessageFormat instance.
 boolean hasErrors()
          Gets if the view contains any error.
protected  void paintForm(java.lang.Object[] form)
          Displays the "view box".
 void removeKeyMapping(ConsoleViewAction action)
          Removes the key mapping for the specified action.
 void removeKeyMapping(GroupField group)
          Removes all key mappings in the specified group field.
 void setApplyDiscardMappings(Configurator config)
          Registers the default apply and discard actions linked to the specified configuration instance.
 void showError(java.lang.String[] message)
          Shows an error message in the bottom line of the view.
 void updateError(java.lang.String id, java.lang.String msg, boolean add)
          Performs an action on an error.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.gridsystems.config.ConfiguratorView
getSubtitle, getTitle, getValues, setValues
 

Field Detail

bundle

protected java.util.ResourceBundle bundle
Resource bundle to use for message I18N.


width

protected int width
Width of the console view.

Constructor Detail

AbstractConsoleView

public AbstractConsoleView(Configurator config)
Creates a new instance with default with and the specified Configuration instance.

Parameters:
config - The configuration instance

AbstractConsoleView

public AbstractConsoleView(Configurator config,
                           int width)
Creates a new instance.

Parameters:
config - The configuration to use
width - The view width
Method Detail

setApplyDiscardMappings

public void setApplyDiscardMappings(Configurator config)
Registers the default apply and discard actions linked to the specified configuration instance.

Parameters:
config - The configuration instance which actions will affect to

getConfigurator

public Configurator getConfigurator()
Gets the configurator this view is associated to.

Specified by:
getConfigurator in interface ConfiguratorView
Returns:
The configurator

execute

public void execute()
Description copied from interface: ConsoleConfiguratorView
Performs the view execution.

Specified by:
execute in interface ConsoleConfiguratorView
See Also:
ConsoleConfiguratorView.execute()

paintForm

protected void paintForm(java.lang.Object[] form)
Displays the "view box".

Parameters:
form - The contents of the box

buildForm

protected java.lang.Object[] buildForm()
Creates the contents of the "view box". It adds an Apply/Discard button bar to the bottom of the box after calling to getContents(java.util.List)

Returns:
An array of objects conforming the "view box" contents, that can be directly used as an argument by the painBox method in ConsoleTools.

addKeyMapping

public void addKeyMapping(java.lang.String key,
                          ConsoleViewAction action)
Registers a string with a ConsoleViewAction instance. The action will be executed when the user types the key string.

Parameters:
key - The associated command string
action - The action to execute when key is typed

addKeyMapping

public void addKeyMapping(ConsoleViewAction action)
Registers action with its own key mapping.

Parameters:
action - The action to execute

addKeyMapping

public void addKeyMapping(GroupField group)
Registers the keymappings of all actions in the specified group field.

Parameters:
group - The group field.

removeKeyMapping

public void removeKeyMapping(ConsoleViewAction action)
Removes the key mapping for the specified action.

Parameters:
action - the action to remove

removeKeyMapping

public void removeKeyMapping(GroupField group)
Removes all key mappings in the specified group field.

Parameters:
group - The group field

getContents

protected abstract void getContents(java.util.List<java.lang.Object> list)
Gets an array with the items conforming the contents of the "view box".

Parameters:
list - A list where to put the contents of the box

createValueField

protected ValueField createValueField(java.lang.String linePattern,
                                      java.lang.String valuePattern)
Creates a ValueField that will share the same bundle as this instance.

Parameters:
linePattern - The line pattern of the new field
valuePattern - The value pattern of the new field
Returns:
The field

createSelectionField

protected SelectionField createSelectionField(java.lang.String linePattern,
                                              java.lang.String valuePattern,
                                              java.lang.String[] values)
Creates a SelectionField that will share the same bundle as this instance.

Parameters:
linePattern - a String with the line pattern of the new field.
valuePattern - a String with the value pattern of the new field.
values - a String[] with the list of valid values of the new field.
Returns:
the SelectionField created.

createBoolField

protected BoolField createBoolField(java.lang.String linePattern)
Creates a BoolField that will share the same bundle as this instance.

Parameters:
linePattern - The field line pattern
Returns:
The field

createPasswordField

protected PasswordField createPasswordField(java.lang.String linePattern)
Creates a password field that will share the same bundle as this instance.

Parameters:
linePattern - The field line pattern
Returns:
The field

createConstantField

protected ConstantField createConstantField(java.lang.String linePattern,
                                            java.lang.String value)
Creates a password field that will share the same bundle as this instance.

Parameters:
linePattern - The field line pattern
value - the value
Returns:
The field

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object[] params)
Gets a localized string, using the found string as a pattern to be used by a MessageFormat instance.

Parameters:
key - The key for the localized pattern
params - The parameters for pattern substitution
Returns:
The localized / formatter string
Throws:
java.lang.NullPointerException - if the bundle is not set

getString

public java.lang.String getString(java.lang.String key)
Gets a localized string, using the found string as a pattern to be used by a MessageFormat instance.

Parameters:
key - The key for the localized pattern
Returns:
The localized / formatter string
Throws:
java.lang.NullPointerException - if the bundle is not set

showError

public void showError(java.lang.String[] message)
Shows an error message in the bottom line of the view.

The message is removed on the next view refresh

Parameters:
message - The error message lines

updateError

public void updateError(java.lang.String id,
                        java.lang.String msg,
                        boolean add)
Performs an action on an error. It receives an error identifier and an error message. Comparisons should be done only on the identifier, as the message can change.

Specified by:
updateError in interface ErrorListener
Parameters:
id - The error identifier
msg - The error message
add - A flag that indicates if the error must be added(true) or remove

clearErrors

public void clearErrors()
The listener should remove all stored data about errors.

Specified by:
clearErrors in interface ErrorListener

hasErrors

public boolean hasErrors()
Gets if the view contains any error.

Specified by:
hasErrors in interface ConfiguratorView
Returns:
true if there is any error in the view


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.