com.gridsystems.config.tools.console
Class ValueField

java.lang.Object
  extended by com.gridsystems.config.tools.console.Field
      extended by com.gridsystems.config.tools.console.ValueField
All Implemented Interfaces:
ConsoleViewAction
Direct Known Subclasses:
BoolField, PasswordField

public class ValueField
extends Field
implements ConsoleViewAction

Text value edition field.

It can be optionally validated through a TextVerifier instance

Author:
Rodrigo Ruiz

Field Summary
protected  java.lang.String linePattern
          Pattern to use for field display.
protected  boolean trimmed
          If true text spaces will be trimmed.
protected  java.lang.Object value
          The value.
protected  java.text.MessageFormat valueFormater
          A cached instance of the value formatter.
protected  java.lang.String valuePattern
          Pattern to use for value display and parsing.
protected  TextVerifier verifier
          The text verifier.
 
Fields inherited from class com.gridsystems.config.tools.console.Field
bundle
 
Constructor Summary
ValueField(java.util.ResourceBundle bundle, java.lang.String linePattern, java.lang.String valuePattern)
          Creates a new instance.
 
Method Summary
 boolean execute(ConsoleConfiguratorView view)
          Asks the user for the new value for this field.
 java.lang.String[] getContents()
          Gets the contents of this field.
 java.lang.String getKeyMapping()
          Gets the key mapping of this action.
protected  java.lang.String getStringValue()
          Gets the field value as a string.
 java.lang.Object getValue()
          Gets this field value.
 TextVerifier getVerifier()
          Gets the current verifier for this field.
 boolean isTrimmed()
          Gets if the value should be trimmed.
protected  java.lang.String readLine()
          Reads a line of text from the console.
 void setKeyMapping(java.lang.String mapping)
          Sets the key-mapping to use for this field.
protected  void setStringValue(java.lang.String newValue)
          Sets the field value from the specified string.
 void setTrimmed(boolean trimmed)
          Sets if the value should be trimmed on storing it.
 void setValue(java.lang.Object value)
          Sets the value of this field.
 void setVerifier(TextVerifier verifier)
          Sets the verifier for this field.
 
Methods inherited from class com.gridsystems.config.tools.console.Field
getString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

linePattern

protected java.lang.String linePattern
Pattern to use for field display.


valuePattern

protected java.lang.String valuePattern
Pattern to use for value display and parsing.


value

protected java.lang.Object value
The value.


verifier

protected TextVerifier verifier
The text verifier.


valueFormater

protected java.text.MessageFormat valueFormater
A cached instance of the value formatter.


trimmed

protected boolean trimmed
If true text spaces will be trimmed.

Constructor Detail

ValueField

public ValueField(java.util.ResourceBundle bundle,
                  java.lang.String linePattern,
                  java.lang.String valuePattern)
Creates a new instance.

Parameters:
bundle - The resource bundle
linePattern - The pattern for field display
valuePattern - The pattern for value display and parsing
Method Detail

getKeyMapping

public java.lang.String getKeyMapping()
Gets the key mapping of this action.

Specified by:
getKeyMapping in interface ConsoleViewAction
Returns:
The key mapping of this action

setKeyMapping

public void setKeyMapping(java.lang.String mapping)
Sets the key-mapping to use for this field.

Parameters:
mapping - The key-mapping to set

getContents

public java.lang.String[] getContents()
Gets the contents of this field.

Specified by:
getContents in class Field
Returns:
The contents of this field

getValue

public java.lang.Object getValue()
Gets this field value.

Returns:
The value

setValue

public void setValue(java.lang.Object value)
Sets the value of this field.

Parameters:
value - The new value

setVerifier

public void setVerifier(TextVerifier verifier)
Sets the verifier for this field.

Parameters:
verifier - The verifier

getVerifier

public TextVerifier getVerifier()
Gets the current verifier for this field.

Returns:
The verifier

setTrimmed

public void setTrimmed(boolean trimmed)
Sets if the value should be trimmed on storing it.

Parameters:
trimmed - true if the value should be trimmed, false otherwise

isTrimmed

public boolean isTrimmed()
Gets if the value should be trimmed.

Returns:
true if the value should be trimmed, false otherwise

getStringValue

protected java.lang.String getStringValue()
Gets the field value as a string.

Returns:
A string containing this field value

setStringValue

protected void setStringValue(java.lang.String newValue)
Sets the field value from the specified string. If not null, the value pattern will be used for parsing the text

Parameters:
newValue - The text containing the new value

execute

public boolean execute(ConsoleConfiguratorView view)
Asks the user for the new value for this field. The empty string means to maintain the current value.

To specify an empty value, in trimmed fields a blank space can be used

This method does not return until the default value or a valid one is specified.

Specified by:
execute in interface ConsoleViewAction
Parameters:
view - The view where this field is located
Returns:
It always returns true, as the edition does not imply an exit from the view execution loop.
See Also:
ConsoleViewAction

readLine

protected java.lang.String readLine()
                             throws java.io.IOException
Reads a line of text from the console.

Returns:
The read text
Throws:
java.io.IOException - If an error occurs while reading from the console


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