org.eclipse.ercp.swt.mobile
Class DateEditor

java.lang.Object
  extended byorg.eclipse.swt.widgets.Widget
      extended byorg.eclipse.swt.widgets.Control
          extended byorg.eclipse.ercp.swt.mobile.DateEditor
All Implemented Interfaces:
Drawable

public class DateEditor
extends Control

A special data entry control that allows users to enter or choose a date. The return value of getDate() is an instance of a Date class.

The default locale and timezone for the date and time formatting reflects the current configuration in the device. The default date used if a date is not set is the current date. Applications may call setTimeZone(timeZone) to change the differential added to UTC time. This change only affects the widget instance and does not affect other applications.

Example code

 DateEditor date1 = new DateEditor(composite, SWT.BORDER, DateEditor.DATE_TIME);
 date1.setDate((new Date()));
 
DateEditor styles:
DATE: year, month and day
TIME: hours, minutes and seconds
DATE_TIME: date and time
DURATION: a period of time in hours, minutes and seconds. If the platform does not support a unique appearance, the control will have the same appearance used for TIME style.
OFFSET: a period of time in hours, minutes, and seconds which can be subtracted or added to another time value. Usually a control with this style has a different appearance with positive or negative signs being used. If not, the control will have the same appearance used for TIME style.
COMPACT: a hint to display a smaller or less full featured widget which perhaps de-emphasizes ease of use in order to save space.
FULL: a hint to display a full size or full capability widget which perhaps emphasizes ease of use.
Note: The ability to enter seconds is platform-specific.
Events:
Selection, DefaultSelection, Modify

IMPORTANT: This class is not intended to be subclassed.


Field Summary
static int COMPACT
          A hint that the widget should be displayed in a format which is smaller or less full featured.
static int DATE
          A date entry type for year, month and day.
static int DATE_TIME
          An entry type for date and time.
static int DURATION
          An entry type for a period of time in hours, minutes and seconds.
static int FULL
          A hint that the widget should be displayed in a format which is full featured and emphasizes ease of use rather than compactness.
static int OFFSET
          An entry type for a period of time in hours, minutes, and seconds which can be subtracted or added to another time value.
static int TIME
          A time entry type for hours, minutes and seconds.
 
Constructor Summary
DateEditor(Composite parent, int style)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
DateEditor(Composite parent, int style, int dateEditorStyle)
          Constructs a new instance of this class given its parent, a style value describing its appearance, and a widget-specific style describing its behavior.
 
Method Summary
 void addModifyListener(ModifyListener listener)
          Adds the listener to the collection of listeners that will be notified when the receiver's content is modified.
 void addSelectionListener(SelectionListener listener)
          Adds the listener to the collection of listeners that will be notified when the control is selected.
 java.util.Date getDate()
          Returns the date when DATE, TIME or DATE_TIME styles are used.
 int getTime()
          Returns the number of seconds when TIME, OFFSET or DURATION styles are used.
 void removeModifyListener(ModifyListener listener)
          Removes the listener from the collection of listeners that will be notified when the receiver's text is modified.
 void removeSelectionListener(SelectionListener listener)
          Removes the listener from the collection of listeners that will be notified when the control is selected.
 void setDate(java.util.Date date)
          Sets the date for the editor when DATE, TIME or DATE_TIME styles are used.
 void setTime(int seconds)
          Sets the time for the editor when TIME, OFFSET or DURATION styles are used.
 void setTimeZone(java.util.TimeZone timeZone)
          Defines the time zone, which is applied on the DateEditor (which is UTC time).
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addKeyListener, addMouseListener, addMouseMoveListener, addPaintListener, addTraverseListener, computeSize, computeSize, forceFocus, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getParent, getShell, getSize, getToolTipText, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setEnabled, setFocus, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DATE

public static final int DATE
A date entry type for year, month and day.

Value 1 is assigned to DATE.

See Also:
Constant Field Values

TIME

public static final int TIME
A time entry type for hours, minutes and seconds.

Value 2 is assigned to TIME.

See Also:
Constant Field Values

DATE_TIME

public static final int DATE_TIME
An entry type for date and time.

Value 3 is assigned to DATE_TIME.

See Also:
Constant Field Values

DURATION

public static final int DURATION
An entry type for a period of time in hours, minutes and seconds.

Value 4 is assigned to DURATION.

See Also:
Constant Field Values

OFFSET

