public void run() { cachedList = calculate(); if (cachedList == null) cachedList = Collections.EMPTY_LIST; }
private final List getList() { getterCalled(); return doGetList(); }
private void makeDirty() { if (!dirty) { dirty = true; makeStale(); stopListening(); // copy the old list final List oldList = new ArrayList(cachedList); // Fire the "dirty" event. This implementation recomputes the new // list lazily. fireListChange(new ListDiff() { ListDiffEntry[] differences; public ListDiffEntry[] getDifferences() { if (differences == null) differences = Diffs.computeListDiff(oldList, getList()) .getDifferences(); return differences; } }); } }
public synchronized void addListChangeListener(IListChangeListener listener) { super.addListChangeListener(listener); // If somebody is listening, we need to make sure we attach our own // listeners computeListForListeners(); }
private void makeStale() { if (!stale) { stale = true; fireStale(); } }
public boolean isStale() { // recalculate list if dirty, to ensure staleness is correct. getList(); return stale; }
protected int doGetSize() { return doGetList().size(); }
public synchronized void dispose() { stopListening(); super.dispose(); } }
private void computeListForListeners() { // Some clients just add a listener and expect to get notified even if // they never called getValue(), so we have to call getValue() ourselves // here to be sure. Need to be careful about realms though, this method // can be called outside of our realm. // See also bug 198211. If a client calls this outside of our realm, // they may receive change notifications before the runnable below has // been executed. It is their job to figure out what to do with those // notifications. getRealm().exec(new Runnable() { public void run() { if (dependencies == null) { // We are not currently listening. // But someone is listening for changes. Call getValue() // to make sure we start listening to the observables we // depend on. getList(); } } }); }
final List doGetList() { if (dirty) { // This line will do the following: // - Run the calculate method // - While doing so, add any observable that is touched to the // dependencies list IObservable[] newDependencies = ObservableTracker.runAndMonitor( privateInterface, privateInterface, null); // If any dependencies are stale, a stale event will be fired here // even if we were already stale before recomputing. This is in case // clients assume that a list change is indicative of non-staleness. stale = false; for (int i = 0; i < newDependencies.length; i++) { if (newDependencies[i].isStale()) { makeStale(); break; } } if (!stale) { for (int i = 0; i < newDependencies.length; i++) { newDependencies[i].addStaleListener(privateInterface); } } dependencies = newDependencies; dirty = false; } return cachedList; }
public synchronized void addChangeListener(IChangeListener listener) { super.addChangeListener(listener); // If somebody is listening, we need to make sure we attach our own // listeners computeListForListeners(); }
public Object get(int index) { getterCalled(); return doGetList().get(index); }