org.objectweb.jac.aspects.gui
Class InputSequence

java.lang.Object
  |
  +--org.objectweb.jac.aspects.gui.InputSequence

public abstract class InputSequence
extends Object

This class allows a GUI programmer to create input sequences to ask the user to fill a set of parameters when invoking a method.

By default, when invoking a method through the GUI, an InputWrapper opens a dialog to fill the parameters values when needed. If an input sequence is attached to this method (see GuiAC.setInputSequence), then the input wrappers will ask for the parameters using several input dialogs, each one corresponding to a step of the input sequence.

Defining a new input sequence is done by concretizing this class. For instance, the following class defines a sequence with two steps that open input dialogs from some prototypes defined in the class. The first steps asks for a boolean value that will dinamically determines the second step input.

 public class MyInputSequence extends InputSequence {
    public MyInputSequence( Display display, 
                            AbstractMethodItem method, 
                            Object[] parameters ) {
       super(display,method,parameters);
    }
    public int getNbSteps() {
       return 2;
    }
    public void init() {}
    public void validate() {
       Object[] values = getStepValues(2);
       setParameterValue(0, values[0]);
       Boolean firstStepResult = getStepValues(1)[0];
       if ( firstStepResult.booleanValue() ) {
          setParameterValue(1, values[1]);
       } else {
          setParameterValue(1, null);
       }
    }
    public AbstractMethodItem getStepMethod( int step ) {
       if( step == 1 ) {
          return getLocalInputMethod( "myPrototype1" );
       } else if ( step == 2 ) {
          Object[] values = getStepValues(1);
          Boolean firstStepResult = values[0];
          if ( firstStepResult.booleanValue() ) {
             return getLocalInputMethod( "myPrototype2" );
          } else {
             return getLocalInputMethod( "myPrototype3" );
       } else {
          return null; 
       }
    }
    public void myPrototype1( boolean b ) {}
    public void myPrototype2( String s ) {}
    public void myPrototype3( String s1, String s2 ) {}
 }
 

Author:
Renaud Pawlak
See Also:
InputWrapper

Constructor Summary
InputSequence(Display display, AbstractMethodItem method, Object[] parameters)
          Creates a user-defined input sequence.
 
Method Summary
 int getCurrentStep()
          Returns the current step (indexed from 1).
protected  AbstractMethodItem getLocalInputMethod(String name)
          Returns the method item that corresponds to a method defined in the user-defined input sequence.
abstract  int getNbSteps()
          Define this method to return the number of steps (can dynamically change regarding the inputted vaules of the steps).
abstract  AbstractMethodItem getStepMethod(int step)
          Returns the method that is used to define the input box for a given step.
protected  Object[] getStepValues(int step)
          Returns the values that were entered by the user for a given step.
 boolean hasNextStep()
          Tells if the sequence has a next step to perform after the current one.
abstract  void init()
          This method is called when a new invocation is performed on the method.
 boolean nextStep()
          Process the next step.
 boolean previousStep()
          Process the previous step back.
 boolean proceedInputs()
          Call this method on a new input sequence to process the inputs.
protected  void setParameterValue(int i, Object value)
          Sets the parameter value for the final call of the method that will be invoked at the end of the sequence.
abstract  boolean validate()
          This method is called when the input sequence is finished and when the user validates the last step input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputSequence

public InputSequence(Display display,
                     AbstractMethodItem method,
                     Object[] parameters)
Creates a user-defined input sequence.

Parameters:
display - the display to use to show the input boxes
method - the method that will be finally invoked at the end of the input sequence
parameters - the array that contains the parameters of the invoked method
Method Detail

init

public abstract void init()
This method is called when a new invocation is performed on the method.

Define it if some objects must be dynamically constructed to handle the sequence.


validate

public abstract boolean validate()
This method is called when the input sequence is finished and when the user validates the last step input.

Define this method to fill the method parameters from the values found in all the performed steps.

Returns:
true is the input is valid (false cancels the invocation)
See Also:
getStepValues(int), setParameterValue(int,Object)

getNbSteps

public abstract int getNbSteps()
Define this method to return the number of steps (can dynamically change regarding the inputted vaules of the steps).

Returns:
the number of steps of the input sequence

getCurrentStep

public final int getCurrentStep()
Returns the current step (indexed from 1).

Returns:
the current step

hasNextStep

public final boolean hasNextStep()
Tells if the sequence has a next step to perform after the current one.

Returns:
true if a next step to perform

getStepMethod

public abstract AbstractMethodItem getStepMethod(int step)
Returns the method that is used to define the input box for a given step.

This is the most important method since it defines the shape of an input box step. You should define a set of local method with the right prototype and get their correponding method item with the getLocalInputMethod method.

Note that the method is not actually called but is only used through the Display.showIntput method.

Parameters:
step - the step (indexed from 1)
Returns:
the method that is used to create the input
See Also:
Display.showInput(Object,AbstractMethodItem,Object[]), getLocalInputMethod(String)

proceedInputs

public final boolean proceedInputs()
Call this method on a new input sequence to process the inputs.

Returns:
false if some error happened or if an input step was cancelled by the user

nextStep

public final boolean nextStep()
Process the next step.

Returns:
true if ok

previousStep

public boolean previousStep()
Process the previous step back.

Returns:
true if ok

getLocalInputMethod

protected AbstractMethodItem getLocalInputMethod(String name)
Returns the method item that corresponds to a method defined in the user-defined input sequence.

Parameters:
name - the method name
Returns:
the corresponding method item

getStepValues

protected Object[] getStepValues(int step)
Returns the values that were entered by the user for a given step.

Parameters:
step - the step number (indexed from 1)
Returns:
the user-inputted values

setParameterValue

protected void setParameterValue(int i,
                                 Object value)
Sets the parameter value for the final call of the method that will be invoked at the end of the sequence.

Parameters:
i - the parameter index
value - the value