01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: * Brad Reynolds - bug 116920
11: *******************************************************************************/package org.eclipse.jface.tests.databinding.scenarios;
12:
13: import org.eclipse.core.databinding.beans.BeansObservables;
14: import org.eclipse.jface.databinding.swt.SWTObservables;
15: import org.eclipse.swt.SWT;
16: import org.eclipse.swt.widgets.Text;
17:
18: /**
19: * @since 3.2
20: *
21: */
22: public class NPETestScenario extends ScenariosTestCase {
23: private Text text;
24:
25: Person person;
26:
27: protected void setUp() throws Exception {
28: super .setUp();
29: person = new Person();
30: text = new Text(getComposite(), SWT.BORDER);
31: }
32:
33: /**
34: * Asserts the ability to have an initial value of <code>null</code> on
35: * the model and to update the value by changing the value of the view.
36: */
37: public void test_InitialNullValue() {
38: Person person = new Person();
39: assertNull(person.getName());
40:
41: System.out
42: .println("Expecting message about not being able to attach a listener");
43: getDbc().bindValue(
44: SWTObservables.observeText(text, SWT.Modify),
45: BeansObservables.observeValue(person, "name"), null,
46: null);
47:
48: text.setText("Brad");
49: text.notifyListeners(SWT.FocusOut, null);
50: assertEquals("Brad", person.getName());
51: }
52:
53: private static class Person {
54: private String name;
55:
56: /**
57: * @return Returns the name.
58: */
59: public String getName() {
60: return name;
61: }
62:
63: /**
64: * @param name
65: * The name to set.
66: */
67: public void setName(String name) {
68: this.name = name;
69: }
70: }
71: }
|