aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDietmar Glachs2012-09-24 06:29:48 (EDT)
committerWim Jongman2012-09-24 06:29:48 (EDT)
commit6b30b14475bd6f2b25158caa32ade402999b9e8a (patch)
tree6ddffc20e8dbc81667a6a8ad20dc4b3fcaa97751
parentce5279a8ad614302fd903c3bac4980be0427b5e2 (diff)
downloadorg.eclipse.nebula-6b30b14475bd6f2b25158caa32ade402999b9e8a.zip
org.eclipse.nebula-6b30b14475bd6f2b25158caa32ade402999b9e8a.tar.gz
org.eclipse.nebula-6b30b14475bd6f2b25158caa32ade402999b9e8a.tar.bz2
bug 388813: No selection event is sent when changing either month
or year from date dropdown's month resp. year button https://bugs.eclipse.org/bugs/show_bug.cgi?id=388813
-rw-r--r--widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/CDateTime.java36
-rw-r--r--widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/DatePicker.java33
2 files changed, 57 insertions, 12 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 faeb6fc..1eef4a0 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
@@ -67,7 +67,7 @@ import org.eclipse.swt.widgets.TypedListener;
* <li>Combo - a text selector with a drop-down graphical selector
* (CDT.DROP_DOWN)</li>
* </ul>
- * <p>
+ * <p>
* Styles are set using the constants provided in the CDT class.
* </p>
*
@@ -1344,6 +1344,40 @@ public class CDateTime extends BaseCombo {
boolean isSingleSelection() {
return singleSelection;
}
+ /**
+ * Determine whether the provided field is the most
+ * <b>precise</b> field. According to the used pattern, e.g.
+ * <ul>
+ * <li>dd.mm.yyyy
+ * <li>MMMM yyyy
+ * <li>yyyy
+ * </ul>
+ * the date picker provides the panels for selecting a day, month or year
+ * respectively. The panel should close itself and set the selection in
+ * the CDateTime field when the user selects the most precise field.
+ * The constants from the {@link Calendar} class may be used to determine
+ * the most precise field:
+ * <ul>
+ * <li>{@link Calendar#YEAR} -> 1
+ * <li>{@link Calendar#MONTH} -> 2
+ * <li>{@link Calendar#DATE} -> 5
+ * </ul>
+ * e.g. the <i>highest</i> constant is the closing field.
+ * @param calendarField The calendar field identifying a pattern field
+ * @return true if the highest pattern field
+ */
+ boolean isClosingField(int calendarField) {
+ // find the "highest" constant in the pattern fields
+ int i = Integer.MIN_VALUE;
+ for (Field f : field) {
+ i = Math.max(i, f.getCalendarField());
+ }
+ // compare the highest constant with the field
+ if ( i == calendarField) {
+ return true;
+ }
+ return false;
+ }
@Override
protected void postClose(Shell popup) {
diff --git a/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/DatePicker.java b/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/DatePicker.java
index 3f2e98f..315efb2 100644
--- a/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/DatePicker.java
+++ b/widgets/cdatetime/org.eclipse.nebula.widgets.cdatetime/src/org/eclipse/nebula/widgets/cdatetime/DatePicker.java
@@ -289,7 +289,10 @@ class DatePicker extends VPanel {
VButton button = (VButton) event.data;
int stateMask = event.stateMask;
setSelectionFromButton(button, stateMask);
- if (cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.DATE) {
+ // Bug 388813
+ // when the date field is the most "precise"
+ // information according to the pattern
+ if (cdt.isClosingField(Calendar.DATE)) {
cdt.fireSelectionChanged(true);
} else {
cdt.fireSelectionChanged();
@@ -590,7 +593,7 @@ class DatePicker extends VPanel {
Calendar tmpcal = cdt.getCalendarInstance();
if(yearButton != null && yearButton.getSelection()) {
tmpcal.add(Calendar.YEAR, 10);
- } else if(cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
+ } else if ( cdt.isClosingField(Calendar.YEAR)) {
tmpcal.add(Calendar.YEAR, 10);
} else {
tmpcal.add(Calendar.YEAR, 1);
@@ -610,7 +613,7 @@ class DatePicker extends VPanel {
Calendar tmpcal = cdt.getCalendarInstance();
if(yearButton != null && yearButton.getSelection()) {
tmpcal.add(Calendar.YEAR, -10);
- } else if(cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
+ } else if ( cdt.isClosingField(Calendar.YEAR)) {
tmpcal.add(Calendar.YEAR, -10);
} else {
tmpcal.add(Calendar.YEAR, -1);
@@ -666,9 +669,14 @@ class DatePicker extends VPanel {
Calendar tmpcal = cdt.getCalendarInstance();
tmpcal.set(Calendar.MONTH, (Integer) button.getData("Month")); //$NON-NLS-1$
cdt.setSelection(tmpcal.getTime());
-
- if (cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.MONTH) {
- cdt.fireSelectionChanged(true);
+ /*:
+ * Bug 388813
+ * the method cdt.isClosingField checks the "most concrete" portion of the date pattern
+ * and returns true if the requested field *is* the one closing the picker panel
+ * and false otherwise
+ */
+ if (cdt.isClosingField(Calendar.MONTH)) {
+ cdt.fireSelectionChanged(true);
} else {
cdt.fireSelectionChanged();
handleHeaderSelection(null);
@@ -731,15 +739,16 @@ class DatePicker extends VPanel {
for(VButton b : yearButtons) {
if(b != button) {
b.setSelection(false);
- }
+ }
}
}
Calendar tmpcal = cdt.getCalendarInstance();
tmpcal.set(Calendar.YEAR, Integer.parseInt(button.getText()));
cdt.setSelection(tmpcal.getTime());
-
- if (cdt.field.length == 1 && cdt.getCalendarField(cdt.field[0]) == Calendar.YEAR) {
+ // Bug 388813
+ // when the year field is the most precise field
+ if ( cdt.isClosingField(Calendar.YEAR)) {
cdt.fireSelectionChanged(true);
} else {
cdt.fireSelectionChanged();
@@ -1128,8 +1137,10 @@ class DatePicker extends VPanel {
(scal.get(Calendar.MONTH) == tmpcal.get(Calendar.MONTH)) &&
(scal.get(Calendar.YEAR) == tmpcal.get(Calendar.YEAR)) ) {
dayButtons[j].setSelection(true);
- focusButton = j;
- break;
+ // Bug 388813:
+ // don't catch the focus
+ //focusButton = j;
+ break;
}
}
if(focusButton >= 0) {