01: /*******************************************************************************
02: * Copyright (c) 2005, 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.jface.examples.databinding.model.Adventure;
16: import org.eclipse.jface.examples.databinding.model.SampleData;
17: import org.eclipse.swt.SWT;
18: import org.eclipse.swt.widgets.Spinner;
19:
20: /**
21: * To run the tests in this class, right-click and select "Run As JUnit Plug-in
22: * Test". This will also start an Eclipse instance. To clean up the launch
23: * configuration, open up its "Main" tab and select "[No Application] - Headless
24: * Mode" as the application to run.
25: */
26:
27: public class SpinnerControlScenario extends ScenariosTestCase {
28:
29: private Adventure adventure;
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: // do any setup work here
34: adventure = SampleData.WINTER_HOLIDAY;
35: }
36:
37: protected void tearDown() throws Exception {
38: // do any teardown work here
39: super .tearDown();
40: }
41:
42: public void testScenario01() {
43: // Bind the adventure "maxNumberOfPeople" property to a spinner
44: // Change the UI and verify the model changes
45: // Change the model and verify the UI changes
46: Spinner spinner = new Spinner(getComposite(), SWT.BORDER);
47: getDbc().bindValue(
48: SWTObservables.observeSelection(spinner),
49: BeansObservables.observeValue(adventure,
50: "maxNumberOfPeople"), null, null);
51:
52: assertEquals(adventure.getMaxNumberOfPeople(), spinner
53: .getSelection());
54: // Verify the model is updated when the GUI is changed
55: spinner.setSelection(5);
56: assertEquals(5, adventure.getMaxNumberOfPeople());
57: // Verify the GUI is updated when the model changes
58: adventure.setMaxNumberOfPeople(7);
59: assertEquals(7, spinner.getSelection());
60: adventure.setMaxNumberOfPeople(11);
61: spinEventLoop(0);
62: assertEquals(11, spinner.getSelection());
63: }
64: }
|