public class BackgroundTask extends java.lang.Object implements ConfigurableUnit
GraphicsEnvironment.isHeadless()
method before any dialogs are
shown.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MESSAGE_TYPE_ERR
Represents a message for
System.err . |
static java.lang.String |
MESSAGE_TYPE_OUT
Represents a message for
System.out . |
static int |
STATUS_CANCELLED
Status for the task, cancelled by user.
|
static int |
STATUS_ERROR
Status for the task, finished with errors.
|
static int |
STATUS_INACTIVE
Status for the task, not started yet.
|
static int |
STATUS_INFO
Status for the task, finished with success but with notices.
|
static int |
STATUS_INTERRUPTED
Status for the task, interrupted programmatically (e.g. to prevent OutOfMemoryError).
|
static int |
STATUS_OK
Status for the task, finished with success.
|
static int |
STATUS_RUNNING
Status for the task, currently running.
|
static int |
STATUS_TIMEOUT
Status for the task, cancelled by timeout.
|
static int |
STATUS_WARNING
Status for the task, finished with warnings.
|
protected java.util.Vector<TaskListener> |
taskListeners
Container holding the external task listeners.
|
Constructor and Description |
---|
BackgroundTask()
Constructor method for i18n purposes only.
|
BackgroundTask(java.lang.Runnable task,
java.lang.String title,
java.lang.String desc,
java.lang.String threadName,
int priority,
boolean cancelAllowed,
boolean exclusive,
int exclusiveTimeout,
boolean indeterminate,
javax.swing.Icon icon,
boolean autoClose,
boolean canRestart,
boolean keepFinished,
boolean autoBackground,
java.lang.String helpID,
boolean logmessages)
Constructor settings the initial values.
|
Modifier and Type | Method and Description |
---|---|
void |
addTaskListener(TaskListener listener)
Adds a listener reacting on task completions.
|
static float |
calculateProgress(long min,
long max,
long value)
Convenience method to calculate the progress as percentile (0%-100%).
|
boolean |
canRestart()
Can the task be restarted by the task manager?
|
void |
configureUnit(java.lang.String id,
Configuration config)
Restores values from persistent data stores.
|
boolean |
equals(BackgroundTask tocheck)
Checks wether a given
BackgroundTask instance is equal to this. |
protected void |
finalize()
Clean-up method to help the gc.
|
java.lang.String |
getDescription()
Getter for description.
|
java.util.Date |
getEndDate()
Getter for time the task finished.
|
int |
getExclusiveTimeout()
Getter for the exclusive mode timeout.
|
java.lang.String |
getHelpID()
Provides the link to the help system of the application.
|
javax.swing.Icon |
getIcon()
Getter for the icon representing the task.
|
java.lang.String |
getMessage()
Getter for current message.
|
java.util.Vector<java.lang.String[]> |
getMessages()
Getter for logged messages (optional).
|
int |
getPriority()
Getter for priority.
|
float |
getProgress()
Getter for current progress value in the range between 0% and 100%.
|
java.util.Date |
getStartDate()
Getter for start time.
|
int |
getStatus()
Getter for current status.
|
java.lang.Runnable |
getTask()
Getter for task.
|
TaskDialog |
getTaskDialog()
Provides the reference for the task dialog (not set when executed from command line).
|
TaskListener[] |
getTaskListeners()
Provides the optional listeners reacting on task completions.
|
java.lang.String |
getThreadName()
Getter for thread name.
|
java.lang.String |
getTitle()
Getter for dialog title.
|
boolean |
hasFinished()
Has this task being finished?
|
boolean |
isAutoBackground()
Getter for auto-backgrounding feature used by the task dialog.
|
boolean |
isAutoClose()
Getter for auto-close feature used by the task dialog.
|
boolean |
isCancelAllowed()
Getter for cancel capability.
|
boolean |
isExclusive()
Getter for exclusive mode.
|
boolean |
isIndeterminate()
Getter for indeterminate mode.
|
boolean |
isInterrupted()
Getter for current interruption state.
|
boolean |
isKeepFinished()
Keep the task within the task manager when finished?
|
boolean |
isUnitRegistered()
Is the instance currently being configured?
|
void |
removeTaskListener(TaskListener listener)
Removes a listener reacting on task completions.
|
void |
resetProgress()
Setter for current progress to the initial start value 0
|
void |
setAutoBackground(boolean enabled)
Setter for auto-backgrounding feature used by the task dialog.
|
void |
setAutoClose(boolean enabled)
Setter for auto-close feature used by the task dialog.
|
void |
setEndDate(java.util.Date endDate)
Setter for time the task finished.
|
void |
setInterrupted(boolean interrupted)
Setter for current interruption state.
|
void |
setKeepFinished(boolean keepfinished)
Setter for current keep finished state.
|
void |
setMessage(java.lang.String message)
Setter for current message.
|
void |
setMessage(java.lang.String message,
java.lang.String type)
Setter for current message.
|
void |
setMessages(java.util.Vector<java.lang.String[]> messages)
Overrides the internally used message container with shared instance.
|
void |
setProgress(float progress)
Setter for current progress value in the range between 0% and 100%.
|
void |
setProgress(long min,
long max,
long value)
Convenience method to set the progress by calculating the percentile.
|
void |
setStartDate(java.util.Date startDate)
Setter for start time.
|
void |
setStatus(int status)
Setter for current status.
|
void |
setStatusAndMessage(int status,
java.lang.String message)
Convenience method to set both message and status.
|
void |
setTaskDialog(TaskDialog dialog)
Sets the reference for the task dialog (not set when executed from command line).
|
void |
storeUnit(java.lang.String id,
Configuration config)
Stores the current configuration values persistently.
|
java.lang.String |
toString()
Overrides method
java.lang.Object.toString . |
void |
unitRegistered(ApplicationModel model,
java.lang.String id)
Informs the configurable unit that it was registered with a model.
|
void |
unitUnregistered(ApplicationModel model,
java.lang.String id)
Informs the configurable unit that it was unregistered with a model.
|
void |
unregisterUnit()
Is the instance currently being configured?
|
public static final int STATUS_INACTIVE
public static final int STATUS_RUNNING
public static final int STATUS_OK
public static final int STATUS_INFO
public static final int STATUS_WARNING
public static final int STATUS_ERROR
public static final int STATUS_CANCELLED
public static final int STATUS_TIMEOUT
public static final int STATUS_INTERRUPTED
public static final java.lang.String MESSAGE_TYPE_OUT
System.out
.public static final java.lang.String MESSAGE_TYPE_ERR
System.err
.protected java.util.Vector<TaskListener> taskListeners
public BackgroundTask() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic BackgroundTask(java.lang.Runnable task, java.lang.String title, java.lang.String desc, java.lang.String threadName, int priority, boolean cancelAllowed, boolean exclusive, int exclusiveTimeout, boolean indeterminate, javax.swing.Icon icon, boolean autoClose, boolean canRestart, boolean keepFinished, boolean autoBackground, java.lang.String helpID, boolean logmessages)
task
- The task itself (required)title
- The short title used for the task dialog, may be null
desc
- The more detailed description of the task e.g. used as task dialog subtitle, may be null
threadName
- The desired name of the task thread, may be null
priority
- Thread priority used by the manager to execute the taskcancelAllowed
- May the task be cancelled by the user?exclusive
- Must the task be executed exclusively (<= 0 deactivates)?exclusiveTimeout
- Exclusive task times out after a while (seconds)?indeterminate
- Can the progress value be monitored or not?icon
- The icon representing the task, may be null
autoClose
- Activate the auto-closing feature?canRestart
- Can the task be restarted by the task manager?keepFinished
- Keep the task within the task manager when finished?autoBackground
- Activate the auto-backgrounding feature?helpID
- Identifier to call the help system (optional)logmessages
- Shall messages be logged sequentially (optional)?java.lang.NullPointerException
- If the task is null
java.lang.IllegalArgumentException
- If at least one of the parameters is invalidprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Error indicationpublic java.lang.String toString()
java.lang.Object.toString
.
toString
in class java.lang.Object
public boolean equals(BackgroundTask tocheck)
BackgroundTask
instance is equal to this.
tocheck
- The instance to be comparedBackgroundTask
instance to check for equalitypublic java.lang.Runnable getTask()
public java.lang.String getTitle()
public java.lang.String getDescription()
public java.lang.String getThreadName()
public int getPriority()
public boolean isCancelAllowed()
public boolean isExclusive()
public int getExclusiveTimeout()
public boolean isIndeterminate()
public boolean isAutoClose()
public void setAutoClose(boolean enabled)
enabled
- The auto-close featurepublic boolean isAutoBackground()
public void setAutoBackground(boolean enabled)
enabled
- The auto-backgrounding featurepublic java.util.Date getStartDate()
public void setStartDate(java.util.Date startDate)
startDate
- The start timepublic java.util.Date getEndDate()
public void setEndDate(java.util.Date endDate)
endDate
- The time the task finishedpublic float getProgress()
public void setProgress(float progress)
progress
- The current progresspublic void resetProgress()
public void setProgress(long min, long max, long value)
min
- Minimum valuemax
- Maximum valuevalue
- The current valuejava.lang.IllegalArgumentException
- If parameters are invalid (e.g. max < min)public static float calculateProgress(long min, long max, long value)
min
- Minimum valuemax
- Maximum valuevalue
- The current valuejava.lang.IllegalArgumentException
- If parameters are invalid (e.g. max < min)public java.lang.String getMessage()
null
public java.util.Vector<java.lang.String[]> getMessages()
logmessages
parameter.
null
if not availablepublic void setMessages(java.util.Vector<java.lang.String[]> messages)
messages
- The message cachejava.lang.NullPointerException
- If a parameter is null
public void setMessage(java.lang.String message)
message
- The current message, may be null
public void setMessage(java.lang.String message, java.lang.String type)
message
- The current message, may be null
type
- The message type (optional), defaults to MESSAGE_TYPE_OUT
public void setStatusAndMessage(int status, java.lang.String message)
status
- The statusmessage
- The final messagepublic int getStatus()
public void setStatus(int status)
status
- The current status of the taskjava.lang.IllegalArgumentException
- If the status is invalidpublic javax.swing.Icon getIcon()
public boolean canRestart()
public boolean isKeepFinished()
public void setKeepFinished(boolean keepfinished)
keepfinished
- The current keep finished statepublic boolean isInterrupted()
public void setInterrupted(boolean interrupted)
interrupted
- The current interruption statepublic void configureUnit(java.lang.String id, Configuration config)
configureUnit
in interface ConfigurableUnit
id
- The unique identifier for the instanceconfig
- The configurationpublic void storeUnit(java.lang.String id, Configuration config)
storeUnit
in interface ConfigurableUnit
id
- The unique identifier for the instanceconfig
- The configurationpublic void unitRegistered(ApplicationModel model, java.lang.String id)
unitRegistered
in interface ConfigurableUnit
model
- The application modelid
- The unique identifier for the instancepublic void unitUnregistered(ApplicationModel model, java.lang.String id)
unitUnregistered
in interface ConfigurableUnit
model
- The application modelid
- The unique identifier for the instancepublic boolean isUnitRegistered()
public void unregisterUnit()
public void addTaskListener(TaskListener listener)
listener
- The listener instancejava.lang.NullPointerException
- If parameter is null
public void removeTaskListener(TaskListener listener)
listener
- The listener instancejava.lang.NullPointerException
- If parameter is null
public TaskListener[] getTaskListeners()
BackgroundTaskManager
instance.
java.lang.NullPointerException
- If parameter is null
public java.lang.String getHelpID()
null
public boolean hasFinished()
public void setTaskDialog(TaskDialog dialog)
dialog
- The dialog, may be null
public TaskDialog getTaskDialog()
null
Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.