| /******************************************************************************* |
| * Copyright (c) 2007, 2009 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| * Matthew Hall - bug 213145, 194734, 195222 |
| * (through TextObservableValueFocusOutText.java) |
| * Matthew Hall - bug 256543 |
| *******************************************************************************/ |
| |
| package org.eclipse.jface.tests.internal.databinding.swt; |
| |
| import org.eclipse.core.databinding.observable.IObservable; |
| import org.eclipse.core.databinding.observable.Realm; |
| import org.eclipse.core.databinding.observable.value.IObservableValue; |
| import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; |
| import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; |
| import org.eclipse.jface.databinding.swt.WidgetProperties; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.swt.widgets.Text; |
| |
| import junit.framework.TestSuite; |
| |
| /** |
| * Tests for the DefaultSelection version of TextObservableValue. |
| */ |
| public class TextObservableValueDefaultSelectionTest { |
| public static void addConformanceTest(TestSuite suite) { |
| suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); |
| } |
| |
| /* package */static class Delegate extends |
| AbstractObservableValueContractDelegate { |
| private Shell shell; |
| |
| private Text text; |
| |
| @Override |
| public void setUp() { |
| shell = new Shell(); |
| text = new Text(shell, SWT.NONE); |
| } |
| |
| @Override |
| public void tearDown() { |
| shell.dispose(); |
| } |
| |
| @Override |
| public IObservableValue createObservableValue(Realm realm) { |
| return WidgetProperties.text(SWT.DefaultSelection).observe(realm, text); |
| } |
| |
| @Override |
| public Object getValueType(IObservableValue observable) { |
| return String.class; |
| } |
| |
| @Override |
| public void change(IObservable observable) { |
| text.setFocus(); |
| |
| IObservableValue observableValue = (IObservableValue) observable; |
| text.setText((String) createValue(observableValue)); |
| |
| text.notifyListeners(SWT.DefaultSelection, null); |
| } |
| |
| @Override |
| public Object createValue(IObservableValue observable) { |
| String value = (String) observable.getValue(); |
| return value + "a"; |
| } |
| } |
| } |