dsto.dfc.swt.util
Class UIPropertyListener

java.lang.Object
  extended by dsto.dfc.swt.util.UIPropertyListener
All Implemented Interfaces:
PropertyListener, Disposable, EventListener

public class UIPropertyListener
extends Object
implements Disposable, PropertyListener

A DataObject property listener adapter that re-routes property change events that occur outside the UI thread into the UI thread by using Display.asyncExec ().

Threading note: clients should call dispose () (ideally dispose(IDataObject)) to remove this listener. This will ensure that any async property updates in the display pipeline will be cancelled rather than calling into a disposed UI element.

Author:
Matthew Phillips

Field Summary
protected  ClassLoader contextClassLoader
           
protected  org.eclipse.swt.widgets.Display display
          Display is used as an interthread variable, so mark as volatile.
protected  PropertyListener listener
           
 
Constructor Summary
UIPropertyListener(org.eclipse.swt.widgets.Control control)
          Shortcut to create a listener for a SWT control that is also the property listener.
UIPropertyListener(org.eclipse.swt.widgets.Display display, PropertyListener listener)
          Create a new instance.
 
Method Summary
static UIPropertyListener create(org.eclipse.swt.widgets.Control control, IDataObject object)
          Factory to create a listener for a SWT control that is also the property listener.
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 void dispose(IDataObject object)
          Remove this listener and dispose it.
protected  ClassLoader installClassLoader(ClassLoader newClassLoader)
          Swaps in a specified class loader
 void propertyValueChanged(PropertyEvent e)
           
protected  void restoreClassLoader(ClassLoader origLoader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

display

protected volatile org.eclipse.swt.widgets.Display display
Display is used as an interthread variable, so mark as volatile. We use this rather than locking due to the high possibility of deadlocking if we hold a lock while calling into client code.


listener

protected PropertyListener listener

contextClassLoader

protected ClassLoader contextClassLoader
Constructor Detail

UIPropertyListener

public UIPropertyListener(org.eclipse.swt.widgets.Control control)
Shortcut to create a listener for a SWT control that is also the property listener.

Parameters:
control - The control: must implement PropertyListener.
See Also:
create(Control, IDataObject)

UIPropertyListener

public UIPropertyListener(org.eclipse.swt.widgets.Display display,
                          PropertyListener listener)
Create a new instance.

Parameters:
display - The display.
listener - The listener that will be called by this one, guaranteed from the UI thread.
Method Detail

create

public static UIPropertyListener create(org.eclipse.swt.widgets.Control control,
                                        IDataObject object)
Factory to create a listener for a SWT control that is also the property listener. The listener is automatically added as a property listener to the object, and is disposed when the control is.

Parameters:
control - The control: must implement PropertyListener.
object - The object to listen to.

propertyValueChanged

public void propertyValueChanged(PropertyEvent e)
Specified by:
propertyValueChanged in interface PropertyListener

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable

dispose

public void dispose(IDataObject object)
Remove this listener and dispose it.

Parameters:
object - The object to remove the listener from. Removing the listener this way ensures no event can sneak in while disposing.

installClassLoader

protected ClassLoader installClassLoader(ClassLoader newClassLoader)
Swaps in a specified class loader

Parameters:
newClassLoader -
Returns:
The original class loader

restoreClassLoader

protected void restoreClassLoader(ClassLoader origLoader)


Copyright © 2008 Commonwealth of Australia