aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaruch Youssin2014-02-24 13:13:02 (EST)
committerBaruch Youssin2014-02-24 13:13:02 (EST)
commit009cb6bac6b9fabf9ce8d0c3456d6e334fa1734c (patch)
treec601541cb5215d9ae180bed891600ef61838faf9
parentb8295c52d79129a66855eb5b8bf1af045022786b (diff)
downloadorg.eclipse.nebula-009cb6bac6b9fabf9ce8d0c3456d6e334fa1734c.zip
org.eclipse.nebula-009cb6bac6b9fabf9ce8d0c3456d6e334fa1734c.tar.gz
org.eclipse.nebula-009cb6bac6b9fabf9ce8d0c3456d6e334fa1734c.tar.bz2
Bug 261414 - [CDateTime] getSelection does not return visible daterefs/changes/70/22470/1
Call commitEditField() on FocusOut event Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=261414 Signed-off-by: Baruch Youssin <quququitty@yahoo.com>
-rw-r--r--widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java b/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java
index 8a4c946..e75c53f 100644
--- a/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java
+++ b/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java
@@ -9,6 +9,7 @@
* Jeremy Dowdall <jeremyd@aspencloud.com> - initial API and implementation
* Wim Jongman - https://bugs.eclipse.org/bugs/show_bug.cgi?id=362181
* Scott Klein - https://bugs.eclipse.org/bugs/show_bug.cgi?id=370605
+ * Baruch Youssin - https://bugs.eclipse.org/bugs/show_bug.cgi?id=261414
*****************************************************************************/
package org.eclipse.nebula.widgets.cdatetime;
@@ -89,6 +90,13 @@ public class CDateTime extends BaseCombo {
buffer = Integer.toString(initialValue);
}
+ /**
+ * Adds a character if it is a digit; in case the field exceeds its capacity, the oldest character is
+ * dropped from the buffer. Non-digits are dropped.
+ * @param c
+ * @return true if the new character is a digit and with its addition the active field
+ * reaches or exceeds its capacity, false otherwise
+ */
boolean addChar(char c) {
if (Character.isDigit(c)) {
buffer = (count > 0) ? buffer : ""; //$NON-NLS-1$
@@ -257,6 +265,7 @@ public class CDateTime extends BaseCombo {
break;
case SWT.FocusOut:
if (!rightClick && !internalFocusShift) {
+ commitEditField();
updateText();
}
break;
@@ -1919,9 +1928,10 @@ public class CDateTime extends BaseCombo {
/**
* This is the only way that text is set to the text box.<br>
- * The selection is also set here (corresponding to the active field) as
+ * The selection of the text in the text box is also set here (the active field is selected) as
* well as if a field is being edited, it's "edit text" is inserted for
* display.
+ * The <code>getSelection</code> property of CDateTime remains unchanged.
*/
private void updateText() {
updateText(false);
@@ -1929,9 +1939,10 @@ public class CDateTime extends BaseCombo {
/**
* This is the only way that text is set to the text box.<br>
- * The selection is also set here (corresponding to the active field) as
+ * The selection of the text in the text box is also set here (the active field is selected) as
* well as if a field is being edited, it's "edit text" is inserted for
* display.
+ * The <code>getSelection</code> property of CDateTime remains unchanged.
*
* @param async
* If true, this operation will be performed asynchronously (for
@@ -2006,6 +2017,24 @@ public class CDateTime extends BaseCombo {
* <b>EVERYTHING</b> is blocked via this handler (Event.doit is set to
* false). Depending upon the input, a course of action is determined and
* the displayed text is updated via the <code>updateText()</code> method.
+ * <br>
+ * This method implements the following logic:
+ * If the event is a paste, the pasted text is parsed for the entire date/time selection;
+ * if this parse is successful, the result is committed to the selection property and is displayed;
+ * otherwise, it is discarded. One-character pastes are discarded without parsing.
+ * When user types characters one by one, all non-digits are discarded (if they have effects, they
+ * have already been processed by other event handlers) while digits are added to
+ * <code>this.editField</code> without affecting the selection.
+ * Once <code>this.editField</code> reaches its capacity for
+ * the active field, its contents are attempted to be committed.
+ * If the commit is successful, focus switches to the next field of CDateTime.
+ * Otherwise, the contents of <code>this.editField</code>
+ * are discarded and the previous value of the selection (before user started typing
+ * in this field) is restored; focus stays in the same field.
+ * <b>Example:</b> if the seconds field contains "23", and user types 8 in the seconds field,
+ * "08" is shown on screen while getSelection still returns 23. If user types 9 after that,
+ * the field reaches its capacity, the attempt to commit 89 seconds fails, and 23 gets restored
+ * on screen.
*
* @param e
* the event