Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElshad Seyidmammadov2017-02-01 13:46:15 +0000
committerGerrit Code Review @ Eclipse.org2017-03-21 07:51:01 +0000
commitb0ef7d2f459d707b5182b7ac231aa7911eb01305 (patch)
tree1de7a099de78ed757e3c1aa5bee494f66f3aa43a
parent6790e87fed7345d452e086f022dca522f9ed156e (diff)
downloadorg.eclipse.rap-b0ef7d2f459d707b5182b7ac231aa7911eb01305.tar.gz
org.eclipse.rap-b0ef7d2f459d707b5182b7ac231aa7911eb01305.tar.xz
org.eclipse.rap-b0ef7d2f459d707b5182b7ac231aa7911eb01305.zip
Implement min/max-value support for DateTime widget
DateTime widget represents wide range of date or time data that is selectable by users. However, in some cases, range of data or time must be limited with according minimum and maximum values. The limitation has to be highlighted in the calendar and prevent users to select a value that is before the defined minimum or after the defined maximum date. Implement min/max-value support for date, time and calendar instances of DateTime widget. 431122: [DateTime] Enable min/max-Value Support for DateTime widget https://bugs.eclipse.org/bugs/show_bug.cgi?id=431122 Change-Id: I1bdf12b53354bec1082c648f907f84cfad71a26d Signed-off-by: Elshad Seyidmammadov <elshad@eclipsesource.com>
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DateTimeHandler.js6
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeCalendar.js18
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js116
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeTime.js110
-rw-r--r--bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/Calendar.js33
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java102
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java4
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java4
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java36
-rw-r--r--bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java4
-rw-r--r--examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DateTimeTab.java56
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeCalendarTest.js16
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeDateTest.js16
-rw-r--r--tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeTimeTest.js42
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java106
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java171
16 files changed, 789 insertions, 51 deletions
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DateTimeHandler.js b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DateTimeHandler.js
index 3005c7bb5e..cb2b4f15b4 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DateTimeHandler.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/DateTimeHandler.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 EclipseSource and others.
+ * Copyright (c) 2011, 2017 EclipseSource 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
@@ -60,7 +60,9 @@ rwt.remote.HandlerRegistry.add( "rwt.widgets.DateTime", {
"hours",
"minutes",
"seconds",
- "subWidgetsBounds"
+ "subWidgetsBounds",
+ "minimum",
+ "maximum"
] ),
propertyHandler : rwt.remote.HandlerUtil.extendControlPropertyHandler( {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeCalendar.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeCalendar.js
index 0d89220224..bbf1f948e1 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeCalendar.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeCalendar.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH.
* 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
@@ -109,6 +109,22 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeCalendar", {
this._calendar.setDate( date );
},
+ setMinimum : function( value ) {
+ var minimum = value === null ? null : new Date( value );
+ if( minimum ) {
+ minimum.setHours( 0, 0, 0, 0 );
+ }
+ this._calendar.setMinimum( minimum );
+ },
+
+ setMaximum : function( value ) {
+ var maximum = value === null ? null : new Date( value );
+ if( maximum ) {
+ maximum.setHours( 0, 0, 0, 0 );
+ }
+ this._calendar.setMaximum( maximum );
+ },
+
setFont : function() {
// TODO: [if] Calendar font is not implemented
}
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js
index 427cb91ccb..a563b8a86a 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeDate.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -257,30 +257,66 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
this._setFocusedTextField( event.getTarget() );
},
- _setFocusedTextField : function( textField ) {
+ _setFocusedTextField : function( textField ) {
if( this._focusedTextField !== textField ) {
this._focusedTextField.removeState( "selected" );
this._focusedTextField = null;
- if( textField === this._dayTextField ) {
- this._spinner.setMin( 1 );
- this._spinner.setMax( this._getDaysInMonth() );
- var tmpValue = this._removeLeadingZero( this._dayTextField.getText() );
- this._spinner.setValue( parseInt( tmpValue, 10 ) );
- } else if( textField === this._monthTextField ) {
- this._spinner.setMin( 1 );
- this._spinner.setMax( 12 );
- this._spinner.setValue( this._monthInt );
- } else if( textField === this._yearTextField ) {
- this._spinner.setMax( 9999 );
- this._spinner.setMin( 1752 );
- this._spinner.setValue( this._lastValidYear );
- }
+ this._applySpinnerValue( textField );
this._focusedTextField = textField;
this._focusedTextField.addState( "selected" );
this._initialEditing = true;
}
},
+ _applySpinnerValue : function( textField ) {
+ if( textField === this._dayTextField ) {
+ this._applyDaySpinnerValue();
+ } else if( textField === this._monthTextField ) {
+ this._applyMonthSpinnerValue();
+ } else if( textField === this._yearTextField ) {
+ this._applyYearSpinnerValue();
+ }
+ },
+
+ _applyDaySpinnerValue : function() {
+ this._spinner.setMin( 1 );
+ this._spinner.setMax( this._getDaysInMonth() );
+ if( this._minimum && this._minimum.getFullYear() === this._lastValidYear &&
+ this._minimum.getMonth() === this._monthInt - 1 ) {
+ this._spinner.setMin( this._minimum.getDate() );
+ }
+ if( this._maximum && this._maximum.getFullYear() === this._lastValidYear &&
+ this._maximum.getMonth() === this._monthInt - 1 ) {
+ this._spinner.setMax( this._maximum.getDate() );
+ }
+ var tmpValue = this._removeLeadingZero( this._dayTextField.getText() );
+ this._spinner.setValue( parseInt( tmpValue, 10 ) );
+ },
+
+ _applyMonthSpinnerValue : function() {
+ this._spinner.setMin( 1 );
+ this._spinner.setMax( 12 );
+ if( this._minimum && this._minimum.getFullYear() === this._lastValidYear ) {
+ this._spinner.setMin( this._minimum.getMonth() + 1 );
+ }
+ if( this._maximum && this._maximum.getFullYear() === this._lastValidYear ) {
+ this._spinner.setMax( this._maximum.getMonth() + 1 );
+ }
+ this._spinner.setValue( this._monthInt );
+ },
+
+ _applyYearSpinnerValue : function() {
+ this._spinner.setMax( 9999 );
+ this._spinner.setMin( 1752 );
+ if( this._minimum ) {
+ this._spinner.setMin( this._minimum.getFullYear() );
+ }
+ if( this._maximum ) {
+ this._spinner.setMax( this._maximum.getFullYear() );
+ }
+ this._spinner.setValue( this._lastValidYear );
+ },
+
_onSpinnerChange : function() {
if( this._focusedTextField != null ) {
var oldValue = this._focusedTextField.getText();
@@ -313,6 +349,22 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
if( oldValue != newValue ) {
this._sendChanges();
}
+ this._applyLimitRestriction();
+ }
+ },
+
+ _applyLimitRestriction : function() {
+ var day = parseInt( this._removeLeadingZero( this._dayTextField.getText() ) );
+ var date = new Date(this._lastValidYear, this._monthInt - 1, day);
+ if( this._minimum && date.getTime() < this._minimum.getTime() ) {
+ this.setYear( this._minimum.getFullYear() );
+ this.setMonth( this._minimum.getMonth() );
+ this.setDay( this._minimum.getDate() );
+ }
+ if( this._maximum && date.getTime() > this._maximum.getTime()) {
+ this.setYear( this._maximum.getFullYear() );
+ this.setMonth( this._maximum.getMonth() );
+ this.setDay( this._maximum.getDate() );
}
},
@@ -647,6 +699,30 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
this._setWeekday();
},
+ setMinimum : function( value ) {
+ this._minimum = value === null ? null : new Date( value );
+ if( this._minimum ) {
+ this._minimum.setHours( 0, 0, 0, 0 );
+ }
+ this._applySpinnerValue(this._focusedTextField);
+ this._applyLimitRestriction();
+ if( this._calendar ) {
+ this._calendar.setMinimum( this._minimum );
+ }
+ },
+
+ setMaximum : function( value ) {
+ this._maximum = value === null ? null : new Date( value );
+ if( this._maximum ) {
+ this._maximum.setHours( 0, 0, 0, 0 );
+ }
+ this._applySpinnerValue(this._focusedTextField);
+ this._applyLimitRestriction();
+ if( this._calendar ) {
+ this._calendar.setMaximum( this._maximum );
+ }
+ },
+
_setDate : function( date ) {
this.setYear( date.getFullYear() );
this.setMonth( date.getMonth() );
@@ -737,9 +813,11 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeDate", {
if( event.isLeftButtonPressed() ) {
var target = event.getTarget();
if( target.getUserData( "calendar-day" ) ) {
- this._calendar._onDayClicked( event );
- this._hideCalendar();
- this.setFocused( true );
+ if( !target.hasState( "disabled" ) ) {
+ this._calendar._onDayClicked( event );
+ this._hideCalendar();
+ this.setFocused( true );
+ }
} else if( target.getUserData( "calendar-button" ) ) {
this._calendar._onNavButtonClicked( event );
} else if( target === this._dropDownButton ) {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeTime.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeTime.js
index e2ff1ef449..f2bc5329b6 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeTime.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/DateTimeTime.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -152,31 +152,67 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeTime", {
_setFocusedTextField : function( textField ) {
if( this._focusedTextField !== textField ) {
- var tmpValue;
this._focusedTextField.removeState( "selected" );
this._focusedTextField = null;
- if( textField === this._hoursTextField ) {
- this._spinner.setMin( 0 );
- this._spinner.setMax( 23 );
- tmpValue = this._removeLeadingZero( this._hoursTextField.getText() );
- this._spinner.setValue( parseInt( tmpValue, 10 ) );
- } else if( textField === this._minutesTextField ) {
- this._spinner.setMin( 0 );
- this._spinner.setMax( 59 );
- tmpValue = this._removeLeadingZero( this._minutesTextField.getText() );
- this._spinner.setValue( parseInt( tmpValue, 10 ) );
- } else if( textField === this._secondsTextField ) {
- this._spinner.setMin( 0 );
- this._spinner.setMax( 59 );
- tmpValue = this._removeLeadingZero( this._secondsTextField.getText() );
- this._spinner.setValue( parseInt( tmpValue, 10 ) );
- }
+ this._applySpinnerValue( textField );
this._focusedTextField = textField;
this._focusedTextField.addState( "selected" );
this._initialEditing = true;
}
},
+ _applySpinnerValue : function( textField ) {
+ if( textField === this._hoursTextField ) {
+ this._applyHourSpinnerValue();
+ } else if( textField === this._minutesTextField ) {
+ this._applyMinuteSpinnerValue();
+ } else if( textField === this._secondsTextField ) {
+ this._applySecondSpinnerValue();
+ }
+ },
+
+ _applySecondSpinnerValue : function() {
+ this._spinner.setMin( 0 );
+ this._spinner.setMax( 59 );
+ var hour = parseInt( this._removeLeadingZero( this._hoursTextField.getText() ) );
+ var minute = parseInt( this._removeLeadingZero( this._minutesTextField.getText() ) );
+ if( this._minimum && this._minimum.getHours() === hour && this._minimum.getMinutes() === minute ) {
+ this._spinner.setMin( this._minimum.getSeconds() );
+ }
+ if( this._maximum && this._maximum.getHours() === hour && this._maximum.getMinutes() === minute ) {
+ this._spinner.setMax( this._maximum.getSeconds() );
+ }
+ var tmpValue = this._removeLeadingZero( this._secondsTextField.getText() );
+ this._spinner.setValue( parseInt( tmpValue, 10 ) );
+ },
+
+ _applyMinuteSpinnerValue : function() {
+ this._spinner.setMin( 0 );
+ this._spinner.setMax( 59 );
+ var hour = parseInt( this._removeLeadingZero( this._hoursTextField.getText() ) );
+ if( this._minimum && this._minimum.getHours() === hour ) {
+ this._spinner.setMin( this._minimum.getMinutes() );
+ }
+ if( this._maximum && this._maximum.getHours() === hour ) {
+ this._spinner.setMax( this._maximum.getMinutes() );
+ }
+ var tmpValue = this._removeLeadingZero( this._minutesTextField.getText() );
+ this._spinner.setValue( parseInt( tmpValue, 10 ) );
+ },
+
+ _applyHourSpinnerValue : function() {
+ this._spinner.setMin( 0 );
+ this._spinner.setMax( 23 );
+ if( this._minimum ) {
+ this._spinner.setMin( this._minimum.getHours() );
+ }
+ if( this._maximum ) {
+ this._spinner.setMax( this._maximum.getHours() );
+ }
+ var tmpValue = this._removeLeadingZero( this._hoursTextField.getText() );
+ this._spinner.setValue( parseInt( tmpValue, 10 ) );
+ },
+
_onSpinnerChange : function() {
if( this._focusedTextField != null ) {
var oldValue = this._focusedTextField.getText();
@@ -185,6 +221,24 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeTime", {
if( oldValue != newValue ) {
this._sendChanges();
}
+ this._applyLimitRestriction();
+ }
+ },
+
+ _applyLimitRestriction : function() {
+ var hour = parseInt( this._removeLeadingZero( this._hoursTextField.getText() ) );
+ var minute = parseInt( this._removeLeadingZero( this._minutesTextField.getText() ) );
+ var second = parseInt( this._removeLeadingZero( this._secondsTextField.getText() ) );
+ var date = new Date( 1970, 0, 1, hour, minute, second );
+ if ( this._minimum && date.getTime() < this._minimum.getTime() ) {
+ this.setHours( this._minimum.getHours() );
+ this.setMinutes( this._minimum.getMinutes() );
+ this.setSeconds( this._minimum.getSeconds() );
+ }
+ if ( this._maximum && date.getTime() > this._maximum.getTime()) {
+ this.setHours( this._maximum.getHours() );
+ this.setMinutes( this._maximum.getMinutes() );
+ this.setSeconds( this._maximum.getSeconds() );
}
},
@@ -386,6 +440,26 @@ rwt.qx.Class.define( "rwt.widgets.DateTimeTime", {
}
},
+ setMinimum : function( value ) {
+ this._minimum = value === null ? null : new Date( value );
+ if( this._minimum ) {
+ this._minimum.setYear( 1970 );
+ this._minimum.setMonth( 0 );
+ this._minimum.setDate( 1 );
+ }
+ this._applyLimitRestriction();
+ },
+
+ setMaximum : function( value ) {
+ this._maximum = value === null ? null : new Date( value );
+ if( this._maximum ) {
+ this._maximum.setYear( 1970 );
+ this._maximum.setMonth( 0 );
+ this._maximum.setDate( 1 );
+ }
+ this._applyLimitRestriction();
+ },
+
setBounds : function( index, x, y, width, height ) {
var widget;
switch( index ) {
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/Calendar.js b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/Calendar.js
index ab502df19f..6135dce36a 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/Calendar.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/widgets/base/Calendar.js
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH.
* 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
@@ -274,6 +274,20 @@ rwt.qx.Class.define("rwt.widgets.base.Calendar", {
apply : "_applyDate",
event : "changeDate",
transform : "_checkDate"
+ },
+
+ minimum : {
+ check : "Date",
+ init : null,
+ nullable : true,
+ apply : "_applyMinimum"
+ },
+
+ maximum : {
+ check : "Date",
+ init : null,
+ nullable : true,
+ apply : "_applyMaximum"
}
},
@@ -405,7 +419,7 @@ rwt.qx.Class.define("rwt.widgets.base.Calendar", {
* @return {void}
*/
_onDayClicked : function(evt) {
- if( evt.isLeftButtonPressed() ) {
+ if( evt.isLeftButtonPressed() && !evt.getTarget().hasState("disabled") ) {
var time = evt.getTarget().dateTime;
this.setDate(new Date(time));
}
@@ -609,7 +623,7 @@ rwt.qx.Class.define("rwt.widgets.base.Calendar", {
}
// Show the days
- helpDate = new Date(shownYear, shownMonth, 1);
+ helpDate = new Date( shownYear, shownMonth, 1 );
var nrDaysOfLastMonth = (7 + firstDayOfWeek - startOfWeek) % 7;
helpDate.setDate(helpDate.getDate() - nrDaysOfLastMonth);
@@ -622,13 +636,18 @@ rwt.qx.Class.define("rwt.widgets.base.Calendar", {
var year = helpDate.getFullYear();
var month = helpDate.getMonth();
var dayOfMonth = helpDate.getDate();
+ var minimum = this.getMinimum();
+ var maximum = this.getMaximum();
+ var isBeforeMinimumLimit = minimum && helpDate.getTime() < minimum.getTime();
+ var isAfterMaximumLimit = maximum && helpDate.getTime() > maximum.getTime();
var isSelectedDate = (selYear == year && selMonth == month && selDayOfMonth == dayOfMonth);
var isToday = (year == todayYear && month == todayMonth && dayOfMonth == todayDayOfMonth);
dayLabel.toggleState( "selected", isSelectedDate );
dayLabel.toggleState( "otherMonth", month != shownMonth );
dayLabel.toggleState( "today", isToday );
+ dayLabel.toggleState( "disabled", isBeforeMinimumLimit || isAfterMaximumLimit );
dayLabel.setText("" + dayOfMonth);
dayLabel.dateTime = helpDate.getTime();
@@ -864,6 +883,14 @@ rwt.qx.Class.define("rwt.widgets.base.Calendar", {
__getTerritory : function() {
var territory = rwt.client.Client.getTerritory() || rwt.client.Client.getLanguage();
return territory.toUpperCase();
+ },
+
+ _applyMinimum : function() {
+ this._updateDatePane();
+ },
+
+ _applyMaximum : function() {
+ this._updateDatePane();
}
},
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
index 922259436e..f58e686eea 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/DateTime.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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 @@ import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;
@@ -158,6 +159,9 @@ public class DateTime extends Composite {
private final Point cellSize;
private transient IDateTimeAdapter dateTimeAdapter;
private final Calendar rightNow;
+ private Date minimum;
+ private Date maximum;
+ private boolean ignoreLimits;
// Date fields
private Rectangle weekdayTextFieldBounds;
private Rectangle dayTextFieldBounds;
@@ -403,6 +407,40 @@ public class DateTime extends Composite {
}
/**
+ * Returns the minimum value which the receiver will allow or null if no minimum limit is applied.
+ *
+ * @return the minimum value
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the
+ * receiver</li>
+ * </ul>
+ * @since 3.2
+ */
+ public Date getMinimum() {
+ checkWidget();
+ return minimum;
+ }
+
+ /**
+ * Returns the maximum value which the receiver will allow or null if no maximum limit is applied.
+ *
+ * @return the maximum value
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the
+ * receiver</li>
+ * </ul>
+ * @since 3.2
+ */
+ public Date getMaximum() {
+ checkWidget();
+ return maximum;
+ }
+
+ /**
* Sets the receiver's hours.
* <p>
* Hours is an integer between 0 and 23.
@@ -420,6 +458,7 @@ public class DateTime extends Composite {
checkWidget();
if( checkTime( hours, getMinutes(), getSeconds() ) ) {
rightNow.set( Calendar.HOUR_OF_DAY, hours );
+ applyLimits();
}
}
@@ -441,6 +480,7 @@ public class DateTime extends Composite {
checkWidget();
if( checkTime( getHours(), minutes, getSeconds() ) ) {
rightNow.set( Calendar.MINUTE, minutes );
+ applyLimits();
}
}
@@ -462,6 +502,7 @@ public class DateTime extends Composite {
checkWidget();
if( checkTime( getHours(), getMinutes(), seconds ) ) {
rightNow.set( Calendar.SECOND, seconds );
+ applyLimits();
}
}
@@ -486,6 +527,7 @@ public class DateTime extends Composite {
int year = rightNow.get( Calendar.YEAR );
if( checkDate( year, month, day ) ) {
rightNow.set( Calendar.DATE, day );
+ applyLimits();
}
}
@@ -509,6 +551,7 @@ public class DateTime extends Composite {
int year = rightNow.get( Calendar.YEAR );
if( checkDate( year, month, day ) ) {
rightNow.set( Calendar.MONTH, month );
+ applyLimits();
}
}
@@ -532,6 +575,49 @@ public class DateTime extends Composite {
int month = rightNow.get( Calendar.MONTH );
if( checkDate( year, month, day ) ) {
rightNow.set( Calendar.YEAR, year );
+ applyLimits();
+ }
+ }
+
+ /**
+ * Sets the minimum value. If this value is greater than or equal to the maximum, the value is
+ * ignored.
+ *
+ * @param date the new minimum
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the
+ * receiver</li>
+ * </ul>
+ * @since 3.2
+ */
+ public void setMinimum( Date date ) {
+ checkWidget();
+ if( date == null || maximum == null || date.getTime() < maximum.getTime() ) {
+ minimum = date;
+ applyLimits();
+ }
+ }
+
+ /**
+ * Sets the maximum value. If this value is lower than or equal to the minimum, the value is
+ * ignored.
+ *
+ * @param date the new maximum
+ * @exception SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the
+ * receiver</li>
+ * </ul>
+ * @since 3.2
+ */
+ public void setMaximum( Date date ) {
+ checkWidget();
+ if( date == null || minimum == null || date.getTime() > minimum.getTime() ) {
+ maximum = date;
+ applyLimits();
}
}
@@ -558,6 +644,7 @@ public class DateTime extends Composite {
checkWidget();
if( checkDate( year, month, day ) ) {
// reset
+ ignoreLimits = true;
setYear( 9996 );
setMonth( 0 );
setDay( 1 );
@@ -565,6 +652,8 @@ public class DateTime extends Composite {
setYear( year );
setMonth( month );
setDay( day );
+ ignoreLimits = false;
+ applyLimits();
}
}
@@ -1049,4 +1138,15 @@ public class DateTime extends Composite {
return style;
}
+ private void applyLimits() {
+ if( !ignoreLimits ) {
+ if( maximum != null && rightNow.getTimeInMillis() > maximum.getTime() ) {
+ rightNow.setTime( maximum );
+ }
+ if( minimum != null && rightNow.getTimeInMillis() < minimum.getTime() ) {
+ rightNow.setTime( minimum );
+ }
+ }
+ }
+
}
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java
index d626ba21cc..1b8fa4e424 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeCalendarLCA.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -33,6 +33,7 @@ final class DateTimeCalendarLCA extends AbstractDateTimeLCADelegate {
preserveProperty( dateTime, PROP_YEAR, dateTime.getYear() );
preserveProperty( dateTime, PROP_MONTH, dateTime.getMonth() );
preserveProperty( dateTime, PROP_DAY, dateTime.getDay() );
+ DateTimeLCAUtil.preserveMinMaxLimit( dateTime );
}
@Override
@@ -49,6 +50,7 @@ final class DateTimeCalendarLCA extends AbstractDateTimeLCADelegate {
renderProperty( dateTime, PROP_YEAR, dateTime.getYear(), SWT.DEFAULT );
renderProperty( dateTime, PROP_MONTH, dateTime.getMonth(), SWT.DEFAULT );
renderProperty( dateTime, PROP_DAY, dateTime.getDay(), SWT.DEFAULT );
+ DateTimeLCAUtil.renderMinMaxLimit( dateTime );
}
private DateTimeCalendarLCA() {
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java
index 1e073ec9d4..2c65527f0d 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeDateLCA.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -36,6 +36,7 @@ final class DateTimeDateLCA extends AbstractDateTimeLCADelegate {
preserveProperty( dateTime, PROP_MONTH, dateTime.getMonth() );
preserveProperty( dateTime, PROP_DAY, dateTime.getDay() );
DateTimeLCAUtil.preserveSubWidgetsBounds( dateTime, getSubWidgetsBounds( dateTime ) );
+ DateTimeLCAUtil.preserveMinMaxLimit( dateTime );
}
@Override
@@ -56,6 +57,7 @@ final class DateTimeDateLCA extends AbstractDateTimeLCADelegate {
renderProperty( dateTime, PROP_MONTH, dateTime.getMonth(), SWT.DEFAULT );
renderProperty( dateTime, PROP_DAY, dateTime.getDay(), SWT.DEFAULT );
DateTimeLCAUtil.renderSubWidgetsBounds( dateTime, getSubWidgetsBounds( dateTime ) );
+ DateTimeLCAUtil.renderMinMaxLimit( dateTime );
}
///////////////////////////////////////////////////
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java
index f8ab5dd704..1bcb5857d7 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCAUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -21,7 +21,10 @@ import static org.eclipse.rap.rwt.internal.protocol.JsonUtil.createJsonArray;
import static org.eclipse.rap.rwt.internal.protocol.RemoteObjectFactory.createRemoteObject;
import static org.eclipse.rap.rwt.internal.protocol.RemoteObjectFactory.getRemoteObject;
+import java.util.Date;
+
import org.eclipse.rap.json.JsonArray;
+import org.eclipse.rap.json.JsonValue;
import org.eclipse.rap.rwt.internal.lifecycle.ControlLCAUtil;
import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil;
import org.eclipse.rap.rwt.internal.util.ParamCheck;
@@ -46,6 +49,8 @@ final class DateTimeLCAUtil {
private static final String PROP_DATE_SEPARATOR = "dateSeparator";
private static final String PROP_DATE_PATTERN = "datePattern";
private static final String PROP_SUB_WIDGETS_BOUNDS = "subWidgetsBounds";
+ private static final String PROP_MINIMUM = "minimum";
+ private static final String PROP_MAXIMUM = "maximum";
private DateTimeLCAUtil() {
// prevent instantiation
@@ -99,6 +104,25 @@ final class DateTimeLCAUtil {
getRemoteObject( dateTime ).set( PROP_DATE_PATTERN, datePattern );
}
+ static void preserveMinMaxLimit( DateTime dateTime ) {
+ preserveProperty( dateTime, PROP_MINIMUM, getMinLimit( dateTime ) );
+ preserveProperty( dateTime, PROP_MAXIMUM, getMaxLimit( dateTime ) );
+ }
+
+ static void renderMinMaxLimit( DateTime dateTime ) {
+ RemoteObject remoteObject = getRemoteObject( dateTime );
+ Long minimum = getMinLimit( dateTime );
+ if( hasChanged( dateTime, PROP_MINIMUM, minimum, null ) ) {
+ JsonValue value = minimum == null ? JsonValue.NULL : JsonValue.valueOf( minimum.longValue() );
+ remoteObject.set( PROP_MINIMUM, value );
+ }
+ Long maximum = getMaxLimit( dateTime );
+ if( hasChanged( dateTime, PROP_MAXIMUM, maximum, null ) ) {
+ JsonValue value = maximum == null ? JsonValue.NULL : JsonValue.valueOf( maximum.longValue() );
+ remoteObject.set( PROP_MAXIMUM, value );
+ }
+ }
+
static void preserveSubWidgetsBounds( DateTime dateTime, SubWidgetBounds[] subWidgetBounds ) {
preserveProperty( dateTime, PROP_SUB_WIDGETS_BOUNDS, subWidgetBounds );
}
@@ -126,6 +150,16 @@ final class DateTimeLCAUtil {
return dateTime.getAdapter( IDateTimeAdapter.class );
}
+ private static Long getMinLimit( DateTime dateTime ) {
+ Date minimum = dateTime.getMinimum();
+ return minimum == null ? null : Long.valueOf( minimum.getTime() );
+ }
+
+ private static Long getMaxLimit( DateTime dateTime ) {
+ Date maximum = dateTime.getMaximum();
+ return maximum == null ? null : Long.valueOf( maximum.getTime() );
+ }
+
static final class SubWidgetBounds {
public final int id;
public final int x;
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java
index d09e900b69..75e73b421f 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/datetimekit/DateTimeTimeLCA.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -35,6 +35,7 @@ final class DateTimeTimeLCA extends AbstractDateTimeLCADelegate {
preserveProperty( dateTime, PROP_MINUTES, dateTime.getMinutes() );
preserveProperty( dateTime, PROP_SECONDS, dateTime.getSeconds() );
DateTimeLCAUtil.preserveSubWidgetsBounds( dateTime, getSubWidgetsBounds( dateTime ) );
+ DateTimeLCAUtil.preserveMinMaxLimit( dateTime );
}
@Override
@@ -49,6 +50,7 @@ final class DateTimeTimeLCA extends AbstractDateTimeLCADelegate {
renderProperty( dateTime, PROP_MINUTES, dateTime.getMinutes(), SWT.DEFAULT );
renderProperty( dateTime, PROP_SECONDS, dateTime.getSeconds(), SWT.DEFAULT );
DateTimeLCAUtil.renderSubWidgetsBounds( dateTime, getSubWidgetsBounds( dateTime ) );
+ DateTimeLCAUtil.renderMinMaxLimit( dateTime );
}
///////////////////////////////////////////////////
diff --git a/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DateTimeTab.java b/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DateTimeTab.java
index c29482efb5..c57b562eb6 100644
--- a/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DateTimeTab.java
+++ b/examples/org.eclipse.rap.demo.controls/src/org/eclipse/rap/demo/controls/DateTimeTab.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -11,17 +11,23 @@
******************************************************************************/
package org.eclipse.rap.demo.controls;
+import java.util.Calendar;
+
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
@@ -32,7 +38,7 @@ class DateTimeTab extends ExampleTab {
private static final String PROP_SELECTION_LISTENER = "selectionListener";
private DateTime dateTime;
- private Group group1, group2;
+ private Group group1, group2, group3;
DateTimeTab() {
super( "DateTime" );
@@ -63,6 +69,10 @@ class DateTimeTab extends ExampleTab {
createBgColorButton();
createPropertyCheckbox( "Add Context Menu", PROP_CONTEXT_MENU );
createPropertyCheckbox( "Add Selection Listener", PROP_SELECTION_LISTENER );
+ group3 = new Group( parent, SWT.NONE );
+ group3.setText( "Min/Max Limit" );
+ group3.setLayout( new GridLayout( 3, false ) );
+ createMinMaxLimit( group3 );
}
@Override
@@ -128,6 +138,48 @@ class DateTimeTab extends ExampleTab {
return button;
}
+ private void createMinMaxLimit( Composite parent ) {
+ Label minLabel = new Label(parent, SWT.NONE);
+ minLabel.setText( "Minimum" );
+ DateTime minDate = new DateTime( parent, SWT.DATE | SWT.MEDIUM | SWT.BORDER );
+ DateTime minTime = new DateTime( parent, SWT.TIME | SWT.SHORT | SWT.BORDER );
+ Label maxLabel = new Label(parent, SWT.NONE);
+ maxLabel.setText( "Maximum" );
+ DateTime maxDate = new DateTime( parent, SWT.DATE | SWT.MEDIUM | SWT.BORDER );
+ DateTime maxTime = new DateTime( parent, SWT.TIME | SWT.SHORT | SWT.BORDER );
+ Button clearButton = new Button( group3, SWT.PUSH );
+ clearButton.setText( "Clear" );
+ clearButton.addListener( SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent( Event event ) {
+ dateTime.setMinimum( null );
+ dateTime.setMaximum( null );
+ }
+ } );
+ Button applyButton = new Button( group3, SWT.PUSH );
+ applyButton.setText( "Apply" );
+ applyButton.addListener( SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent( Event event ) {
+ Calendar limit = Calendar.getInstance();
+ limit.set( minDate.getYear(),
+ minDate.getMonth(),
+ minDate.getDay(),
+ minTime.getHours(),
+ minTime.getMinutes(),
+ minTime.getSeconds() );
+ dateTime.setMinimum( limit.getTime() );
+ limit.set( maxDate.getYear(),
+ maxDate.getMonth(),
+ maxDate.getDay(),
+ maxTime.getHours(),
+ maxTime.getMinutes(),
+ maxTime.getSeconds() );
+ dateTime.setMaximum( limit.getTime() );
+ }
+ } );
+ }
+
protected int getStyle( Composite comp ) {
int result = SWT.NONE;
if( checkControl( comp ) ) {
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeCalendarTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeCalendarTest.js
index e5bdffb6ab..73e952a7bc 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeCalendarTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeCalendarTest.js
@@ -88,6 +88,22 @@ rwt.qx.Class.define( "org.eclipse.rwt.test.tests.DateTimeCalendarTest", {
widget.destroy();
},
+ testSetMinimumByProtocol : function() {
+ var widget = this._createDefaultDateTimeByProtocol( "w3", "w2" );
+ var date = new Date( 1999, 0, 1, 0, 0, 0, 0 );
+ TestUtil.protocolSet( "w3", { "minimum" : date.getTime() } );
+ assertEquals( date.getTime(), widget._calendar.getMinimum().getTime() );
+ widget.destroy();
+ },
+
+ testSetMaximumByProtocol : function() {
+ var widget = this._createDefaultDateTimeByProtocol( "w3", "w2" );
+ var date = new Date( 2050, 0, 1, 0, 0, 0, 0 );
+ TestUtil.protocolSet( "w3", { "maximum" : date.getTime() } );
+ assertEquals( date.getTime(), widget._calendar.getMaximum().getTime() );
+ widget.destroy();
+ },
+
// see bug 401780
testKeypressEscape : function() {
var widget = this._createDefaultDateTimeByProtocol( "w3", "w2" );
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeDateTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeDateTest.js
index eae1accd27..729394b03d 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeDateTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeDateTest.js
@@ -105,6 +105,22 @@ rwt.qx.Class.define( "org.eclipse.rwt.test.tests.DateTimeDateTest", {
widget.destroy();
},
+ testSetMinimumByProtocol : function() {
+ var widget = this._createDefaultDateTimeByProtocol( "w3", "w2", true );
+ var date = new Date( 2000, 0, 1, 0, 0, 0, 0 );
+ TestUtil.protocolSet( "w3", { "minimum" : date.getTime() } );
+ assertEquals( date.getTime(), widget._minimum.getTime() );
+ widget.destroy();
+ },
+
+ testSetMaximumByProtocol : function() {
+ var widget = this._createDefaultDateTimeByProtocol( "w3", "w2", true );
+ var date = new Date( 2090, 0, 1, 0, 0, 0, 0 );
+ TestUtil.protocolSet( "w3", { "maximum" : date.getTime() } );
+ assertEquals( date.getTime(), widget._maximum.getTime() );
+ widget.destroy();
+ },
+
testSetSubWidgetsBoundsByProtocol : function() {
var widget = this._createDefaultDateTimeByProtocol( "w3", "w2", true );
TestUtil.protocolSet( "w3", { "subWidgetsBounds" : [ [ 0, 3, 5, 0, 18 ],
diff --git a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeTimeTest.js b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeTimeTest.js
index e5398409bf..e08316cbf9 100644
--- a/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeTimeTest.js
+++ b/tests/org.eclipse.rap.rwt.jstest/js/org/eclipse/rwt/test/tests/DateTimeTimeTest.js
@@ -107,6 +107,48 @@ rwt.qx.Class.define( "org.eclipse.rwt.test.tests.DateTimeTimeTest", {
widget.destroy();
},
+ testSetMinimumByProtocol : function() {
+ var minimum = 1000;
+ var minimumDate = new Date( minimum );
+ var time = new Date(1970, 0, 1, minimumDate.getHours(), minimumDate.getMinutes(), minimumDate.getSeconds());
+
+ Processor.processOperation( {
+ "target" : "w3",
+ "action" : "create",
+ "type" : "rwt.widgets.DateTime",
+ "properties" : {
+ "style" : [ "TIME", "MEDIUM" ],
+ "parent" : "w2",
+ "minimum" : minimum
+ }
+ } );
+ var widget = ObjectRegistry.getObject( "w3" );
+
+ assertEquals( time.getTime(), widget._minimum.getTime() );
+ widget.destroy();
+ },
+
+ testSetMaximumByProtocol : function() {
+ var maximum = 99000;
+ var maximumDate = new Date( maximum );
+ var time = new Date(1970, 0, 1, maximumDate.getHours(), maximumDate.getMinutes(), maximumDate.getSeconds());
+
+ Processor.processOperation( {
+ "target" : "w3",
+ "action" : "create",
+ "type" : "rwt.widgets.DateTime",
+ "properties" : {
+ "style" : [ "TIME", "MEDIUM" ],
+ "parent" : "w2",
+ "maximum" : maximum
+ }
+ } );
+ var widget = ObjectRegistry.getObject( "w3" );
+
+ assertEquals( time.getTime(), widget._maximum.getTime() );
+ widget.destroy();
+ },
+
testSetSubWidgetsBoundsByProtocol : function() {
Processor.processOperation( {
"target" : "w3",
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java
index 057bc6ac45..f0f604ea9b 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/datetimekit/DateTimeLCA_Test.java
@@ -16,6 +16,7 @@ import static org.eclipse.rap.rwt.internal.protocol.RemoteObjectFactory.getRemot
import static org.eclipse.rap.rwt.testfixture.internal.TestMessage.getParent;
import static org.eclipse.rap.rwt.testfixture.internal.TestMessage.getStyles;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -23,6 +24,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.util.Date;
import java.util.List;
import org.eclipse.rap.json.JsonArray;
@@ -423,6 +425,110 @@ public class DateTimeLCA_Test {
}
@Test
+ public void testRenderInitialMinimum() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+
+ lca.render( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ CreateOperation operation = message.findCreateOperation( dateTime );
+ assertFalse( operation.getProperties().names().contains( "minimum" ) );
+ }
+
+ @Test
+ public void testRenderMinimum() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Date date = new Date();
+
+ dateTime.setMinimum( date );
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( date.getTime(), message.findSetProperty( dateTime, "minimum" ).asLong() );
+ }
+
+ @Test
+ public void testRenderMinimumUnchanged() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( dateTime );
+
+ dateTime.setMinimum( new Date() );
+ Fixture.preserveWidgets();
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertNull( message.findSetOperation( dateTime, "minimum" ) );
+ }
+
+ @Test
+ public void testRenderMinimumReset() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( dateTime );
+
+ dateTime.setMinimum( new Date() );
+ Fixture.preserveWidgets();
+ dateTime.setMinimum( null );
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( JsonValue.NULL, message.findSetProperty( dateTime, "minimum" ) );
+ }
+
+ @Test
+ public void testRenderInitialMaximum() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+
+ lca.render( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ CreateOperation operation = message.findCreateOperation( dateTime );
+ assertFalse( operation.getProperties().names().contains( "maximum" ) );
+ }
+
+ @Test
+ public void testRenderMaximum() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Date date = new Date();
+
+ dateTime.setMaximum( date );
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( date.getTime(), message.findSetProperty( dateTime, "maximum" ).asLong() );
+ }
+
+ @Test
+ public void testRenderMaximumUnchanged() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( dateTime );
+
+ dateTime.setMaximum( new Date() );
+ Fixture.preserveWidgets();
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertNull( message.findSetOperation( dateTime, "maximum" ) );
+ }
+
+ @Test
+ public void testRenderMaximumReset() throws IOException {
+ DateTime dateTime = new DateTime( shell, SWT.DATE );
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( dateTime );
+
+ dateTime.setMaximum( new Date() );
+ Fixture.preserveWidgets();
+ dateTime.setMaximum( null );
+ lca.renderChanges( dateTime );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( JsonValue.NULL, message.findSetProperty( dateTime, "maximum" ) );
+ }
+
+ @Test
public void testRenderInitialSubWidgetsBounds_Date() throws IOException {
DateTime dateTime = new DateTime( shell, SWT.DATE );
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
index 4bb1f18d85..56b3b0ad2d 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DateTime_Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2008, 2017 Innoopract Informationssysteme GmbH 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
@@ -20,6 +20,9 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Locale;
import org.eclipse.rap.rwt.RWT;
@@ -45,12 +48,14 @@ public class DateTime_Test {
private Shell shell;
private DateTime dateTime;
+ SimpleDateFormat formatter;
@Before
public void setUp() {
Display display = new Display();
shell = new Shell( display, SWT.NONE );
dateTime = new DateTime( shell, SWT.NONE );
+ formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
@Test
@@ -127,6 +132,170 @@ public class DateTime_Test {
}
@Test
+ public void testSetMininum() throws ParseException {
+ Date minimum = formatter.parse( "1985-10-29 11:00:00" );
+
+ dateTime.setMinimum( minimum );
+
+ assertEquals( minimum, dateTime.getMinimum() );
+ }
+
+ @Test
+ public void testSetMininum_limitsDate() throws ParseException {
+ dateTime.setDate( 1984, 8, 28 );
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
+
+ assertEquals( 29, dateTime.getDay() );
+ assertEquals( 9, dateTime.getMonth() );
+ assertEquals( 1985, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMininum_limitsYear() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
+ dateTime.setDate( 1984, 10, 29 );
+
+ assertEquals( 29, dateTime.getDay() );
+ assertEquals( 9, dateTime.getMonth() );
+ assertEquals( 1985, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMininum_limitsMonth() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
+ dateTime.setDate( 1985, 5, 29 );
+
+ assertEquals( 29, dateTime.getDay() );
+ assertEquals( 9, dateTime.getMonth() );
+ assertEquals( 1985, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMininum_limitsDay() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:00:00" ) );
+ dateTime.setDate( 1985, 9, 28 );
+
+ assertEquals( 29, dateTime.getDay() );
+ assertEquals( 9, dateTime.getMonth() );
+ assertEquals( 1985, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMininum_limitsHour() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
+ dateTime.setDate( 1985, 9, 28 );
+ dateTime.setTime( 10, 22, 33 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
+ public void testSetMininum_limitsMinute() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
+ dateTime.setDate( 1985, 9, 28 );
+ dateTime.setTime( 11, 21, 33 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
+ public void testSetMininum_limitsSecond() throws ParseException {
+ dateTime.setMinimum( formatter.parse( "1985-10-29 11:22:33" ) );
+ dateTime.setDate( 1985, 9, 28 );
+ dateTime.setTime( 11, 22, 32 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
+ public void testSetMaximum() throws ParseException {
+ Date maximum = formatter.parse( "2020-03-15 11:00:00" );
+
+ dateTime.setMaximum( maximum );
+
+ assertEquals( maximum, dateTime.getMaximum() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsDate() throws ParseException {
+ dateTime.setDate( 2021, 3, 16 );
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:00:00" ) );
+
+ assertEquals( 15, dateTime.getDay() );
+ assertEquals( 2, dateTime.getMonth() );
+ assertEquals( 2020, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsYear() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:00:00" ) );
+ dateTime.setDate( 2021, 2, 15 );
+
+ assertEquals( 15, dateTime.getDay() );
+ assertEquals( 2, dateTime.getMonth() );
+ assertEquals( 2020, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsMonth() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:00:00" ) );
+ dateTime.setDate( 2020, 3, 15 );
+
+ assertEquals( 15, dateTime.getDay() );
+ assertEquals( 2, dateTime.getMonth() );
+ assertEquals( 2020, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsDay() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:00:00" ) );
+ dateTime.setDate( 2020, 2, 16 );
+
+ assertEquals( 15, dateTime.getDay() );
+ assertEquals( 2, dateTime.getMonth() );
+ assertEquals( 2020, dateTime.getYear() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsHour() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:22:33" ) );
+ dateTime.setDate( 2020, 2, 16 );
+ dateTime.setTime( 12, 22, 33 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsMinute() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:22:33" ) );
+ dateTime.setDate( 2020, 2, 16 );
+ dateTime.setTime( 11, 23, 33 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
+ public void testSetMaximum_limitsSecond() throws ParseException {
+ dateTime.setMaximum( formatter.parse( "2020-03-15 11:22:33" ) );
+ dateTime.setDate( 2020, 2, 16 );
+ dateTime.setTime( 11, 23, 34 );
+
+ assertEquals( 11, dateTime.getHours() );
+ assertEquals( 22, dateTime.getMinutes() );
+ assertEquals( 33, dateTime.getSeconds() );
+ }
+
+ @Test
public void testSetDate() {
dateTime.setDate( 1985, 10, 29 );
assertEquals( 29, dateTime.getDay() );

Back to the top