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 50985 Details for
Bug 156264
[DataBinding] Enter key does not cause data-binding to fire on a Text control
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]
Updated TextObservableValue, TextObservableValueTests, and SWTObservables
DataBinding_2006-09-27.txt (text/plain), 11.11 KB, created by
Andy Maleh
on 2006-09-27 01:36:26 EDT
(
hide
)
Description:
Updated TextObservableValue, TextObservableValueTests, and SWTObservables
Filename:
MIME Type:
Creator:
Andy Maleh
Created:
2006-09-27 01:36:26 EDT
Size:
11.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface.tests.databinding >Index: src/org/eclipse/jface/tests/databinding/swt/TextObservableValueTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/TextObservableValueTests.java,v >retrieving revision 1.1 >diff -u -r1.1 TextObservableValueTests.java >--- src/org/eclipse/jface/tests/databinding/swt/TextObservableValueTests.java 16 Jun 2006 22:42:39 -0000 1.1 >+++ src/org/eclipse/jface/tests/databinding/swt/TextObservableValueTests.java 27 Sep 2006 05:25:07 -0000 >@@ -27,7 +27,7 @@ > */ > public void testConstructor() { > try { >- new TextObservableValue(null, SWT.NONE); >+ new TextObservableValue(null, TextObservableValue.NONE); > fail(); > } catch (IllegalArgumentException e) { > assertTrue(true); >@@ -39,16 +39,18 @@ > */ > public void testConstructorUpdateEventTypes() { > try { >- new TextObservableValue(text, SWT.NONE); >- new TextObservableValue(text, SWT.FocusOut); >- new TextObservableValue(text, SWT.Modify); >+ new TextObservableValue(text, TextObservableValue.NONE); >+ new TextObservableValue(text, TextObservableValue.UPDATE_ON_FOCUS_OUT); >+ new TextObservableValue(text, TextObservableValue.UPDATE_ON_MODIFY); >+ new TextObservableValue(text, TextObservableValue.UPDATE_ON_ENTER); >+ new TextObservableValue(text, TextObservableValue.REVERT_ON_ESC); > assertTrue(true); > } catch (IllegalArgumentException e) { > fail(); > } > > try { >- new TextObservableValue(text, SWT.Verify); >+ new TextObservableValue(text, 1024); > fail(); > } catch (IllegalArgumentException e) { > assertTrue(true); >#P org.eclipse.jface.databinding >Index: src/org/eclipse/jface/databinding/swt/SWTObservables.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java,v >retrieving revision 1.1 >diff -u -r1.1 SWTObservables.java >--- src/org/eclipse/jface/databinding/swt/SWTObservables.java 2 Sep 2006 04:19:35 -0000 1.1 >+++ src/org/eclipse/jface/databinding/swt/SWTObservables.java 27 Sep 2006 05:25:08 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Obtiva Corporation (bug 156264) > *******************************************************************************/ > package org.eclipse.jface.databinding.swt; > >@@ -43,7 +44,7 @@ > * > */ > public class SWTObservables { >- >+ > /** > * @param control > * @return >@@ -85,12 +86,14 @@ > } > > /** >- * @param text >- * @param event >- * @return >+ * Creates a Text control observable value. >+ * >+ * @param text Text control >+ * @param observableStyle Observable style as in {@link TextObservableValue} >+ * @return observable value > */ >- public static ISWTObservableValue getText(Text text, int event) { >- return new TextObservableValue(text, event); >+ public static ISWTObservableValue getText(Text text, int observableStyle) { >+ return new TextObservableValue(text, observableStyle); > } > > /** >Index: src/org/eclipse/jface/internal/databinding/internal/swt/TextObservableValue.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/internal/swt/TextObservableValue.java,v >retrieving revision 1.9 >diff -u -r1.9 TextObservableValue.java >--- src/org/eclipse/jface/internal/databinding/internal/swt/TextObservableValue.java 1 Sep 2006 01:35:12 -0000 1.9 >+++ src/org/eclipse/jface/internal/databinding/internal/swt/TextObservableValue.java 27 Sep 2006 05:25:08 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Brad Reynolds (bug 135446) >+ * Obtiva Corporation (bug 156264) > *******************************************************************************/ > package org.eclipse.jface.internal.databinding.internal.swt; > >@@ -32,14 +33,20 @@ > * 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> >+ * <dt>Observable Styles:</dt> >+ * <dd> If the observable style (specified on construction) contains >+ * <code>UPDATE_ON_MODIFY</code> a value change event will be fired on every >+ * key stroke. If the observable style contains >+ * <code>UPDATE_ON_FOCUS_OUT</code>, a value change event will be fired on focus >+ * out. If the observable style contains <code>UPDATE_ON_ENTER</code>, a value >+ * change event will be fired when pressing [Enter]. If the observable style is >+ * <code>NONE</code>, no value change event will ever fire. >+ * If the observable style <code>TextObservableStyle.REVERT_ON_ESC</code> is >+ * specified, then 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 observable style a value changing event will fire on >+ * verify to enable vetoing of changes. >+ * </dd> > * </dl> > * > * @since 1.0 >@@ -47,6 +54,32 @@ > public class TextObservableValue extends AbstractSWTVetoableValue { > > /** >+ * No value change event must ever fire. >+ */ >+ public static final int NONE = 0; >+ >+ /** >+ * A value change event must be fired on every key stroke. >+ */ >+ public static final int UPDATE_ON_MODIFY = 1<<0; >+ >+ /** >+ * A value change event must be fired when pressing [Enter]. >+ */ >+ public static final int UPDATE_ON_ENTER = 1<<1; >+ >+ /** >+ * A value change event must be fired on focus out. >+ */ >+ public static final int UPDATE_ON_FOCUS_OUT = 1<<2; >+ >+ /** >+ * If the user is entering text and presses [Escape], the value must be >+ * reverted back to the last value set. >+ */ >+ public static final int REVERT_ON_ESC = 1<<3; >+ >+ /** > * {@link Text} widget that this is being observed. > */ > private final Text text; >@@ -59,16 +92,17 @@ > private boolean updating = false; > > /** >- * SWT event that on firing this observable will fire change events to its >- * listeners. >+ * Observable style for specifying whether Enter should be handled, >+ * whether to use FocusOut or Modify as the time of updating, and whether >+ * to support Escape to undo edits. > */ >- private int updateEventType; >+ private int observableStyle; > > /** >- * Valid types for the {@link #updateEventType}. >+ * SWT event that on firing this observable will fire change events to its >+ * listeners. > */ >- private static final int[] validUpdateEventTypes = new int[] { SWT.Modify, >- SWT.FocusOut, SWT.NONE }; >+ private int updateEventType; > > /** > * Last value set using doSetValue(), or null. This is maintained so that >@@ -112,28 +146,36 @@ > * <code>updateEventType</code>. > * > * @param text >- * @param updateEventType >+ * @param observableStyle > * 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>. >+ * response to. Appropriate values are: <code>UPDATE_ON_MODIFY</code>, >+ * <code>SWT.FocusOut</code>, <code>UPDATE_ON_ENTER</code>, >+ * <code>NONE</code>. > * @throws IllegalArgumentException > * if <code>updateEventType</code> is an incorrect type. > */ >- public TextObservableValue(final Text text, int updateEventType) { >+ public TextObservableValue(final Text text, final int observableStyle) { > super(text); >- boolean eventValid = false; >- for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { >- eventValid = (updateEventType == validUpdateEventTypes[i]); >- } >- if (!eventValid) { >+ this.text = text; >+ this.observableStyle = observableStyle; >+ if (observableStyleContains(UPDATE_ON_MODIFY)) { >+ updateEventType = SWT.Modify; >+ } else if (observableStyleContains(UPDATE_ON_FOCUS_OUT)) { >+ updateEventType = SWT.FocusOut; >+ // If equal to NONE after filtering remaining styles >+ } else if ((observableStyle & >+ ~UPDATE_ON_ENTER & >+ ~REVERT_ON_ESC) == NONE) { >+ updateEventType = SWT.NONE; >+ } else { > throw new IllegalArgumentException( >- "UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ "Invalid ObservableStyle was supplied."); //$NON-NLS-1$ > } >- this.text = text; >- this.updateEventType = updateEventType; >- if (updateEventType != SWT.None) { >+ >+ if (updateEventType != SWT.NONE) { > text.addListener(updateEventType, updateListener); > } >+ > // If the update policy is SWT.Modify then the model is notified of > // changed on key stroke by key stroke > // When escape is pressed we need to rollback to the previous value >@@ -149,6 +191,7 @@ > } > }); > } >+ > verifyListener = new VerifyListener() { > public void verifyText(VerifyEvent e) { > if (!updating) { >@@ -164,18 +207,38 @@ > } > }; > text.addVerifyListener(verifyListener); >+ > keyListener = new KeyListener() { > public void keyPressed(KeyEvent e) { >- if (e.character == SWT.ESC && bufferedValue != null) { >+ >+ // If character is escape >+ if ((observableStyleContains(REVERT_ON_ESC)) && >+ (e.character == SWT.ESC) && >+ (bufferedValue != null)) { > // Revert the value in the text field to the model value > text.setText(bufferedValue); > } >+ >+ // If character is carriage return >+ String oldValue = bufferedValue; >+ String newValue = text.getText(); >+ if ((observableStyleContains(UPDATE_ON_ENTER)) && >+ (e.character == SWT.CR)) { >+ bufferedValue = text.getText(); >+ if (!newValue.equals(oldValue)) { >+ // Fire value change event >+ fireValueChange(Diffs.createValueDiff(oldValue, >+ newValue)); >+ } >+ >+ } > } > > public void keyReleased(KeyEvent e) { > } > }; > text.addKeyListener(keyListener); >+ > shellListener = new ShellAdapter() { > public void shellClosed(ShellEvent e) { > if (!text.isDisposed()) { >@@ -241,4 +304,13 @@ > } > super.dispose(); > } >+ >+ /** >+ * Indicates if observableStyle contains a particular SWT style >+ * @param style SWT style >+ * @return true if observableStyle contains SWT style or false otherwise >+ */ >+ private boolean observableStyleContains(int style) { >+ return (observableStyle & style) == style; >+ } > }
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 156264
:
50775
|
50779
| 50985