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 /bundles
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>
Diffstat (limited to 'bundles')
-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
10 files changed, 385 insertions, 48 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 );
}
///////////////////////////////////////////////////

Back to the top