org.gudy.azureus2.ui.swt.progress
Interface IProgressReporterListener

All Superinterfaces:
IProgressReportConstants
All Known Implementing Classes:
ProgressReporterPanel

public interface IProgressReporterListener
extends IProgressReportConstants

A simple listener interface used to pass a ProgressReport to a listener from a ProgressReporter

Author:
knguyen

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
 
Method Summary
 int report(IProgressReport progressReport)
          When an event is detected this callback method will be called so listeners can take appropriate action such as updating a UI element
 

Method Detail

report

int report(IProgressReport progressReport)
When an event is detected this callback method will be called so listeners can take appropriate action such as updating a UI element

Currently there are 2 return types recognized:

The return value of RETVAL_OK_TO_DISPOSE is a hint to the caller that it is now safe to remove this listener from the caller's list of listeners. This pattern allows the caller to perform clean up operations associated with this listener, and allows the listener to initiate its own removal from within an event loop.

A typical life cycle of an event listener is create listener, register listener, then remove listener. To accomplish all three steps we would need a reference to the listeners at all time as can be seen in this sample:

 ProgressReporter reporter = new ProgressReporter("I'm a reporter");
 
 // Create a concrete listener since we need to remove it later for clean up
 IProgressReporterListener listener = new IProgressReporterListener() {
        public int report(ProgressReport progressReport) {
                // Do some work here
                return RETVAL_OK;
        }
 };
 
 // Add the listener
 reporter.addListener(listener);
 
 // Do some more work
 
 // Then for clean up remove the listener
 if ([some condition] == true) {
        reporter.removeListener(listener);
 }
 
 
Sometime it is more convenient to remove a listener from within the call to .report() but a direct attempt at removal of this listener may result in modification conflict since most likely this method is being called from within an iterator loop which does not allow concurrent modifications. To address this limitation we make use of the RETVAL_OK_TO_DISPOSE as a return code which will allow the caller to perform the clean up as in this modification of the example above:
 ...
 
 final IProgressReporterListener listener = new IProgressReporterListener() {
        public int report(ProgressReport progressReport) {
 
                // Do some work here
 
                // This would throw a ConcurrentModificationException
                reporter.removeListener(listener); 
 
                // This would work
                if ([some condition] == true) {
                        return RETVAL_OK_TO_DISPOSE;
                }
 
                return RETVAL_OK;
        }
 };
 

If the decision to remove a listener is based on the information contained in the given ProgressReport we can implement a much simpler listener as an inner class like so:

 
 ProgressReporter reporter = new ProgressReporter("I'm a reporter");
 
 // Creates an anonymous inner class using RETVAL_OK_TO_DISPOSE to initiate clean up  
 reporter.addListener(new IProgressReporterListener() {
        public int report(ProgressReport progressReport) {
 
                // Do some work
 
                if ([some condition] == true) {
                        return RETVAL_OK_TO_DISPOSE;
                }
                return RETVAL_OK;
 
        }}
 );
 
 
 

Parameters:
progressReport -
Returns: