Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

DateTime Component

DateTime Component

Overview

The date/time component uses the implemention of a Nebula project widget - CDateTime. It provides a text field that could be a combo box as well and a popup date/time selector. From this widget only the popup window is integrated with a SWT Text object. This way it allows the date/time component to be bound using the binding framework. Another reason for doing so are a couple of problems we have stumbled upon: - it does not allow to set a border style of the widget (probably a bug) - when no date has been set there is a problem with the tab navigation inside the component

How to use it

  • Standalone
EpControlFactory epControlFactory = new EpControlFactory();
IEpDateTimePicker picker = epControlFactory.createDateTimeComponent(final Composite parentComposite, final int style, final EpState epState);
  • Using the UI framework
IEpLayoutComposite epComposite = ...
IEpDateTimePicker picker = epComposite.addDateTimeComponent(int style, EpState epState, IEpLayoutData data);

The style can be either IEpDateTimePicker.STYLE_DATE or IEpDateTimePicker.STYLE_DATE_AND_TIME.

Useful Methods

  • setFormatter(DateFormat)
  • For displaying the correct date/time string a DateFormat is used. If no formatter has been set the default ones are used - DateFormat.getDateInstance() for dates and DateFormat.getDateTimeInstance() for date and time.
  • setDate(Date)
  • This method initializes the date (if null the current date will be displayed and the text field will be empty)
  • getDate()
  • Returns the Date object representing the selected date.
  • open(Control, boolean)
  • Used only if the date/time component has to be invoked from another UI widget. It is used currently only for the table in-line editing.

How to bind it using the binding framework

The recommended way of doing that is to use the utility method defined in the IEpDateTimePicker interface:

               com.elasticpath.cmclient.core/src/main/java/com/elasticpath/cmclient/core/ui/framework/IEpDateTimePicker.java
	EpValueBinding bind(DataBindingContext context, IValidator validator, Object target, String fieldName);
            

All that has to be provided is the binding context, validator (most probably from EpValidatorFactory), the object to be bound and the respective field name.

The other way round is to use the IEpDateTimePicker.getSwtText() in order to bind the text field to the respective object field.

There are predefined validators in EpValidatorFactory class - DATE, DATE_REQUIRED, DATE_TIME and DATE_TIME_REQURED.