public abstract class Operation
extends java.lang.Object
Base class for all operations.
It supports progress notification.
All classes that want to be notified by a new progress level of the operation
(defined as value between 0.0f (nothing has been done so far) to 1.0f
(operation finished)) must implement the ProgressListener
interface.
An abortion state is stored in each Operation object.
It should be queried by a running operation from time to time
(via getAbort()
- if it returns true
,
the operation should terminate and return control to the caller.
The abort state can be modified using setAbort(boolean)
.
Modifier and Type | Field and Description |
---|---|
private boolean |
abort |
private java.util.Vector |
progressListeners |
Constructor and Description |
---|
Operation()
This constructor creates two internal empty lists for progress listeners and parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
addProgressListener(ProgressListener progressListener)
Adds the argument progress listener to the internal list of
progress listeners.
|
void |
addProgressListeners(java.util.Vector progressListeners)
Adds several progress listeners to this operation object.
|
boolean |
getAbort()
Returns the current abort status.
|
void |
process()
This method does the actual work of the operation.
|
void |
removeProgressListener(ProgressListener progressListener)
Removes the argument progress listener from the internal list of
progress listeners.
|
void |
setAbort(boolean newAbortStatus)
Sets a new abort status.
|
void |
setProgress(float progress)
This method will notify all registered progress listeners
about a new progress level.
|
void |
setProgress(int zeroBasedIndex,
int totalItems)
This method will notify all registered progress listeners
about a new progress level.
|
private boolean abort
private java.util.Vector progressListeners
public Operation()
public void addProgressListener(ProgressListener progressListener)
progressListener
- the progress listener to be addedpublic void addProgressListeners(java.util.Vector progressListeners)
progressListeners
- contains zero or more objects implementing ProgressListener;
each will be added by calling addProgressListener(net.sourceforge.jiu.ops.ProgressListener)
on itpublic boolean getAbort()
true
, a running operation should terminate what it is doing
(return from process()
).setAbort(boolean)
public void process() throws MissingParameterException, OperationFailedException, WrongParameterException
WrongParameterException
- if at least one of the input parameters was
not initialized appropriately (values out of the valid interval, etc.)MissingParameterException
- if any mandatory parameter was not given to the operationOperationFailedException
public void removeProgressListener(ProgressListener progressListener)
progressListener
- the progress listener to be removedpublic void setAbort(boolean newAbortStatus)
newAbortStatus
- the new statusgetAbort()
public void setProgress(float progress)
progress
- new progress value, from 0.0 to 1.0public void setProgress(int zeroBasedIndex, int totalItems)
setProgress((float)zeroBasedIndex / (float)totalItems);
.zeroBasedIndex
- the index of the item that was just processed, zero-basedtotalItems
- the number of items that will be processed