|
Eclipse Platform Release 3.3 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.core.databinding.observable.ObservableTracker
This class makes it possible to monitor whenever an IObservable is read from. This can be used to automatically attach and remove listeners. How to use it:
If you are implementing an IObservable, invoke getterCalled(this) whenever a getter is called - that is, whenever your observable is read from. You only need to do this once per method call. If one getter delegates to another, the outer getter doesn't need to call the method since the inner one will.
If you want to determine what observables were used in a particular block of code, call runAndMonitor(Runnable). This will execute the given runnable and return the set of observables that were read from.
This can be used to automatically attach listeners. For example, imagine you have a block of code that updates some widget by reading from a bunch of observables. Whenever one of those observables changes, you want to re-run the code and cause the widget to be refreshed. You could do this in the traditional manner by attaching one listener to each observable and re-running your widget update code whenever one of them changes, but this code is repetitive and requires updating the listener code whenever you refactor the widget updating code.
Alternatively, you could use a utility class that runs the code in a runAndMonitor block and automatically attach listeners to any observable used in updating the widget. The advantage of the latter approach is that it, eliminates the code for attaching and detaching listeners and will always stay in synch with changes to the widget update logic.
Constructor Summary | |
---|---|
ObservableTracker()
|
Method Summary | |
---|---|
static void |
getterCalled(IObservable observable)
Notifies the ObservableTracker that an observable was read from. |
static IObservable[] |
runAndMonitor(Runnable runnable,
IChangeListener changeListener,
IStaleListener staleListener)
Invokes the given runnable, and returns the set of IObservables that were read by the runnable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObservableTracker()
Method Detail |
public static IObservable[] runAndMonitor(Runnable runnable, IChangeListener changeListener, IStaleListener staleListener)
runnable
- runnable to executechangeListener
- listener to register with all accessed observablesstaleListener
- listener to register with all accessed observables, or
null
if no stale listener is to be registered
public static void getterCalled(IObservable observable)
observable
-
|
Eclipse Platform Release 3.3 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp. and others 2000, 2007. All rights reserved.