Package com.biglybt.ui.swt.progress
Class ProgressReporterWindow.AutoRemoveListener
- java.lang.Object
-
- com.biglybt.ui.swt.progress.ProgressReporterWindow.AutoRemoveListener
-
- All Implemented Interfaces:
IProgressReportConstants
,IProgressReporterListener
- Enclosing class:
- ProgressReporterWindow
private class ProgressReporterWindow.AutoRemoveListener extends java.lang.Object implements IProgressReporterListener
Listener to reporters so we can remove the correspondingProgressReporterPanel
is the optionisAutoRemove
=true
-
-
Field Summary
Fields Modifier and Type Field Description private ProgressReporterPanel
panel
-
Fields inherited from interface com.biglybt.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
Constructors Modifier Constructor Description private
AutoRemoveListener(ProgressReporterPanel panel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
Field Detail
-
panel
private ProgressReporterPanel panel
-
-
Constructor Detail
-
AutoRemoveListener
private AutoRemoveListener(ProgressReporterPanel panel)
-
-
Method Detail
-
report
public int report(IProgressReport progressReport)
Description copied from interface:IProgressReporterListener
When an event is detected this callback method will be called so listeners can take appropriate action such as updating a UI elementCurrently there are 2 return types recognized:
RETVAL_OK
- Indicates the givenProgressReport
has been consumed successfullyRETVAL_OK_TO_DISPOSE
- Indicates that this listener is no longer interested in any subsequent reports
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 theRETVAL_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; }} );
- Specified by:
report
in interfaceIProgressReporterListener
- Returns:
-
-