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 50779 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 and SWTObservables (a)
DataBinding_2006-09-25a.txt (text/plain), 7.88 KB, created by
Andy Maleh
on 2006-09-25 02:12:59 EDT
(
hide
)
Description:
Updated TextObservableValue and SWTObservables (a)
Filename:
MIME Type:
Creator:
Andy Maleh
Created:
2006-09-25 02:12:59 EDT
Size:
7.88 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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 25 Sep 2006 06:14:50 -0000 >@@ -86,11 +86,11 @@ > > /** > * @param text >- * @param event >+ * @param observableStyle as specified in {@link TextObservableValue} > * @return > */ >- 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 25 Sep 2006 06:14:50 -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; > >@@ -33,13 +34,19 @@ > * > * <dl> > * <dt>Events:</dt> >- * <dd> If the update event type (specified on construction) is >+ * <dd> The update event type (specified on construction) can contain either >+ * SWT.Modify or SWT.FocusOut, but not both. If the update event type contains > * <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> >+ * stroke. If the update event type contains <code>SWT.FocusOut</code>, a value >+ * change event will be fired on focus out. If the update event type contains >+ * <code>SWT.CR</code> in addition to <code>SWT.FocusOut</code>, a value change >+ * event will be fired when pressing [Enter]. The default <code>SWT.NONE</code> >+ * is equivalent to <code>SWT.FocusOut | SWT.CR</code> >+ * Regardless of the update event type a value changing event will fire on >+ * verify to enable vetoing of changes. Moreover, if the user is entering >+ * text and presses [Escape], the value will be reverted back to the last value >+ * set using doSetValue(). >+ * </dd> > * </dl> > * > * @since 1.0 >@@ -59,16 +66,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 +120,34 @@ > * <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>. >+ * <code>SWT.FocusOut</code>, <code>SWT.CR</code>, >+ * <code>SWT.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]); >+ this.text = text; >+ this.observableStyle = observableStyle; >+ if (observableStyleContains(SWT.Modify) && >+ !observableStyleContains(SWT.CR)) { // CR conflicts with Modify >+ updateEventType = SWT.Modify; >+ } else if (observableStyleContains(SWT.FocusOut)) { >+ updateEventType = SWT.FocusOut; >+ } else if (observableStyle == SWT.NONE) { >+ updateEventType = SWT.FocusOut; >+ this.observableStyle = SWT.FocusOut | SWT.CR; // Defaults > } >- if (!eventValid) { >+ else { > 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); >+ "Invalid ObservableStyle was supplied."); //$NON-NLS-1$ > } >+ >+ 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 +163,7 @@ > } > }); > } >+ > verifyListener = new VerifyListener() { > public void verifyText(VerifyEvent e) { > if (!updating) { >@@ -164,18 +179,37 @@ > } > }; > text.addVerifyListener(verifyListener); >+ > keyListener = new KeyListener() { > public void keyPressed(KeyEvent e) { >- if (e.character == SWT.ESC && bufferedValue != null) { >+ >+ // If character is escape >+ if ((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(SWT.CR)) && >+ (e.character == SWT.CR)) { >+ bufferedValue = text.getText(); >+ if (!newValue.equals(oldValue)) { >+ // Propagate text field value to the model >+ 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 +275,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