net.refractions.udig.catalog.ui.workflow
Class Workflow

java.lang.Object
  extended by net.refractions.udig.catalog.ui.workflow.Workflow

public class Workflow
extends java.lang.Object


Nested Class Summary
static interface Workflow.Listener
           
static class Workflow.Runner
           
static class Workflow.State
           
 
Constructor Summary
Workflow()
          Creates an empty workflow.
Workflow(Workflow.State[] states)
          Creates a workflow from a set of workflow states.
 
Method Summary
 void addListener(Workflow.Listener l)
          Adds a listener to the workflow.
protected  void assertFinished()
           
protected  void assertNotFinished()
           
protected  void assertNotStarted()
           
protected  void assertStarted()
           
protected  void dispatchBackward(Workflow.State current, Workflow.State next)
           
protected  void dispatchFailed(Workflow.State state)
           
protected  void dispatchFinished(Workflow.State last)
           
protected  void dispatchForward(Workflow.State current, Workflow.State prev)
           
protected  void dispatchPassed(Workflow.State state)
           
protected  void dispatchStarted(Workflow.State start)
           
 java.lang.Object getContext()
          Returns an object representing a context for which the states can feed off of.
 Workflow.State getCurrentState()
           
<T> T
getState(java.lang.Class<T> c)
          Returns a state of a specific class.
 Workflow.State[] getStates()
           
 boolean hasMoreStates()
          Determines if the workflow has more states.
 boolean isFinished()
           
protected  boolean isPrimaryState(Workflow.State state)
           
 boolean isStarted()
           
 void next()
          Moves the workflow to the next state.
 void next(IProgressMonitor monitor)
          Moves the workflow to the next state.
 void previous()
          Moves the workflow to the previous state.
 void previous(IProgressMonitor monitor)
          Moves the workflow to the previous state.
 void removeListener(Workflow.Listener l)
           
 void reset()
          Resets the workflow.
 boolean run(IProgressMonitor monitor)
          Runs the workflow from its current state.
 void setContext(java.lang.Object context)
          Sets the object representing a context for which states can feed off of.
 void setStates(Workflow.State[] states)
          Sets the primary set of states of the workflow.
 void start()
          Starts the workflow by moving to the first state.
 void start(IProgressMonitor monitor)
          Starts the workflow by moving to the first state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Workflow

public Workflow()
Creates an empty workflow. When using this constructor the states of the workflow must be set before the workflow can be started.


Workflow

public Workflow(Workflow.State[] states)
Creates a workflow from a set of workflow states.

Parameters:
states - The states of the workflow.
Method Detail

addListener

public void addListener(Workflow.Listener l)
Adds a listener to the workflow. The listener collection is a set which prevents duplicates. For this resason clients may call this method multiple times with the same object.

Parameters:
l - The listening object.

removeListener

public void removeListener(Workflow.Listener l)

getContext

public java.lang.Object getContext()
Returns an object representing a context for which the states can feed off of. The context is often provided via a workbench selection.

Returns:
The context object, or null if none has been set

setContext

public void setContext(java.lang.Object context)
Sets the object representing a context for which states can feed off of. The context is often provided via a workbench selection.

Parameters:
context - The context object to set.

setStates

public void setStates(Workflow.State[] states)
Sets the primary set of states of the workflow.

Parameters:
states - An array of states.

getStates

public Workflow.State[] getStates()
Returns:
the primary set of states of the workflow.

getState

public <T> T getState(java.lang.Class<T> c)
Returns a state of a specific class.

Type Parameters:
T - The type of the state.
Parameters:
c - The class of the state.
Returns:
The state instance, or null if none exists.

start

public void start()
Starts the workflow by moving to the first state. This method must only be called once. This method executes asynchronously performing work in a seperate thread and does not block.


start

public void start(IProgressMonitor monitor)
Starts the workflow by moving to the first state. This method must only be called once. This method executes synchronously performing work in the current thread and blocks.


next

public void next()
Moves the workflow to the next state. This method executes asynchronously performing work in a seperate thread and does not block.


next

public void next(IProgressMonitor monitor)
Moves the workflow to the next state. This method executes synchronously performing work in the current thread and blocks.


previous

public void previous()
Moves the workflow to the previous state. This method executes asynchronously performing work in a seperate thread and does not block.


previous

public void previous(IProgressMonitor monitor)
Moves the workflow to the previous state. This method executes synchronously performing work in the current thread and blocks.


isStarted

public boolean isStarted()
Returns:
True if the workflow has been started with a call to #start().

isFinished

public boolean isFinished()
Returns:
True if the workflow has been finished. The workflow is considered finished after the call to #next(), while in the final state.

getCurrentState

public Workflow.State getCurrentState()
Returns:
the current state of the workflow.

hasMoreStates

public boolean hasMoreStates()
Determines if the workflow has more states. It is important to note that this method may not 100% accurate depending on the behaviour of states dynamically creating new states.

Returns:
True if there are more states, otherwise false.

run

public boolean run(IProgressMonitor monitor)
Runs the workflow from its current state. The workflow will continue to walk through the states while the state is finished.

Parameters:
monitor - A progress monitor.
Returns:
True if the pipe was able to run to completion, otherwise false.

reset

public void reset()
Resets the workflow. This method may only be called if the workflow is in a finished state. Once reset the workflow lifecycle starts again with a call to @see DataPipeline#start().


assertStarted

protected void assertStarted()

assertNotStarted

protected void assertNotStarted()

assertFinished

protected void assertFinished()

assertNotFinished

protected void assertNotFinished()

isPrimaryState

protected boolean isPrimaryState(Workflow.State state)

dispatchStarted

protected void dispatchStarted(Workflow.State start)

dispatchForward

protected void dispatchForward(Workflow.State current,
                               Workflow.State prev)

dispatchBackward

protected void dispatchBackward(Workflow.State current,
                                Workflow.State next)

dispatchPassed

protected void dispatchPassed(Workflow.State state)

dispatchFailed

protected void dispatchFailed(Workflow.State state)

dispatchFinished

protected void dispatchFinished(Workflow.State last)