Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/StalenessTracker.d @ 85:6be48cf9f95c
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:54:50 +0200 |
parents | 383ce7bd736b |
children |
comparison
equal
deleted
inserted
replaced
84:fcf926c91ca4 | 85:6be48cf9f95c |
---|---|
28 * @since 1.0 | 28 * @since 1.0 |
29 * | 29 * |
30 */ | 30 */ |
31 public class StalenessTracker { | 31 public class StalenessTracker { |
32 | 32 |
33 private Map staleMap = new HashMap(); | 33 private Map staleMap; |
34 | 34 |
35 private int staleCount = 0; | 35 private int staleCount = 0; |
36 | 36 |
37 private final IStalenessConsumer stalenessConsumer; | 37 private final IStalenessConsumer stalenessConsumer; |
38 | 38 |
44 public void handleChange(ChangeEvent event) { | 44 public void handleChange(ChangeEvent event) { |
45 processStalenessChange(cast(IObservable) event.getSource(), true); | 45 processStalenessChange(cast(IObservable) event.getSource(), true); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 private ChildListener childListener = new ChildListener(); | 49 private ChildListener childListener; |
50 | 50 |
51 /** | 51 /** |
52 * @param observables | 52 * @param observables |
53 * @param stalenessConsumer | 53 * @param stalenessConsumer |
54 */ | 54 */ |
55 public this(IObservable[] observables, | 55 public this(IObservable[] observables, |
56 IStalenessConsumer stalenessConsumer) { | 56 IStalenessConsumer stalenessConsumer) { |
57 childListener = new ChildListener(); | |
58 staleMap = new HashMap(); | |
57 this.stalenessConsumer = stalenessConsumer; | 59 this.stalenessConsumer = stalenessConsumer; |
58 for (int i = 0; i < observables.length; i++) { | 60 for (int i = 0; i < observables.length; i++) { |
59 IObservable observable = observables[i]; | 61 IObservable observable = observables[i]; |
60 doAddObservable(observable, false); | 62 doAddObservable(observable, false); |
61 } | 63 } |
66 * @param child | 68 * @param child |
67 * @param callback | 69 * @param callback |
68 */ | 70 */ |
69 public void processStalenessChange(IObservable child, bool callback) { | 71 public void processStalenessChange(IObservable child, bool callback) { |
70 bool oldStale = staleCount > 0; | 72 bool oldStale = staleCount > 0; |
71 IdentityWrapper wrappedChild = new IdentityWrapper(child); | 73 IdentityWrapper wrappedChild = new IdentityWrapper(cast(Object)child); |
72 bool oldChildStale = getOldChildStale(wrappedChild); | 74 bool oldChildStale = getOldChildStale(wrappedChild); |
73 bool newChildStale = child.isStale(); | 75 bool newChildStale = child.isStale(); |
74 if (oldChildStale !is newChildStale) { | 76 if (oldChildStale !is newChildStale) { |
75 if (oldChildStale) { | 77 if (oldChildStale) { |
76 staleCount--; | 78 staleCount--; |
111 /** | 113 /** |
112 * @param observable | 114 * @param observable |
113 */ | 115 */ |
114 public void removeObservable(IObservable observable) { | 116 public void removeObservable(IObservable observable) { |
115 bool oldStale = staleCount > 0; | 117 bool oldStale = staleCount > 0; |
116 IdentityWrapper wrappedChild = new IdentityWrapper(observable); | 118 IdentityWrapper wrappedChild = new IdentityWrapper(cast(Object)observable); |
117 bool oldChildStale = getOldChildStale(wrappedChild); | 119 bool oldChildStale = getOldChildStale(wrappedChild); |
118 if (oldChildStale) { | 120 if (oldChildStale) { |
119 staleCount--; | 121 staleCount--; |
120 } | 122 } |
121 staleMap.remove(wrappedChild); | 123 staleMap.remove(wrappedChild); |