ewe.data
Class InputObject

java.lang.Object
  extended byewe.data.DataObject
      extended byewe.data.LiveObject
          extended byewe.data.InputObject
All Implemented Interfaces:
Comparable, Copyable, DataUnit, FieldListener, HasProperties, LiveData
Direct Known Subclasses:
GetSearchCriteria

public class InputObject
extends LiveObject
implements HasProperties

This is a utility object which can be used to input data from a user. There are two basic ways of doing this:

  • Construct it using InputObject(String fields,int inputLength) and provide a text formatted specification for "fields".
  • Override InputObject and override the setupInputStack() method.
  • Using the first method, constructing an InputObject with a field specification, the format for the "fields" variable is as follows:

    "prompt$hotkey|fieldName$fieldType|prompt$hotkey|fieldName$fieldType|..."

    prompt can be any string which will be displayed as a prompt for an input field. If you end the prompt with the sequence "$x", where 'x' can be any character, then 'x' will be considered the hot key for that field.
    fieldName must be a field name for the previous prompt. This must be followed by a '$' and then an optional java type in 'L' format. For example if you want to input a ewe.sys.Time object then you should have: "$Lewe/sys/Time;" immediately following the field name. If you want to enter an integer then you should have: "$I" immediately following the field name. A '$' with nothing after it denotes a String.

    For example:

    public static void main(String args[])
    {
            ewe.sys.Vm.startEwe(args);
            PropertyList defaultValues = PropertyList.fromStrings("name|Homer Simpson|age|42");
            PropertyList entered = new InputObject("Name:$n|name$|Age:$a|age$I",30).input(null,"Please enter data!",defaultValues);
            if (entered != null) ewe.sys.Vm.debug(entered.toString());
            ewe.sys.Vm.exit(0);
    }
    

    With the second method, in the overriden setupInputStack(InputStack is,Editor ed) you should add the appropiate input controls and fields to the InputStack 'is' and editor 'ed'.


    Field Summary
     String fields
              This is the specification of the fields to be input.
     int inputLength
              This is the default input length, currently set to 30 characters.
     
    Constructor Summary
    InputObject()
               
    InputObject(String fields, int inputLength)
              Create an InputObject with the specified fields and with a particular input length.
     
    Method Summary
     void addToPanel(CellPanel cp, Editor ed, int which)
              You should not need to override this, but you can if you want to completely change the way the input form will look.
     PropertyList getProperties()
              Get the property list which holds the values for the entered fields.
     PropertyList input(Frame parent, String title, PropertyList values)
              This does the following: Sets the values of the fields to be as specified in the "values" PropertyList parameter.
    protected  boolean isValid(PropertyList pl, Editor ed)
              This is called before the InputObject form exits with an exit code of IDOK.
    static void main(String[] args)
              This allows you to test the InputObject with specified data.
    protected  Editor makeNewEditor(int options)
              This shoudl create the new Editor object but not add anything to it.
    protected  void setupInputStack(InputStack is, Editor ed)
              You can override this to add your own custom fields and controls.
    protected  void showErrorMessage(String title, String message)
              Use this if you wish from the isValid() method to display a message if the input is invalid.
     
    Methods inherited from class ewe.data.LiveObject
    action, action, addMeToPanel, addObjectToPanel, decode, decoded, decodeFields, enableEditorScrolling, encode, encoded, encodeFields, fieldChanged, fieldChanged, fieldEvent, getEditor, getEditorScroller, getIcon, getName, input, runAsApp, textDecode, textEncode
     
    Methods inherited from class ewe.data.DataObject
    _getSetField, appendAllFields, compareTo, copied, copyFrom, equals, getCopy, getDeclaredField, getDeclaredFieldValue, getDeclaredFieldValue, getFieldList, getFieldList, getMyFieldList, getNew
     
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, hashCode, toString
     
    Methods inherited from interface ewe.data.DataUnit
    copyFrom, getNew
     
    Methods inherited from interface ewe.util.Copyable
    getCopy
     
    Methods inherited from interface ewe.util.Comparable
    compareTo
     

    Field Detail

    inputLength

    public int inputLength
    This is the default input length, currently set to 30 characters.


    fields

    public String fields
    This is the specification of the fields to be input.

    Constructor Detail

    InputObject

    public InputObject()

    InputObject

    public InputObject(String fields,
                       int inputLength)
    Create an InputObject with the specified fields and with a particular input length. Each field must specify its type.

    Parameters:
    fields - This can be in two formats:
    Either: field1$type1,field2$type2,field3%type3,...
    Or: Prompt1$hotKey1|field1$type1|Prompt2$hotKey2|field2$type2|...
    Note that the first one is comma separated while the second is '|' separated.

    The type of the field must be specified and should be for primitive (non-object values): I (integer), D (double), Z (boolean) or, to specify an object type: Lfull_class_name;. Note that can just have a '$' with nothing following to specify a String. Note also that for object values, you must use a '/' instead of a '.' to separate packages. e.g. Lewe/sys/Time;

    inputLength - The length of the inputs.
    Method Detail

    getProperties

    public PropertyList getProperties()
    Get the property list which holds the values for the entered fields.

    Specified by:
    getProperties in interface HasProperties

    setupInputStack

    protected void setupInputStack(InputStack is,
                                   Editor ed)
    You can override this to add your own custom fields and controls.


    addToPanel

    public void addToPanel(CellPanel cp,
                           Editor ed,
                           int which)
    You should not need to override this, but you can if you want to completely change the way the input form will look.

    Overrides:
    addToPanel in class LiveObject

    input

    public PropertyList input(Frame parent,
                              String title,
                              PropertyList values)
    This does the following: You can retrieve the data entered for each field by calling getValue("fieldName",defaultValue) on the returned PropertyList.


    makeNewEditor

    protected Editor makeNewEditor(int options)
    This shoudl create the new Editor object but not add anything to it. This is called by getEditor(). By default it returns a standard Editor object.

    Overrides:
    makeNewEditor in class LiveObject

    showErrorMessage

    protected void showErrorMessage(String title,
                                    String message)
    Use this if you wish from the isValid() method to display a message if the input is invalid.

    Parameters:
    title - the title of the message box.
    message - the text of the message.

    isValid

    protected boolean isValid(PropertyList pl,
                              Editor ed)
    This is called before the InputObject form exits with an exit code of IDOK. If it returns false the form will not exit.

    Parameters:
    pl - the PropertyList holding the input data.
    ed - the Editor form used for input.
    Returns:
    true to allow the input form to exit, false to prevent an exit.

    main

    public static void main(String[] args)
    This allows you to test the InputObject with specified data. Simply execute:
    ewe ewe.data.InputObjct "field_list" ["default_data"]
    To display an input box for the specified field list. The default_data is optional.

    Try it out with the following field lists:
    "lastName$,firstNames$,smoker$Z,salary$D,dob$Lewe/sys/Time;
    and
    "Contact Name$n|name$|Company$c|company$|Age$a|age$I"