Mercurial > projects > dwt2
comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ValidatedObservableList.d @ 85:6be48cf9f95c
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:54:50 +0200 |
parents | 0a55d2d5a946 |
children |
comparison
equal
deleted
inserted
replaced
84:fcf926c91ca4 | 85:6be48cf9f95c |
---|---|
51 // True when validaton status changes from invalid to valid. | 51 // True when validaton status changes from invalid to valid. |
52 private bool computeNextDiff = false; | 52 private bool computeNextDiff = false; |
53 | 53 |
54 private bool updatingTarget = false; | 54 private bool updatingTarget = false; |
55 | 55 |
56 private IListChangeListener targetChangeListener = new class() IListChangeListener { | 56 private IListChangeListener targetChangeListener; |
57 class TargetChangeListener : IListChangeListener { | |
57 public void handleListChange(ListChangeEvent event) { | 58 public void handleListChange(ListChangeEvent event) { |
58 if (updatingTarget) | 59 if (updatingTarget) |
59 return; | 60 return; |
60 IStatus status = cast(IStatus) validationStatus.getValue(); | 61 IStatus status = cast(IStatus) validationStatus.getValue(); |
61 if (isValid(status)) { | 62 if (isValid(status)) { |
81 | 82 |
82 private static bool isValid(IStatus status) { | 83 private static bool isValid(IStatus status) { |
83 return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); | 84 return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); |
84 } | 85 } |
85 | 86 |
86 private IStaleListener targetStaleListener = new class() IStaleListener { | 87 private IStaleListener targetStaleListener; |
88 class TargetStaleListener : IStaleListener { | |
87 public void handleStale(StaleEvent staleEvent) { | 89 public void handleStale(StaleEvent staleEvent) { |
88 fireStale(); | 90 fireStale(); |
89 } | 91 } |
90 }; | 92 }; |
91 | 93 |
92 private IValueChangeListener validationStatusChangeListener = new class() IValueChangeListener { | 94 private IValueChangeListener validationStatusChangeListener; |
95 class ValidationStatusChangeListener : IValueChangeListener { | |
93 public void handleValueChange(ValueChangeEvent event) { | 96 public void handleValueChange(ValueChangeEvent event) { |
94 IStatus oldStatus = cast(IStatus) event.diff.getOldValue(); | 97 IStatus oldStatus = cast(IStatus) event.diff.getOldValue(); |
95 IStatus newStatus = cast(IStatus) event.diff.getNewValue(); | 98 IStatus newStatus = cast(IStatus) event.diff.getNewValue(); |
96 if (stale && !isValid(oldStatus) && isValid(newStatus)) { | 99 if (stale && !isValid(oldStatus) && isValid(newStatus)) { |
97 // this.stale means we are out of sync with target, | 100 // this.stale means we are out of sync with target, |
110 * @param target | 113 * @param target |
111 * @param validationStatus | 114 * @param validationStatus |
112 */ | 115 */ |
113 public this(IObservableList target, | 116 public this(IObservableList target, |
114 IObservableValue validationStatus) { | 117 IObservableValue validationStatus) { |
118 targetStaleListener = new TargetStaleListener(); | |
119 targetChangeListener = new TargetChangeListener(); | |
120 validationStatusChangeListener = new ValidationStatusChangeListener(); | |
115 super(target.getRealm(), new ArrayList(target), target.getElementType()); | 121 super(target.getRealm(), new ArrayList(target), target.getElementType()); |
116 Assert.isNotNull(validationStatus, | 122 Assert.isNotNull(cast(Object)validationStatus, |
117 "Validation status observable cannot be null"); //$NON-NLS-1$ | 123 "Validation status observable cannot be null"); //$NON-NLS-1$ |
118 Assert | 124 Assert |
119 .isTrue(target.getRealm().equals(validationStatus.getRealm()), | 125 .isTrue(cast(bool)target.getRealm().opEquals(validationStatus.getRealm()), |
120 "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ | 126 "Target and validation status observables must be on the same realm"); //$NON-NLS-1$ |
121 this.target = target; | 127 this.target = target; |
122 this.validationStatus = validationStatus; | 128 this.validationStatus = validationStatus; |
123 target.addListChangeListener(targetChangeListener); | 129 target.addListChangeListener(targetChangeListener); |
124 target.addStaleListener(targetStaleListener); | 130 target.addStaleListener(targetStaleListener); |
250 final ListIterator wrappedIterator = wrappedList.listIterator(index); | 256 final ListIterator wrappedIterator = wrappedList.listIterator(index); |
251 return new class() ListIterator { | 257 return new class() ListIterator { |
252 int lastIndex = -1; | 258 int lastIndex = -1; |
253 Object last = null; | 259 Object last = null; |
254 | 260 |
261 public void add(String o) { | |
262 add(stringcast(o)); | |
263 } | |
255 public void add(Object o) { | 264 public void add(Object o) { |
256 wrappedIterator.add(o); | 265 wrappedIterator.add(o); |
257 lastIndex = previousIndex(); | 266 lastIndex = previousIndex(); |
258 ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( | 267 ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |
259 lastIndex, true, o)); | 268 lastIndex, true, o)); |
313 public Object move(int oldIndex, int newIndex) { | 322 public Object move(int oldIndex, int newIndex) { |
314 checkRealm(); | 323 checkRealm(); |
315 int size = wrappedList.size(); | 324 int size = wrappedList.size(); |
316 if (oldIndex >= size) | 325 if (oldIndex >= size) |
317 throw new IndexOutOfBoundsException( | 326 throw new IndexOutOfBoundsException( |
318 "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ | 327 Format("oldIndex: {}, size:{}", oldIndex, size)); //$NON-NLS-1$ //$NON-NLS-2$ |
319 if (newIndex >= size) | 328 if (newIndex >= size) |
320 throw new IndexOutOfBoundsException( | 329 throw new IndexOutOfBoundsException( |
321 "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ | 330 Format("newIndex: {}, size:{}", newIndex, size)); //$NON-NLS-1$ //$NON-NLS-2$ |
322 if (oldIndex is newIndex) | 331 if (oldIndex is newIndex) |
323 return wrappedList.get(oldIndex); | 332 return wrappedList.get(oldIndex); |
324 Object element = wrappedList.remove(oldIndex); | 333 Object element = wrappedList.remove(oldIndex); |
325 wrappedList.add(newIndex, element); | 334 wrappedList.add(newIndex, element); |
326 ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( | 335 ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry( |