comparison org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.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
11 * Brad Reynolds - bug 170848 11 * Brad Reynolds - bug 170848
12 * Matthew Hall - bug 180746, bug 207844 12 * Matthew Hall - bug 180746, bug 207844
13 * Michael Krauter, bug 180223 13 * Michael Krauter, bug 180223
14 *******************************************************************************/ 14 *******************************************************************************/
15 module org.eclipse.jface.databinding.swt.SWTObservables; 15 module org.eclipse.jface.databinding.swt.SWTObservables;
16 import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16 17
17 import java.lang.all; 18 import java.lang.all;
18 19
19 import java.util.ArrayList; 20 import java.util.ArrayList;
20 import java.util.Iterator; 21 import java.util.Iterator;
22 static import java.util.List;
21 23
22 import org.eclipse.core.databinding.observable.Realm; 24 import org.eclipse.core.databinding.observable.Realm;
23 import org.eclipse.core.databinding.observable.list.IObservableList; 25 import org.eclipse.core.databinding.observable.list.IObservableList;
24 import org.eclipse.jface.internal.databinding.internal.swt.LinkObservableValue; 26 import org.eclipse.jface.internal.databinding.internal.swt.LinkObservableValue;
25 import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; 27 import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue;
64 * @since 1.1 66 * @since 1.1
65 * 67 *
66 */ 68 */
67 public class SWTObservables { 69 public class SWTObservables {
68 70
69 private static java.util.List realms = new ArrayList(); 71 private static java.util.List.List realms;
72 static this(){
73 realms = new ArrayList();
74 }
70 75
71 /** 76 /**
72 * Returns the realm representing the UI thread for the given display. 77 * Returns the realm representing the UI thread for the given display.
73 * 78 *
74 * @param display 79 * @param display
172 return new ScaleObservableValue(cast(Scale) control, 177 return new ScaleObservableValue(cast(Scale) control,
173 SWTProperties.SELECTION); 178 SWTProperties.SELECTION);
174 } 179 }
175 180
176 throw new IllegalArgumentException( 181 throw new IllegalArgumentException(
177 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 182 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
178 } 183 }
179 184
180 /** 185 /**
181 * Returns an observable observing the minimum attribute of the provided 186 * Returns an observable observing the minimum attribute of the provided
182 * <code>control</code>. The supported types are: 187 * <code>control</code>. The supported types are:
197 } else if (null !is cast(Scale)control) { 202 } else if (null !is cast(Scale)control) {
198 return new ScaleObservableValue(cast(Scale) control, SWTProperties.MIN); 203 return new ScaleObservableValue(cast(Scale) control, SWTProperties.MIN);
199 } 204 }
200 205
201 throw new IllegalArgumentException( 206 throw new IllegalArgumentException(
202 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 207 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
203 } 208 }
204 209
205 /** 210 /**
206 * Returns an observable observing the maximum attribute of the provided 211 * Returns an observable observing the maximum attribute of the provided
207 * <code>control</code>. The supported types are: 212 * <code>control</code>. The supported types are:
222 } else if (null !is cast(Scale)control) { 227 } else if (null !is cast(Scale)control) {
223 return new ScaleObservableValue(cast(Scale) control, SWTProperties.MAX); 228 return new ScaleObservableValue(cast(Scale) control, SWTProperties.MAX);
224 } 229 }
225 230
226 throw new IllegalArgumentException( 231 throw new IllegalArgumentException(
227 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 232 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
228 } 233 }
229 234
230 /** 235 /**
231 * Returns an observable observing the text attribute of the provided 236 * Returns an observable observing the text attribute of the provided
232 * <code>control</code>. The supported types are: 237 * <code>control</code>. The supported types are:
245 if (null !is cast(Text)control) { 250 if (null !is cast(Text)control) {
246 return new TextObservableValue(cast(Text) control, event); 251 return new TextObservableValue(cast(Text) control, event);
247 } 252 }
248 253
249 throw new IllegalArgumentException( 254 throw new IllegalArgumentException(
250 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 255 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
251 } 256 }
252 257
253 /** 258 /**
254 * Returns an observable observing the text attribute of the provided 259 * Returns an observable observing the text attribute of the provided
255 * <code>control</code>. The supported types are: 260 * <code>control</code>. The supported types are:
282 } else if (null !is cast(Shell)control) { 287 } else if (null !is cast(Shell)control) {
283 return new ShellObservableValue(cast(Shell) control); 288 return new ShellObservableValue(cast(Shell) control);
284 } 289 }
285 290
286 throw new IllegalArgumentException( 291 throw new IllegalArgumentException(
287 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 292 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
288 } 293 }
289 294
290 /** 295 /**
291 * Returns an observable observing the items attribute of the provided 296 * Returns an observable observing the items attribute of the provided
292 * <code>control</code>. The supported types are: 297 * <code>control</code>. The supported types are:
309 } else if (null !is cast(List)control) { 314 } else if (null !is cast(List)control) {
310 return new ListObservableList(cast(List) control); 315 return new ListObservableList(cast(List) control);
311 } 316 }
312 317
313 throw new IllegalArgumentException( 318 throw new IllegalArgumentException(
314 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 319 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
315 } 320 }
316 321
317 /** 322 /**
318 * Returns an observable observing the single selection index attribute of 323 * Returns an observable observing the single selection index attribute of
319 * the provided <code>control</code>. The supported types are: 324 * the provided <code>control</code>. The supported types are:
340 } else if (null !is cast(List)control) { 345 } else if (null !is cast(List)control) {
341 return new ListSingleSelectionObservableValue(cast(List) control); 346 return new ListSingleSelectionObservableValue(cast(List) control);
342 } 347 }
343 348
344 throw new IllegalArgumentException( 349 throw new IllegalArgumentException(
345 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 350 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
346 } 351 }
347 352
348 /** 353 /**
349 * @param control 354 * @param control
350 * @return an observable value tracking the foreground color of the given 355 * @return an observable value tracking the foreground color of the given
387 if (null !is cast(Text)control) { 392 if (null !is cast(Text)control) {
388 return new TextEditableObservableValue(cast(Text) control); 393 return new TextEditableObservableValue(cast(Text) control);
389 } 394 }
390 395
391 throw new IllegalArgumentException( 396 throw new IllegalArgumentException(
392 "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ 397 "Widget [" ~ Class.fromObject(control).getName() ~ "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$
393 } 398 }
394 399
395 private static class DisplayRealm : Realm { 400 private static class DisplayRealm : Realm {
396 private Display display; 401 private Display display;
397 402
418 /* 423 /*
419 * (non-Javadoc) 424 * (non-Javadoc)
420 * 425 *
421 * @see java.lang.Object#hashCode() 426 * @see java.lang.Object#hashCode()
422 */ 427 */
423 public int hashCode() { 428 public override hash_t toHash() {
424 return (display is null) ? 0 : display.hashCode(); 429 return (display is null) ? 0 : display.toHash();
425 } 430 }
426 431
427 /* 432 /*
428 * (non-Javadoc) 433 * (non-Javadoc)
429 * 434 *
430 * @see java.lang.Object#equals(java.lang.Object) 435 * @see java.lang.Object#equals(java.lang.Object)
431 */ 436 */
432 public bool equals(Object obj) { 437 public override equals_t opEquals(Object obj) {
433 if (this is obj) 438 if (this is obj)
434 return true; 439 return true;
435 if (obj is null) 440 if (obj is null)
436 return false; 441 return false;
437 if (getClass() !is obj.getClass()) 442 if (Class.fromObject(this) !is Class.fromObject(obj))
438 return false; 443 return false;
439 final DisplayRealm other = cast(DisplayRealm) obj; 444 final DisplayRealm other = cast(DisplayRealm) obj;
440 if (display is null) { 445 if (display is null) {
441 if (other.display !is null) 446 if (other.display !is null)
442 return false; 447 return false;
443 } else if (!display.equals(other.display)) 448 } else if (!display.opEquals(other.display))
444 return false; 449 return false;
445 return true; 450 return true;
446 } 451 }
447 } 452 }
448 } 453 }