Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.d @ 85:6be48cf9f95c
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:54:50 +0200 |
parents | 383ce7bd736b |
children | 9e0ab372d5d8 |
comparison
equal
deleted
inserted
replaced
84:fcf926c91ca4 | 85:6be48cf9f95c |
---|---|
122 private IObservableValue unmodifiableValidationStatus; | 122 private IObservableValue unmodifiableValidationStatus; |
123 private WritableList targets; | 123 private WritableList targets; |
124 private IObservableList unmodifiableTargets; | 124 private IObservableList unmodifiableTargets; |
125 private IObservableList models; | 125 private IObservableList models; |
126 | 126 |
127 IListChangeListener targetsListener = new class() IListChangeListener { | 127 IListChangeListener targetsListener; |
128 class TargetsListener : IListChangeListener { | |
128 public void handleListChange(ListChangeEvent event) { | 129 public void handleListChange(ListChangeEvent event) { |
129 event.diff.accept(new class() ListDiffVisitor { | 130 event.diff.accept(new class() ListDiffVisitor { |
130 public void handleAdd(int index, Object element) { | 131 public void handleAdd(int index, Object element) { |
131 (cast(IObservable) element) | 132 (cast(IObservable) element) |
132 .addChangeListener(dependencyListener); | 133 .addChangeListener(dependencyListener); |
138 } | 139 } |
139 }); | 140 }); |
140 } | 141 } |
141 }; | 142 }; |
142 | 143 |
143 private IChangeListener dependencyListener = new class() IChangeListener { | 144 private IChangeListener dependencyListener; |
145 class DependencyListener : IChangeListener { | |
144 public void handleChange(ChangeEvent event) { | 146 public void handleChange(ChangeEvent event) { |
145 revalidate(); | 147 revalidate(); |
146 } | 148 } |
147 }; | 149 }; |
148 | 150 |
158 * | 160 * |
159 * @param realm | 161 * @param realm |
160 * the realm on which validation takes place. | 162 * the realm on which validation takes place. |
161 */ | 163 */ |
162 public this(Realm realm) { | 164 public this(Realm realm) { |
165 targetsListener = new TargetsListener(); | |
166 dependencyListener = new DependencyListener(); | |
163 Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ | 167 Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$ |
164 this.realm = realm; | 168 this.realm = realm; |
165 | 169 |
166 validationStatus = new WritableValue(realm, ValidationStatus.ok(), | 170 validationStatus = new WritableValue(realm, cast(Object)ValidationStatus.ok(), |
167 IStatus.classinfo); | 171 typeid(IStatus)); |
168 | 172 |
169 targets = new WritableList(realm, new ArrayList(), IObservable.classinfo); | 173 targets = new WritableList(realm, new ArrayList(), typeid(IObservable)); |
170 targets.addListChangeListener(targetsListener); | 174 targets.addListChangeListener(targetsListener); |
171 unmodifiableTargets = Observables.unmodifiableObservableList(targets); | 175 unmodifiableTargets = Observables.unmodifiableObservableList(targets); |
172 | 176 |
173 models = Observables.emptyObservableList(realm); | 177 models = Observables.emptyObservableList(realm); |
174 } | 178 } |
175 | 179 |
176 private void checkObservable(IObservable target) { | 180 private void checkObservable(IObservable target) { |
177 Assert.isNotNull(target, "Target observable cannot be null"); //$NON-NLS-1$ | 181 Assert.isNotNull(cast(Object)target, "Target observable cannot be null"); //$NON-NLS-1$ |
178 Assert | 182 Assert |
179 .isTrue(realm.equals(target.getRealm()), | 183 .isTrue(cast(bool)realm.opEquals(target.getRealm()), |
180 "Target observable must be in the same realm as MultiValidator"); //$NON-NLS-1$ | 184 "Target observable must be in the same realm as MultiValidator"); //$NON-NLS-1$ |
181 } | 185 } |
182 | 186 |
183 /** | 187 /** |
184 * Returns an {@link IObservableValue} whose value is always the current | 188 * Returns an {@link IObservableValue} whose value is always the current |
203 public void run() { | 207 public void run() { |
204 try { | 208 try { |
205 IStatus status = validate(); | 209 IStatus status = validate(); |
206 if (status is null) | 210 if (status is null) |
207 status = ValidationStatus.ok(); | 211 status = ValidationStatus.ok(); |
208 validationStatus.setValue(status); | 212 validationStatus.setValue(cast(Object)status); |
209 } catch (RuntimeException e) { | 213 } catch (RuntimeException e) { |
210 // Usually an NPE as dependencies are | 214 // Usually an NPE as dependencies are |
211 // init'ed | 215 // init'ed |
212 validationStatus.setValue(ValidationStatus.error(e | 216 validationStatus.setValue(cast(Object)ValidationStatus.error(e |
213 .getMessage(), e)); | 217 .getMessage(), e)); |
214 } | 218 } |
215 } | 219 } |
216 }, null, null); | 220 }, null, null); |
217 ObservableTracker.runAndIgnore(new class() Runnable { | 221 ObservableTracker.runAndIgnore(new class() Runnable { |