Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111875 Details for
Bug 131435
[DataBinding] Support for StyledText
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch + tests
clipboard.txt (text/plain), 25.39 KB, created by
Chris Aniszczyk
on 2008-09-05 17:06:06 EDT
(
hide
)
Description:
patch + tests
Filename:
MIME Type:
Creator:
Chris Aniszczyk
Created:
2008-09-05 17:06:06 EDT
Size:
25.39 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface.tests.databinding >Index: src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java,v >retrieving revision 1.9 >diff -u -r1.9 SWTObservablesTest.java >--- src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java 19 Mar 2008 23:03:20 -0000 1.9 >+++ src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java 5 Sep 2008 21:04:08 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007 Brad Reynolds and others. >+ * Copyright (c) 2007, 2008 Brad Reynolds 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 > ******************************************************************************/ > > package org.eclipse.jface.tests.databinding.swt; >@@ -27,6 +28,7 @@ > import org.eclipse.jface.internal.databinding.swt.SWTProperties; > import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; > import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.internal.databinding.swt.StyledTextObservableValue; > import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; > import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; > import org.eclipse.jface.internal.databinding.swt.TextObservableValue; >@@ -34,6 +36,7 @@ > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CCombo; > import org.eclipse.swt.custom.CLabel; >+import org.eclipse.swt.custom.StyledText; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.widgets.Button; >@@ -146,7 +149,7 @@ > } catch (IllegalArgumentException e) { > } > } >- >+ > public void testObserveTextOfText() throws Exception { > Text text = new Text(shell, SWT.NONE); > assertFalse(text.isListening(SWT.FocusOut)); >@@ -157,6 +160,17 @@ > assertTrue(value instanceof TextObservableValue); > assertTrue(text.isListening(SWT.FocusOut)); > } >+ >+ public void testObserveTextOfStyledText() throws Exception { >+ StyledText text = new StyledText(shell, SWT.NONE); >+ assertFalse(text.isListening(SWT.FocusOut)); >+ >+ ISWTObservableValue value = SWTObservables.observeText(text, >+ SWT.FocusOut); >+ assertNotNull(value); >+ assertTrue(value instanceof StyledTextObservableValue); >+ assertTrue(text.isListening(SWT.FocusOut)); >+ } > > public void testObserveTextWithEventOfUnsupportedControl() throws Exception { > Label label = new Label(shell, SWT.NONE); >Index: src/org/eclipse/jface/tests/databinding/BindingTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java,v >retrieving revision 1.89 >diff -u -r1.89 BindingTestSuite.java >--- src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 5 Sep 2008 18:12:37 -0000 1.89 >+++ src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 5 Sep 2008 21:04:08 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005-2008 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 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 >@@ -15,6 +15,7 @@ > * 212518, 215531, 221351, 184830, 213145, 218269, 239015, > * 237703, 237718 > * Ovidio Mallo - bug 237163, bug 235195 >+ * Chris Aniszczyk - bug 131435 > *******************************************************************************/ > package org.eclipse.jface.tests.databinding; > >@@ -163,6 +164,9 @@ > import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMinTest; > import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueSelectionTest; > import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueTest; >+import org.eclipse.jface.tests.internal.databinding.swt.StyledTextObservableValueFocusOutTest; >+import org.eclipse.jface.tests.internal.databinding.swt.StyledTextObservableValueModifyTest; >+import org.eclipse.jface.tests.internal.databinding.swt.StyledTextObservableValueTest; > import org.eclipse.jface.tests.internal.databinding.swt.TableObservableValueTest; > import org.eclipse.jface.tests.internal.databinding.swt.TableSingleSelectionObservableValueTest; > import org.eclipse.jface.tests.internal.databinding.swt.TextEditableObservableValueTest; >@@ -386,6 +390,9 @@ > addTest(TextObservableValueFocusOutTest.suite()); > addTest(TextObservableValueModifyTest.suite()); > addTestSuite(TextObservableValueTest.class); >+ addTest(StyledTextObservableValueFocusOutTest.suite()); >+ addTest(StyledTextObservableValueModifyTest.suite()); >+ addTestSuite(StyledTextObservableValueTest.class); > > //org.eclipse.jface.tests.internal.databinding.internal.viewers > addTest(ObservableViewerElementSetTest.suite()); >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,102 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 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: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >+import org.eclipse.jface.internal.databinding.swt.StyledTextObservableValue; >+import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Tests to assert the inputs of the StyledTextObservableValue constructor. >+ */ >+public class StyledTextObservableValueTest extends AbstractDefaultRealmTestCase { >+ private StyledText text; >+ private ValueChangeEventTracker listener; >+ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ >+ Shell shell = new Shell(); >+ text = new StyledText(shell, SWT.NONE); >+ >+ listener = new ValueChangeEventTracker(); >+ } >+ >+ /** >+ * Asserts that only valid SWT event types are accepted on construction of >+ * StyledTextObservableValue. >+ */ >+ public void testConstructorUpdateEventTypes() { >+ try { >+ new StyledTextObservableValue(text, SWT.NONE); >+ new StyledTextObservableValue(text, SWT.FocusOut); >+ new StyledTextObservableValue(text, SWT.Modify); >+ assertTrue(true); >+ } catch (IllegalArgumentException e) { >+ fail(); >+ } >+ >+ try { >+ new StyledTextObservableValue(text, SWT.Verify); >+ fail(); >+ } catch (IllegalArgumentException e) { >+ assertTrue(true); >+ } >+ } >+ >+ /** >+ * @throws Exception >+ */ >+ public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception { >+ StyledTextObservableValue observableValue = new StyledTextObservableValue(text, SWT.FocusOut); >+ observableValue.addValueChangeListener(listener); >+ >+ String a = "a"; >+ String b = "b"; >+ >+ text.setText(a); >+ assertEquals(a, observableValue.getValue()); //fetch the value updating the buffered value >+ >+ text.setText(b); >+ text.notifyListeners(SWT.FocusOut, null); >+ >+ assertEquals(1, listener.count); >+ assertEquals(a, listener.event.diff.getOldValue()); >+ assertEquals(b, listener.event.diff.getNewValue()); >+ } >+ >+ public void testDispose() throws Exception { >+ StyledTextObservableValue observableValue = new StyledTextObservableValue(text, >+ SWT.Modify); >+ ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); >+ observableValue.addValueChangeListener(testCounterValueChangeListener); >+ >+ String expected1 = "Test123"; >+ text.setText(expected1); >+ >+ assertEquals(1, testCounterValueChangeListener.count); >+ assertEquals(expected1, text.getText()); >+ assertEquals(expected1, observableValue.getValue()); >+ >+ observableValue.dispose(); >+ >+ String expected2 = "NewValue123"; >+ text.setText(expected2); >+ >+ assertEquals(1, testCounterValueChangeListener.count); >+ assertEquals(expected2, text.getText()); >+ } >+} >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,74 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 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: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+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.internal.databinding.swt.StyledTextObservableValue; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Tests for the Modify version of StyledTextObservableValue. >+ */ >+public class StyledTextObservableValueModifyTest extends TestCase { >+ public static Test suite() { >+ TestSuite suite = new TestSuite(StyledTextObservableValueModifyTest.class.toString()); >+ suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ return suite; >+ } >+ >+ /* package */static class Delegate extends >+ AbstractObservableValueContractDelegate { >+ private Shell shell; >+ >+ private StyledText text; >+ >+ public void setUp() { >+ shell = new Shell(); >+ text = new StyledText(shell, SWT.NONE); >+ } >+ >+ public void tearDown() { >+ shell.dispose(); >+ } >+ >+ public IObservableValue createObservableValue(Realm realm) { >+ return new StyledTextObservableValue(realm, text, SWT.Modify); >+ } >+ >+ public Object getValueType(IObservableValue observable) { >+ return String.class; >+ } >+ >+ public void change(IObservable observable) { >+ text.setFocus(); >+ >+ IObservableValue observableValue = (IObservableValue) observable; >+ text.setText((String) createValue(observableValue)); >+ } >+ >+ public Object createValue(IObservableValue observable) { >+ String value = (String) observable.getValue(); >+ return value + "a"; >+ } >+ } >+} >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,76 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 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: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+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.internal.databinding.swt.StyledTextObservableValue; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Tests for the FocusOut version of StyledTextObservableValue. >+ */ >+public class StyledTextObservableValueFocusOutTest extends TestCase { >+ public static Test suite() { >+ TestSuite suite = new TestSuite(StyledTextObservableValueFocusOutTest.class.toString()); >+ suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ return suite; >+ } >+ >+ /* package */static class Delegate extends >+ AbstractObservableValueContractDelegate { >+ private Shell shell; >+ >+ private StyledText text; >+ >+ public void setUp() { >+ shell = new Shell(); >+ text = new StyledText(shell, SWT.NONE); >+ } >+ >+ public void tearDown() { >+ shell.dispose(); >+ } >+ >+ public IObservableValue createObservableValue(Realm realm) { >+ return new StyledTextObservableValue(realm, text, SWT.FocusOut); >+ } >+ >+ public Object getValueType(IObservableValue observable) { >+ return String.class; >+ } >+ >+ public void change(IObservable observable) { >+ text.setFocus(); >+ >+ IObservableValue observableValue = (IObservableValue) observable; >+ text.setText((String) createValue(observableValue)); >+ >+ text.notifyListeners(SWT.FocusOut, null); >+ } >+ >+ public Object createValue(IObservableValue observable) { >+ String value = (String) observable.getValue(); >+ return value + "a"; >+ } >+ } >+} >#P org.eclipse.jface.databinding >Index: src/org/eclipse/jface/databinding/swt/SWTObservables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java,v >retrieving revision 1.19 >diff -u -r1.19 SWTObservables.java >--- src/org/eclipse/jface/databinding/swt/SWTObservables.java 24 Mar 2008 19:13:54 -0000 1.19 >+++ src/org/eclipse/jface/databinding/swt/SWTObservables.java 5 Sep 2008 21:04:09 -0000 >@@ -19,6 +19,7 @@ > > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.jface.internal.databinding.internal.swt.LinkObservableValue; > import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; > import org.eclipse.jface.internal.databinding.swt.CComboObservableList; > import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; >@@ -26,7 +27,6 @@ > import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; > import org.eclipse.jface.internal.databinding.swt.ComboObservableList; > import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; >-import org.eclipse.jface.internal.databinding.internal.swt.LinkObservableValue; > import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; > import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; > import org.eclipse.jface.internal.databinding.swt.DelayedObservableValue; >@@ -38,11 +38,13 @@ > import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; > import org.eclipse.jface.internal.databinding.swt.ShellObservableValue; > import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.internal.databinding.swt.StyledTextObservableValue; > import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; > import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; > import org.eclipse.jface.internal.databinding.swt.TextObservableValue; > import org.eclipse.swt.custom.CCombo; > import org.eclipse.swt.custom.CLabel; >+import org.eclipse.swt.custom.StyledText; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Control; >@@ -230,9 +232,9 @@ > * <code>control</code>. The supported types are: > * <ul> > * <li>org.eclipse.swt.widgets.Text</li> >+ * <li>org.eclipse.swt.custom.StyledText (as of 1.3)</li> > * </ul> > * >- * <li>org.eclipse.swt.widgets.Label</li> > * @param control > * @param event event type to register for change events > * @return observable value >@@ -242,6 +244,8 @@ > public static ISWTObservableValue observeText(Control control, int event) { > if (control instanceof Text) { > return new TextObservableValue((Text) control, event); >+ } else if (control instanceof StyledText) { >+ return new StyledTextObservableValue((StyledText) control, event); > } > > throw new IllegalArgumentException( >Index: src/org/eclipse/jface/internal/databinding/swt/StyledTextObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/StyledTextObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/StyledTextObservableValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/StyledTextObservableValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 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: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ *******************************************************************************/ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.events.VerifyEvent; >+import org.eclipse.swt.events.VerifyListener; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+ >+/** >+ * {@link IObservable} implementation that wraps a {@link StyledText} widget. The time >+ * at which listeners should be notified about changes to the text is specified >+ * on construction. >+ * >+ * <dl> >+ * <dt>Events:</dt> >+ * <dd> If the update event type (specified on construction) is >+ * <code>SWT.Modify</code> a value change event will be fired on every key >+ * stroke. If the update event type is <code>SWT.FocusOut</code> a value >+ * change event will be fired on focus out. When in either mode if the user is >+ * entering text and presses [Escape] the value will be reverted back to the >+ * last value set using doSetValue(). Regardless of the update event type a >+ * value changing event will fire on verify to enable vetoing of changes.</dd> >+ * </dl> >+ * >+ * @since 1.3 >+ */ >+public class StyledTextObservableValue extends AbstractSWTVetoableValue { >+ >+ /** >+ * {@link StyledText} widget that this is being observed. >+ */ >+ private final StyledText text; >+ >+ /** >+ * Flag to track when the model is updating the widget. When >+ * <code>true</code> the handlers for the SWT events should not process >+ * the event as this would cause an infinite loop. >+ */ >+ private boolean updating = false; >+ >+ /** >+ * SWT event that on firing this observable will fire change events to its >+ * listeners. >+ */ >+ private final int updateEventType; >+ >+ /** >+ * Valid types for the {@link #updateEventType}. >+ */ >+ private static final int[] validUpdateEventTypes = new int[] { SWT.Modify, >+ SWT.FocusOut, SWT.None }; >+ >+ /** >+ * Previous value of the Text. >+ */ >+ private String oldValue; >+ >+ private Listener updateListener = new Listener() { >+ public void handleEvent(Event event) { >+ if (!updating) { >+ String newValue = text.getText(); >+ >+ if (!newValue.equals(oldValue)) { >+ fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >+ oldValue = newValue; >+ } >+ } >+ } >+ }; >+ >+ private VerifyListener verifyListener; >+ >+ /** >+ * Constructs a new instance bound to the given <code>StyledText</code> widget >+ * and configured to fire change events to its listeners at the time of the >+ * <code>updateEventType</code>. >+ * >+ * @param text >+ * @param updateEventType >+ * SWT event constant as to what SWT event to update the model in >+ * response to. Appropriate values are: <code>SWT.Modify</code>, >+ * <code>SWT.FocusOut</code>, <code>SWT.None</code>. >+ * @throws IllegalArgumentException >+ * if <code>updateEventType</code> is an incorrect type. >+ */ >+ public StyledTextObservableValue(final StyledText text, int updateEventType) { >+ this(SWTObservables.getRealm(text.getDisplay()), text, updateEventType); >+ } >+ >+ /** >+ * Constructs a new instance. >+ * >+ * @param realm can not be <code>null</code> >+ * @param text >+ * @param updateEventType >+ */ >+ public StyledTextObservableValue(final Realm realm, StyledText text, int updateEventType) { >+ super(realm, text); >+ >+ boolean eventValid = false; >+ for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { >+ eventValid = (updateEventType == validUpdateEventTypes[i]); >+ } >+ if (!eventValid) { >+ throw new IllegalArgumentException( >+ "UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ this.text = text; >+ this.updateEventType = updateEventType; >+ if (updateEventType != SWT.None) { >+ text.addListener(updateEventType, updateListener); >+ } >+ >+ oldValue = text.getText(); >+ >+ verifyListener = new VerifyListener() { >+ public void verifyText(VerifyEvent e) { >+ if (!updating) { >+ String currentText = StyledTextObservableValue.this.text >+ .getText(); >+ String newText = currentText.substring(0, e.start) + e.text >+ + currentText.substring(e.end); >+ if (!fireValueChanging(Diffs.createValueDiff(currentText, >+ newText))) { >+ e.doit = false; >+ } >+ } >+ } >+ }; >+ text.addVerifyListener(verifyListener); >+ } >+ >+ /** >+ * Sets the bound {@link StyledText Text's} text to the passed <code>value</code>. >+ * >+ * @param value >+ * new value, String expected >+ * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doSetApprovedValue(java.lang.Object) >+ * @throws ClassCastException >+ * if the value is anything other than a String >+ */ >+ protected void doSetApprovedValue(final Object value) { >+ try { >+ updating = true; >+ text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ >+ oldValue = text.getText(); >+ } finally { >+ updating = false; >+ } >+ } >+ >+ /** >+ * Returns the current value of the {@link StyledText}. >+ * >+ * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doGetValue() >+ */ >+ public Object doGetValue() { >+ return oldValue = text.getText(); >+ } >+ >+ /** >+ * Returns the type of the value from {@link #doGetValue()}, i.e. >+ * String.class >+ * >+ * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() >+ */ >+ public Object getValueType() { >+ return String.class; >+ } >+ >+ public void dispose() { >+ if (!text.isDisposed()) { >+ if (updateEventType != SWT.None) { >+ text.removeListener(updateEventType, updateListener); >+ } >+ text.removeVerifyListener(verifyListener); >+ } >+ super.dispose(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 131435
:
36093
| 111875 |
111876