public static final int OFFSET
An entry type for a period of time in hours, minutes, and seconds which can be subtracted or added to another time value. Usually a control with this style has a different appearance. Positive or negative signs are used in this style.

Value 5 is assigned to OFFSET.

See Also:
Constant Field Values

COMPACT

public static final int COMPACT
A hint that the widget should be displayed in a format which is smaller or less full featured. It may de-emphasizes ease of use in order to use the least amount of screen space.

Value 0x10 is assigned to COMPACT.

See Also:
Constant Field Values

FULL

public static final int FULL
A hint that the widget should be displayed in a format which is full featured and emphasizes ease of use rather than compactness.

Value 0x20 is assigned to FULL.

See Also:
Constant Field Values
Constructor Detail

DateEditor

public DateEditor(Composite parent,
                  int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR 'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

DATE|COMPACT is used as the default date editor style value.

Parameters:
parent - a composite control which will be the parent of the new instance (cannot be null)
style - the SWT style to construct
Throws:
java.lang.IllegalArgumentException -
SWTException -
See Also:
DATE, COMPACT

DateEditor

public DateEditor(Composite parent,
                  int style,
                  int dateEditorStyle)
Constructs a new instance of this class given its parent, a style value describing its appearance, and a widget-specific style describing its behavior.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR 'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

The DateEditor type constants: DATE, TIME, DATE_TIME, DURATION, OFFSET may be bitwise OR'ed with one of the widget-specific styles: COMPACT or FULL.

Parameters:
parent - a composite control which will be the parent of the new instance (cannot be null)
style - the SWT style to construct
dateEditorStyle - the DateEditor style to construct.
Throws:
java.lang.IllegalArgumentException -
SWTException -
See Also:
DATE, TIME, DATE_TIME, DURATION, OFFSET, COMPACT, FULL
Method Detail

addModifyListener

public void addModifyListener(ModifyListener listener)
Adds the listener to the collection of listeners that will be notified when the receiver's content is modified. This listener will receive the messages defined in the ModifyListener interface.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
ModifyListener, removeModifyListener(org.eclipse.swt.events.ModifyListener)

addSelectionListener

public void addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners that will be notified when the control is selected. This listener will receive the messages defined in the SelectionListener interface.

widgetSelected is called when a date or time selection is finalized by single clicking or pressing the selection key. widgetDefaultSelected is called when the user double clicks or presses the ENTER key.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
SelectionListener, removeSelectionListener(org.eclipse.swt.events.SelectionListener), SelectionEvent

getDate

public java.util.Date getDate()
Returns the date when DATE, TIME or DATE_TIME styles are used. Updating the returned Date instance will not affect the date value in the control.

Returns:
Date an instance of date/time in UTC.
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed

getTime

public int getTime()
Returns the number of seconds when TIME, OFFSET or DURATION styles are used. The return value is the total number of seconds derived from the hours, minutes, and seconds displayed in the widget. The maximum value is +/- 86399 seconds which is equivalent to 23:59:59 in hh:mm:ss.

Returns:
time value converted to number of seconds
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed

removeModifyListener

public void removeModifyListener(ModifyListener listener)
Removes the listener from the collection of listeners that will be notified when the receiver's text is modified.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
ModifyListener, addModifyListener(org.eclipse.swt.events.ModifyListener)

removeSelectionListener

public void removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners that will be notified when the control is selected.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
SelectionListener, addSelectionListener(org.eclipse.swt.events.SelectionListener)

setDate

public void setDate(java.util.Date date)
Sets the date for the editor when DATE, TIME or DATE_TIME styles are used. The control does not retain the Date object or modify its value.

Parameters:
date - an instance of date/time in UTC
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the date is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver

setTime

public void setTime(int seconds)
Sets the time for the editor when TIME, OFFSET or DURATION styles are used.

Parameters:
seconds - the number of seconds which will be displayed in hours, minutes, and seconds. The maximum value is +/- 86399 seconds which is equivalent to 23:59:59 in hh:mm:ss.
Throws:
java.lang.IllegalArgumentException -
  • ERROR_INVALID_ARGUMENT - if the number of seconds is out of range
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed

setTimeZone

public void setTimeZone(java.util.TimeZone timeZone)
Defines the time zone, which is applied on the DateEditor (which is UTC time). The date and time presented in the user interface of DateEditor is a local time in this time zone. The argument can be null, which defaults to currently active time zone of the device. TimeZone has no affect for DURATION and OFFSET styles.

Parameters:
timeZone - an instance of TimeZone or null
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver