001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Brad Reynolds - bug 116920, 159768
011: *******************************************************************************/package org.eclipse.jface.tests.databinding.scenarios;
012:
013: import java.text.ParseException;
014: import java.util.Date;
015: import java.util.Locale;
016:
017: import org.eclipse.core.databinding.AggregateValidationStatus;
018: import org.eclipse.core.databinding.Binding;
019: import org.eclipse.core.databinding.UpdateValueStrategy;
020: import org.eclipse.core.databinding.beans.BeansObservables;
021: import org.eclipse.core.databinding.conversion.Converter;
022: import org.eclipse.core.databinding.conversion.IConverter;
023: import org.eclipse.core.databinding.conversion.NumberToStringConverter;
024: import org.eclipse.core.databinding.conversion.StringToNumberConverter;
025: import org.eclipse.core.databinding.observable.ChangeEvent;
026: import org.eclipse.core.databinding.observable.IChangeListener;
027: import org.eclipse.core.databinding.observable.value.IObservableValue;
028: import org.eclipse.core.databinding.validation.IValidator;
029: import org.eclipse.core.databinding.validation.ValidationStatus;
030: import org.eclipse.core.internal.databinding.conversion.IdentityConverter;
031: import org.eclipse.core.runtime.IStatus;
032: import org.eclipse.core.runtime.Status;
033: import org.eclipse.jface.databinding.swt.SWTObservables;
034: import org.eclipse.jface.examples.databinding.model.Account;
035: import org.eclipse.jface.examples.databinding.model.Adventure;
036: import org.eclipse.jface.examples.databinding.model.Cart;
037: import org.eclipse.jface.examples.databinding.model.SampleData;
038: import org.eclipse.swt.SWT;
039: import org.eclipse.swt.events.FocusEvent;
040: import org.eclipse.swt.events.FocusListener;
041: import org.eclipse.swt.widgets.Button;
042: import org.eclipse.swt.widgets.Event;
043: import org.eclipse.swt.widgets.Spinner;
044: import org.eclipse.swt.widgets.Text;
045:
046: import com.ibm.icu.text.NumberFormat;
047:
048: /**
049: * To run the tests in this class, right-click and select "Run As JUnit Plug-in
050: * Test". This will also start an Eclipse instance. To clean up the launch
051: * configuration, open up its "Main" tab and select "[No Application] - Headless
052: * Mode" as the application to run.
053: */
054:
055: public class PropertyScenarios extends ScenariosTestCase {
056:
057: private Adventure adventure;
058:
059: protected void setUp() throws Exception {
060: super .setUp();
061: // do any setup work here
062: adventure = SampleData.WINTER_HOLIDAY;
063: }
064:
065: protected void tearDown() throws Exception {
066: // do any teardown work here
067: super .tearDown();
068: }
069:
070: public void testEnterText() {
071: // just to make sure enterText() generates a FocusOut event.
072: Text text = new Text(getComposite(), SWT.BORDER);
073: final boolean[] focusLostHolder = { false };
074: text.addFocusListener(new FocusListener() {
075:
076: public void focusGained(FocusEvent e) {
077: // only interested in focus lost events
078: }
079:
080: public void focusLost(FocusEvent e) {
081: focusLostHolder[0] = true;
082: }
083: });
084: enterText(text, "hallo");
085: assertTrue(focusLostHolder[0]);
086: }
087:
088: public void testScenario01() {
089: Text text = new Text(getComposite(), SWT.BORDER);
090: getDbc().bindValue(
091: SWTObservables.observeText(text, SWT.Modify),
092: BeansObservables.observeValue(adventure, "name"), null,
093: null);
094:
095: // getDbc().bind(text, new Property(adventure, "name"), null);
096: // uncomment the following line to see what's happening
097: // spinEventLoop(1);
098: assertEquals(adventure.getName(), text.getText());
099: enterText(text, "foobar");
100: // uncomment the following line to see what's happening
101: // spinEventLoop(1);
102: assertEquals("foobar", adventure.getName());
103: adventure.setName("barfoo");
104: // uncomment the following line to see what's happening
105: // spinEventLoop(1);
106: assertEquals("barfoo", text.getText());
107: }
108:
109: public void testScenario02() {
110: // Binding the name property of an Adventure object to the contents of
111: // Text controls, no conversion, no validation. The Text widget editable
112: // is set to false.by the developer (can not change the name)
113: Text text = new Text(getComposite(), SWT.READ_ONLY);
114:
115: getDbc().bindValue(SWTObservables.observeText(text, SWT.None),
116: BeansObservables.observeValue(adventure, "name"), null,
117: null);
118: assertEquals(adventure.getName(), text.getText());
119: }
120:
121: public void testScenario03() {
122: // Binding of a read-only property of an Adventure object to the
123: // contents of Text controls, no conversion, no validation. Text control
124: // is not editable as a side effect of binding to a read-only property..
125: Cart cart = SampleData.CART;
126: cart.setAdventureDays(42);
127: // bind to the lodgingDays feature, which is read-only and always one
128: // less than the number of adventure days.
129: Text text = new Text(getComposite(), SWT.BORDER);
130:
131: System.out
132: .println("Expecting message about not being able to attach a listener");
133: getDbc().bindValue(
134: SWTObservables.observeText(text, SWT.Modify),
135: BeansObservables.observeValue(cart, "lodgingDays"),
136: null, null);
137:
138: assertEquals(new Integer(cart.getLodgingDays()).toString(),
139: text.getText());
140: }
141:
142: public void testScenario04() {
143: // Binding a nested property of an Adventure object to the content of a
144: // Text control, no conversion, no validation.
145: Text text = new Text(getComposite(), SWT.BORDER);
146: // TODO Scenario needs to be more specific - I'm binding to the default
147: // lodging's description of an adventure. What do we expect to happen
148: // when the default lodging changes? If we expect no change, then this
149: // scenario does not introduce anything new. If we expect the binding to
150: // be to the new default lodging's description, shouldn't we move this
151: // scenario to the master/detail section? I'm assuming the latter for
152: // now.
153:
154: IObservableValue defaultLodging = BeansObservables
155: .observeDetailValue(realm, BeansObservables
156: .observeValue(adventure, "defaultLodging"),
157: "description", String.class);
158:
159: getDbc().bindValue(
160: SWTObservables.observeText(text, SWT.Modify),
161: defaultLodging, null, null);
162:
163: // test changing the description
164: assertEquals(adventure.getDefaultLodging().getDescription(),
165: text.getText());
166: enterText(text, "foobar");
167: assertEquals("foobar", adventure.getDefaultLodging()
168: .getDescription());
169: adventure.getDefaultLodging().setDescription("barfoo");
170: assertEquals(adventure.getDefaultLodging().getDescription(),
171: text.getText());
172:
173: // test changing the default lodging
174: adventure.setDefaultLodging(SampleData.CAMP_GROUND);
175: assertEquals(adventure.getDefaultLodging().getDescription(),
176: text.getText());
177: adventure.getDefaultLodging().setDescription("barfo");
178: assertEquals(adventure.getDefaultLodging().getDescription(),
179: text.getText());
180:
181: adventure.setDefaultLodging(null);
182: assertEquals("", text.getText());
183:
184: adventure.setDefaultLodging(SampleData.FIVE_STAR_HOTEL);
185: assertEquals(adventure.getDefaultLodging().getDescription(),
186: text.getText());
187: adventure.getDefaultLodging().setDescription("barf");
188: assertEquals(adventure.getDefaultLodging().getDescription(),
189: text.getText());
190:
191: }
192:
193: public void testScenario05() {
194: // Binding the name property of an Adventure object to the contents of
195: // Text controls where conversion occurs � the model data is held all
196: // in
197: // uppercase and displayed in lowercase with the first letter
198: // capitalized.
199: Text text = new Text(getComposite(), SWT.BORDER);
200: adventure.setName("UPPERCASE");
201:
202: IConverter converter1 = new IConverter() {
203: public Object getFromType() {
204: return String.class;
205: }
206:
207: public Object getToType() {
208: return String.class;
209: }
210:
211: public Object convert(Object toObject) {
212: String modelValue = (String) toObject;
213: if (modelValue == null || modelValue.equals("")) {
214: return modelValue;
215: }
216: String firstChar = modelValue.substring(0, 1);
217: String remainingChars = modelValue.substring(1);
218: return firstChar.toUpperCase()
219: + remainingChars.toLowerCase();
220: }
221: };
222: IConverter converter2 = new IConverter() {
223: public Object getFromType() {
224: return String.class;
225: }
226:
227: public Object getToType() {
228: return String.class;
229: }
230:
231: public Object convert(Object fromObject) {
232: return ((String) fromObject).toUpperCase();
233: }
234: };
235:
236: getDbc().bindValue(
237: SWTObservables.observeText(text, SWT.Modify),
238: BeansObservables.observeValue(adventure, "name"),
239: new UpdateValueStrategy().setConverter(converter2),
240: new UpdateValueStrategy().setConverter(converter1));
241:
242: // spinEventLoop(1);
243: assertEquals("Uppercase", text.getText());
244: enterText(text, "lowercase");
245: // spinEventLoop(1);
246: // TODO If we wanted to "canonicalize" the value in the text field, how
247: // could we do that?
248: assertEquals("LOWERCASE", adventure.getName());
249: }
250:
251: public void testScenario06() {
252: // Binding the name property of an Adventure object to the contents of
253: // Text controls where validation occurs and the name cannot be longer
254: // than 15 characters and cannot contain spaces
255: Text text = new Text(getComposite(), SWT.BORDER);
256: final String noSpacesMessage = "Name must not contain spaces.";
257: final String max15CharactersMessage = "Maximum length for name is 15 characters.";
258: adventure.setName("ValidValue");
259:
260: IValidator validator = new IValidator() {
261: public IStatus validate(Object value) {
262: String stringValue = (String) value;
263: if (stringValue.length() > 15) {
264: return ValidationStatus
265: .error(max15CharactersMessage);
266: } else if (stringValue.indexOf(' ') != -1) {
267: return ValidationStatus.cancel(noSpacesMessage);
268: } else {
269: return Status.OK_STATUS;
270: }
271: }
272: };
273:
274: // BindSpec bindSpec = new DefaultBindSpec().setModelToTargetConverter(new IdentityConverter(String.class))
275: // .setTargetToModelConverter(new IdentityConverter(String.class))
276: // .addTargetValidator(BindingEvent.PIPELINE_VALUE_CHANGING, validator);
277:
278: Binding binding = getDbc().bindValue(
279: SWTObservables.observeText(text, SWT.Modify),
280: BeansObservables.observeValue(adventure, "name"),
281: new UpdateValueStrategy().setConverter(
282: new IdentityConverter(String.class))
283: .setAfterGetValidator(validator),
284: new UpdateValueStrategy()
285: .setConverter(new IdentityConverter(
286: String.class)));
287:
288: // no validation message
289: assertTrue(((IStatus) binding.getValidationStatus().getValue())
290: .isOK());
291: enterText(text, "Invalid Value");
292: assertEquals(noSpacesMessage, ((IStatus) binding
293: .getValidationStatus().getValue()).getMessage());
294: assertEquals("ValidValue", adventure.getName());
295: text.setText("InvalidValueBecauseTooLong");
296: assertEquals(max15CharactersMessage, ((IStatus) binding
297: .getValidationStatus().getValue()).getMessage());
298: assertEquals("ValidValue", adventure.getName());
299: enterText(text, "anothervalid");
300: assertTrue(((IStatus) binding.getValidationStatus().getValue())
301: .isOK());
302: assertEquals("anothervalid", adventure.getName());
303: }
304:
305: public void testScenario07() {
306: // Binding the price property of an Adventure to a Text control. Price
307: // is a double and Text accepts String so conversion will have to occur.
308: // Validation ensure that the value is positive
309: Text text = new Text(getComposite(), SWT.BORDER);
310: adventure.setPrice(5.0);
311: final String cannotBeNegativeMessage = "Price cannot be negative.";
312: final String mustBeCurrencyMessage = "Price must be a currency.";
313:
314: IValidator validator = new IValidator() {
315: public IStatus validate(Object value) {
316: String stringValue = (String) value;
317: try {
318: double doubleValue = new Double(stringValue)
319: .doubleValue();
320: if (doubleValue < 0.0) {
321: return ValidationStatus
322: .error(cannotBeNegativeMessage);
323: }
324: return Status.OK_STATUS;
325: } catch (NumberFormatException ex) {
326: return ValidationStatus
327: .error(mustBeCurrencyMessage);
328: }
329: }
330: };
331:
332: //Create a number formatter that will display one decimal position.
333: NumberFormat numberFormat = NumberFormat.getInstance();
334: numberFormat.setMinimumFractionDigits(1);
335:
336: IConverter targetToModelConverter = StringToNumberConverter
337: .toDouble(numberFormat, true);
338: IConverter modelToTargetConverter = NumberToStringConverter
339: .fromDouble(numberFormat, true);
340:
341: getDbc()
342: .bindValue(
343: SWTObservables.observeText(text, SWT.Modify),
344: BeansObservables.observeValue(adventure,
345: "price"),
346: new UpdateValueStrategy().setAfterGetValidator(
347: validator).setConverter(
348: targetToModelConverter),
349: new UpdateValueStrategy()
350: .setConverter(modelToTargetConverter));
351:
352: String expected = numberFormat.format(adventure.getPrice());
353: assertEquals(expected, text.getText());
354: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
355: getDbc().getBindings()).isOK());
356:
357: String toEnter = numberFormat.format(0.65);
358: enterText(text, toEnter);
359: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
360: getDbc().getBindings()).isOK());
361: assertEquals(0.65, adventure.getPrice(), 0.0001);
362:
363: adventure.setPrice(42.24);
364: expected = numberFormat.format(adventure.getPrice());
365: assertEquals(expected, text.getText());
366: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
367: getDbc().getBindings()).isOK());
368:
369: enterText(text, "jygt");
370: assertEquals(mustBeCurrencyMessage, AggregateValidationStatus
371: .getStatusMaxSeverity(getDbc().getBindings())
372: .getMessage());
373:
374: toEnter = numberFormat.format(-23.9);
375: enterText(text, toEnter);
376: assertEquals(cannotBeNegativeMessage, AggregateValidationStatus
377: .getStatusMaxSeverity(getDbc().getBindings())
378: .getMessage());
379: assertEquals(42.24, adventure.getPrice(), 0.0001);
380:
381: adventure.setPrice(0.0);
382: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
383: getDbc().getBindings()).isOK());
384: }
385:
386: public void testScenario08() {
387: // Binding the price property of an Adventure to a Text control but with
388: // custom conversion � the double will be validated to only have two
389: // decimal places and displayed with a leading currency symbol, and can
390: // be entered with or without the currency symbol.
391: Text text = new Text(getComposite(), SWT.BORDER);
392: adventure.setPrice(5.0);
393: final String cannotBeNegativeMessage = "Price cannot be negative.";
394: final String mustBeCurrencyMessage = "Price must be a currency.";
395: final NumberFormat currencyFormat = NumberFormat
396: .getCurrencyInstance(Locale.CANADA);
397:
398: IConverter toCurrency = new Converter(double.class,
399: String.class) {
400: public Object convert(Object toObject) {
401: return currencyFormat.format(((Double) toObject)
402: .doubleValue());
403: }
404: };
405:
406: IConverter toDouble = new Converter(String.class, double.class) {
407: public Object convert(Object fromObject) {
408: try {
409: return new Double(currencyFormat.parse(
410: (String) fromObject).doubleValue());
411: } catch (ParseException e) {
412: // TODO throw something like
413: // IllegalConversionException?
414: return new Double(0);
415: }
416: }
417: };
418:
419: IValidator validator = new IValidator() {
420: public IStatus validate(Object value) {
421: String stringValue = (String) value;
422: try {
423: double doubleValue = currencyFormat.parse(
424: stringValue).doubleValue();
425: if (doubleValue < 0.0) {
426: return ValidationStatus
427: .error(cannotBeNegativeMessage);
428: }
429: return Status.OK_STATUS;
430: } catch (ParseException e) {
431: return ValidationStatus
432: .error(mustBeCurrencyMessage);
433: }
434: }
435: };
436:
437: getDbc().bindValue(
438: SWTObservables.observeText(text, SWT.Modify),
439: BeansObservables.observeValue(adventure, "price"),
440: new UpdateValueStrategy().setConverter(toDouble)
441: .setAfterGetValidator(validator),
442: new UpdateValueStrategy().setConverter(toCurrency));
443:
444: String expected = currencyFormat.format(5);
445: assertEquals(expected, text.getText());
446: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
447: getDbc().getBindings()).isOK());
448:
449: String toEnter = currencyFormat.format(0.65);
450: enterText(text, toEnter);
451: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
452: getDbc().getBindings()).isOK());
453: assertEquals(0.65, adventure.getPrice(), 0.0001);
454:
455: adventure.setPrice(42.24);
456: expected = currencyFormat.format(adventure.getPrice());
457: assertEquals(expected, text.getText());
458:
459: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
460: getDbc().getBindings()).isOK());
461: enterText(text, "jygt");
462: assertEquals(mustBeCurrencyMessage, AggregateValidationStatus
463: .getStatusMaxSeverity(getDbc().getBindings())
464: .getMessage());
465:
466: toEnter = currencyFormat.format(-23.9);
467: enterText(text, toEnter);
468:
469: assertEquals(cannotBeNegativeMessage, AggregateValidationStatus
470: .getStatusMaxSeverity(getDbc().getBindings())
471: .getMessage());
472: assertEquals(42.24, adventure.getPrice(), 0.0001);
473: adventure.setPrice(0.0);
474: assertTrue(AggregateValidationStatus.getStatusMaxSeverity(
475: getDbc().getBindings()).isOK());
476: }
477:
478: public void testScenario09() {
479: // Binding a boolean property to a CheckBox. Adventure will have a
480: // Boolean property �petsAllowed�
481: Button checkbox = new Button(getComposite(), SWT.CHECK);
482: // checkbox.setText("Pets allowed");
483: // checkbox.setLayoutData(new GridData(SWT.LEFT,SWT.TOP, false,false));
484: adventure.setPetsAllowed(true);
485:
486: getDbc()
487: .bindValue(
488: SWTObservables.observeSelection(checkbox),
489: BeansObservables.observeValue(adventure,
490: "petsAllowed"), null, null);
491:
492: assertEquals(true, checkbox.getSelection());
493: setButtonSelectionWithEvents(checkbox, false);
494: assertEquals(false, adventure.isPetsAllowed());
495: adventure.setPetsAllowed(true);
496: assertEquals(true, checkbox.getSelection());
497: }
498:
499: public void testScenario10() {
500: // Binding a Transportation departure time to a Text control that
501: // formats and validates the time to and from a String. There are
502: // property bindings that bind elements of the GUI to elements to GUI
503: // and also elements of the domain to elements of the domain
504: // TODO fail("not implemented");
505: }
506:
507: public void testScenario11() {
508: // Binding the max value of a spinner to another spinner.
509: Spinner spinner1 = new Spinner(getComposite(), SWT.NONE);
510: spinner1.setSelection(10);
511: spinner1.setMinimum(1);
512: spinner1.setMaximum(100);
513: Spinner spinner2 = new Spinner(getComposite(), SWT.NONE);
514: spinner2.setMaximum(1);
515:
516: getDbc().bindValue(SWTObservables.observeSelection(spinner1),
517: SWTObservables.observeMax(spinner2), null, null);
518:
519: assertEquals(1, spinner1.getSelection());
520: spinner1.setSelection(10);
521: spinner1.notifyListeners(SWT.Modify, new Event());
522: assertEquals(10, spinner2.getMaximum());
523: }
524:
525: public void testScenario12() {
526: // Binding the enabled state of several Text controls to a check box.
527: // There will be two check boxes, so as each is enabled/disabled the
528: // other one follows as do the states of the Text controls.
529: Button checkbox1 = new Button(getComposite(), SWT.CHECK);
530: checkbox1.setSelection(false);
531: Button checkbox2 = new Button(getComposite(), SWT.CHECK);
532: checkbox2.setSelection(false);
533: Text text1 = new Text(getComposite(), SWT.NONE);
534: Text text2 = new Text(getComposite(), SWT.NONE);
535:
536: IObservableValue checkbox1Selected = SWTObservables
537: .observeSelection(checkbox1);
538: IObservableValue checkbox2Selected = SWTObservables
539: .observeSelection(checkbox2);
540:
541: // bind the two checkboxes so that if one is checked, the other is not
542: // and vice versa.
543: Converter negatingConverter = new Converter(boolean.class,
544: boolean.class) {
545: private Boolean negated(Boolean booleanObject) {
546: return new Boolean(!booleanObject.booleanValue());
547: }
548:
549: public Object convert(Object targetObject) {
550: return negated((Boolean) targetObject);
551: }
552: };
553:
554: getDbc().bindValue(
555: checkbox1Selected,
556: checkbox2Selected,
557: new UpdateValueStrategy()
558: .setConverter(negatingConverter),
559: new UpdateValueStrategy()
560: .setConverter(negatingConverter));
561:
562: // bind the enabled state of the two text widgets to one of the
563: // checkboxes each.
564:
565: getDbc().bindValue(SWTObservables.observeEnabled(text1),
566: checkbox1Selected, null, null);
567: getDbc().bindValue(SWTObservables.observeEnabled(text2),
568: checkbox2Selected, null, null);
569:
570: assertEquals(true, text1.getEnabled());
571: assertEquals(false, text2.getEnabled());
572: assertEquals(true, checkbox1.getSelection());
573: setButtonSelectionWithEvents(checkbox1, false);
574: assertEquals(false, text1.getEnabled());
575: assertEquals(true, text2.getEnabled());
576: assertEquals(true, checkbox2.getSelection());
577: setButtonSelectionWithEvents(checkbox2, false);
578: assertEquals(true, text1.getEnabled());
579: assertEquals(false, text2.getEnabled());
580: assertEquals(true, checkbox1.getSelection());
581: }
582:
583: public void testScenario13() {
584: Text text = new Text(getComposite(), SWT.BORDER);
585:
586: getDbc().bindValue(
587: SWTObservables.observeText(text, SWT.FocusOut),
588: BeansObservables.observeValue(adventure, "name"), null,
589: null);
590:
591: // uncomment the following line to see what's happening
592: // happening
593: // spinEventLoop(1);
594: String adventureName = adventure.getName();
595: assertEquals(adventureName, text.getText());
596: enterText(text, "foobar");
597: // uncomment the following line to see what's happening
598: // spinEventLoop(1);
599: assertEquals("foobar", adventure.getName());
600: adventure.setName("barfoo");
601: // uncomment the following line to see what's happening
602: // spinEventLoop(1);
603: assertEquals("barfoo", text.getText());
604: }
605:
606: public void testScenario14() {
607: Text t1 = new Text(getComposite(), SWT.BORDER);
608: Text t2 = new Text(getComposite(), SWT.BORDER);
609:
610: getDbc().bindValue(SWTObservables.observeText(t1, SWT.Modify),
611: BeansObservables.observeValue(adventure, "name"), null,
612: null);
613: getDbc().bindValue(SWTObservables.observeText(t2, SWT.Modify),
614: BeansObservables.observeValue(adventure, "name"), null,
615: null);
616:
617: final int[] counter = { 0 };
618:
619: IObservableValue uv = BeansObservables.observeValue(adventure,
620: "name");
621:
622: uv.addChangeListener(new IChangeListener() {
623: public void handleChange(ChangeEvent event) {
624: // Count how many times adventure has changed
625: counter[0]++;
626: }
627: });
628:
629: String name = adventure.getName() + "Foo";
630: enterText(t1, name);
631: assertEquals(name, adventure.getName());
632: assertEquals(name, t2.getText());
633: assertTrue(counter[0] == 1);
634:
635: name = name + "Bar";
636: uv.setValue(name);
637: assertEquals(t1.getText(), adventure.getName());
638: assertEquals(2, counter[0]);
639:
640: }
641:
642: public void testScenario15() {
643: Text text = new Text(getComposite(), SWT.NONE);
644: Account account = new Account();
645: account.setExpiryDate(new Date());
646:
647: Binding b = getDbc().bindValue(
648: SWTObservables.observeText(text, SWT.Modify),
649: BeansObservables.observeValue(account, "expiryDate"),
650: null, null);
651: Text errorText = new Text(getComposite(), SWT.NONE);
652:
653: getDbc().bindValue(
654: SWTObservables.observeText(errorText, SWT.Modify),
655: b.getValidationStatus(),
656: new UpdateValueStrategy(false,
657: UpdateValueStrategy.POLICY_NEVER), null);
658: assertTrue(((IStatus) b.getValidationStatus().getValue())
659: .isOK());
660: enterText(text, "foo");
661: assertFalse(((IStatus) b.getValidationStatus().getValue())
662: .isOK());
663: }
664: }
|