|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.gudy.azureus2.ui.swt.progress.ProgressReporter
public class ProgressReporter
A implementation of IProgressReporter
Any process wishing to participate in providing global progress indication can instantiate this class and simply use the available methods so set values or issue a command
When ever any state changes in this reporter a notification will be sent to the global
reporting manager ProgressReportingManager
followed by a notification to all
registered listeners of this reporter
ProgressReporter.ProgressReport
which
represents a snapshot of all the public properties contained in this reporter; inspecting the
ProgressReport is the only way a listener can query the properties of this reporter. This pattern
allows the ProgressReporter to continue and process requests by not having to thread lock all public
methods. Additionally, the listeners are guaranteed a consistent snapshot of the reporter.
This reporter also has the capability to receive loop back commands from a listener for actions such like
cancel()
and retry()
. These commands are enabled by calling
setCancelAllowed(boolean)
or setRetryAllowed(boolean)
.
The listener only initiates these actions by sending a notification back to the owner of the reporter;
it is up the to owner to perform the actual act of canceling or retrying.
A typical life cycle of the ProgresReporter as seen from an owner is as follows (an owner is defined as the process that created the reporter):
setSelection(int, String)
, setPercentage(int, String)
]setMessage(String)
]setDone()
]ProgressReporter#dispose(Object)
]In addition to internal clean-ups, calling dispose(Object) will effectively remove the reporter from the history stack of the reporting manager and no more messages from this reporter will be processed.
Once a reporter is created and any property in the reporter is set the global reporting manager is notified; at which point any listener listening to the manager is forwarded this reporter. The manager listener may decide to display this reporter in a UI element, may register specific listeners to this reporter, may query its properties and take action, or can simply monitor it for such functions as logging.
This implementation is non-intrusive to the owner process and so provides existing processes the ability to participate in global progress indication without significant modification to the underlying processes.
Nested Class Summary | |
---|---|
class |
ProgressReporter.ProgressReport
An immutable object containing all interesting values in a ProgressReporter . |
Field Summary |
---|
Fields inherited from interface org.gudy.azureus2.ui.swt.progress.IProgressReportConstants |
---|
AUTO_CLOSE, BORDER, MANAGER_EVENT_ADDED, MANAGER_EVENT_REMOVED, MANAGER_EVENT_UPDATED, MODAL, MSG_TYPE_ERROR, MSG_TYPE_INFO, MSG_TYPE_LOG, NONE, REPORT_TYPE_CANCEL, REPORT_TYPE_DISPOSED, REPORT_TYPE_DONE, REPORT_TYPE_ERROR, REPORT_TYPE_INIT, REPORT_TYPE_MODE_CHANGE, REPORT_TYPE_PROPERTY_CHANGED, REPORT_TYPE_RETRY, REPORTER_TYPE_DEFAULT, REPORTER_VISIBILITY_SYSTEM, REPORTER_VISIBILITY_USER, RETVAL_OK, RETVAL_OK_TO_DISPOSE, SHOW_TOOLBAR, STANDALONE |
Constructor Summary | |
---|---|
protected |
ProgressReporter(ProgressReportingManager manager)
Construct a ProgressReporter ; the returned instance is initialized with the proper ID |
protected |
ProgressReporter(ProgressReportingManager _manager,
String name)
Construct a ProgressReporter with the given name ; the returned
instance would have been initialized with the proper ID |
Method Summary | |
---|---|
void |
addListener(IProgressReporterListener listener)
|
void |
appendDetailMessage(String detailMessage)
Appends the detail message to this reporter. |
void |
cancel()
Marks this reporter as canceled and notify any listeners about it |
int |
compareTo(Object obj)
Numerically compare by reporter ID's |
void |
dispose()
Disposes any resources or listeners that this reporter has references to or otherwise is responsible for |
boolean |
equals(Object obj)
Reporters are equal iif they have the same ID |
boolean |
getCancelCloses()
|
IMessage[] |
getMessageHistory()
Returns an array of IMessage 's that has been generated since the reporter was created |
IProgressReport |
getProgressReport()
Returns an IProgressReport which is a snapshot of this reporter |
int |
hashCode()
Hashcode and ID are the same |
void |
removeListener(IProgressReporterListener listener)
|
void |
retry()
Notifies listener that a retry is requested |
void |
setCancelAllowed(boolean cancelAllowed)
Sets whether the process associated with this reporter is allowed to be canceled by the user. |
void |
setCancelCloses(boolean b)
|
void |
setDone()
Indicates that the associated process is done |
void |
setErrorMessage(String errorMessage)
Sets an error message to this reporter; subsequently isInErrorState will be set to true |
void |
setImage(org.eclipse.swt.graphics.Image image)
Sets the image corresponding to this reporter; this image may be used by the UI to decorate this reporter |
void |
setIndeterminate(boolean isIndeterminate)
Set this reporter into indeterminate mode; use this when an accurate ratio of amount of work done vs. |
void |
setMaximum(int max)
|
void |
setMessage(String message)
Sets the current status message for this reporter; this is typically used to display a message at each incremental update |
void |
setMinimum(int min)
|
void |
setName(String name)
|
void |
setObjectData(Object objectData)
An arbitrary object reference that can be used to further identify the reporter. |
void |
setPercentage(int percentage,
String message)
Sets the percentage value to the progress reporter; this is used when a simple percentage is specified as opposed to setting min, max, and selection. |
void |
setReporterType(String reporterType)
Sets the type of a reporter. |
void |
setRetryAllowed(boolean retryOnError)
This is a hint to any UI components displaying this reporter to determine if the user should be prompted to retry on error |
void |
setSelection(int selection,
String message)
Sets the selection to the progress reporter; this is used when a traditional min, max, selection is specified. |
void |
setTitle(String title)
Sets the title that may be used by a UI component. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ProgressReporter(ProgressReportingManager manager)
ProgressReporter
; the returned instance is initialized with the proper ID
protected ProgressReporter(ProgressReportingManager _manager, String name)
ProgressReporter
with the given name
; the returned
instance would have been initialized with the proper ID
name
- Method Detail |
---|
public void setReporterType(String reporterType)
IProgressReporter
setReporterType
in interface IProgressReporter
public void dispose()
IProgressReporter
Also removes it from the global ProgressReportingManager
so that any subsequent event
from this reporter is no longer forwarded
dispose
in interface IProgressReporter
public void setSelection(int selection, String message)
IProgressReporter
selection
to the progress reporter; this is used when a traditional min, max, selection is specified.
NOTE: this selection value also synchronize the percentage
value of this reporter
setSelection
in interface IProgressReporter
public void setPercentage(int percentage, String message)
IProgressReporter
percentage
value to the progress reporter; this is used when a simple percentage is specified as opposed to setting min, max, and selection.
NOTE: this percentage value also synchronize the selection
value of this reporter
setPercentage
in interface IProgressReporter
percentage
- an integer from 0-100message
- a textual message to display; null
to leave the previous message untouched, empty String to clear any previous messagepublic void setIndeterminate(boolean isIndeterminate)
IProgressReporter
setIndeterminate
in interface IProgressReporter
public void setDone()
IProgressReporter
setDone
in interface IProgressReporter
public void setMessage(String message)
IProgressReporter
setMessage
in interface IProgressReporter
message
- a textual messagepublic void appendDetailMessage(String detailMessage)
IProgressReporter
null
)or show the regular message in its place
Additionally this is an appending message so that reporters can send smaller units of the message rather than having to store and send the entire (and ever increasing) messages for each update
appendDetailMessage
in interface IProgressReporter
public void setMinimum(int min)
setMinimum
in interface IProgressReporter
min
- the min to setpublic void setMaximum(int max)
setMaximum
in interface IProgressReporter
max
- the max to setpublic void cancel()
IProgressReporter
NOTE: This is only a hint back to the processes listening to this reporter; it is up to that process to determine the correct course of action in response to this flag
cancel
in interface IProgressReporter
public void retry()
IProgressReporter
retry
in interface IProgressReporter
public void setCancelAllowed(boolean cancelAllowed)
IProgressReporter
true
the manager may
enable a UI component allowing the user to cancel the associated process if appropriate.
The holder of this reporter can register a listener to receive the cancel event
setCancelAllowed
in interface IProgressReporter
cancelAllowed
- true
to indicate that this process may solicit a REPORT_TYPE_CANCEL
input from the user;
default is false
IProgressReporter.addListener(IProgressReporterListener)
,
IProgressReporter.removeListener(IProgressReporterListener)
public void setName(String name)
setName
in interface IProgressReporter
name
- a textual name to identify the process this reporter represents; need not be unique (should not be used as a lookup key), and may be null
.public void setTitle(String title)
IProgressReporter
setTitle
in interface IProgressReporter
title
- the title to setpublic void setImage(org.eclipse.swt.graphics.Image image)
IProgressReporter
NOTE: Though not strictly required (nor enforced) the image should be 32X32 pixels with transparency. If not then cropping or enlargement may be applied as required by the particular UI
setImage
in interface IProgressReporter
image
- the image; may be null
public void setErrorMessage(String errorMessage)
IProgressReporter
isInErrorState
will be set to true
setErrorMessage
in interface IProgressReporter
#reInit()
public void setRetryAllowed(boolean retryOnError)
IProgressReporter
setRetryAllowed
in interface IProgressReporter
public boolean getCancelCloses()
getCancelCloses
in interface IProgressReporter
public void setCancelCloses(boolean b)
setCancelCloses
in interface IProgressReporter
public void setObjectData(Object objectData)
IProgressReporter
ProgressReporter.ProgressReport.objectData
so that it can be used to pass information to and from the listeners.
setObjectData
in interface IProgressReporter
objectData
- the objectData to setpublic IMessage[] getMessageHistory()
IProgressReporter
IMessage
's that has been generated since the reporter was created
getMessageHistory
in interface IProgressReporter
public void addListener(IProgressReporterListener listener)
addListener
in interface IProgressReporter
public void removeListener(IProgressReporterListener listener)
removeListener
in interface IProgressReporter
public int compareTo(Object obj)
compareTo
in interface Comparable
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public IProgressReport getProgressReport()
IProgressReporter
IProgressReport
which is a snapshot of this reporter
NOTE: Each call to this method creates a new snapshot therefore the correct usage pattern is:
IProgressReport report = getProgressReport(); if( report.isDone() == false ){ // Do something { else if( report.isCanceled() == false ){ // Do something else { ...It may be tempting to use the less verbose pattern by repeatedly calling this method directly such as:
if( getProgressReport().isDone == false ){ // Do something { else if( getProgressReport().isCanceled == false ){ // Do something else {BUT this can produce inconsistent results since each successive call to getProgressReport() is returning a different snapshot.
getProgressReport
in interface IProgressReporter
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |