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.

Abstract Dialog

Abstract Dialog

Overview

AbstractEPDialog is meant to be used for all dialogs that have title bar area consisting of a title, description and image. It provides utility methods for creating the more commonly used buttons like OK, Save, Set, Confirm and Cancel. By default a combination of Save and Cancel buttons is configured.

How to use AbstractEPDialog

AbstractEPDialog should be extended and the following abstract methods implemented when necessary:

/**
	 * Populates the controls for the contents.
	 */
	protected abstract void populateControls();

	/**
	 * Binds the controls for the contents.
	 */
	protected abstract void bindControls();

	/**
	 * Creates the controls that have to be displayed in the client area of the dialog.
	 *
	 * @param dialogComposite the EP layout composite to be used
	 */
	protected abstract void createEpDialogContent(IEpLayoutComposite dialogComposite);

	/**
	 * Gets the title of the dialog displayed in the title area.
	 *
	 * @return String or null if none
	 */
	protected abstract String getTitle();

	/**
	 * Gets the description of the dialog displayed in the title area.
	 *
	 * @return String or null if none
	 */
	protected abstract String getInitialMessage();

	/**
	 * Gets the title image displayed in the title area.
	 *
	 * @return Image or null if none
	 */
	protected abstract Image getTitleImage();

	/**
	 * Should return the dialog window title.
	 *
	 * @return String or null if none
	 */
	protected abstract String getWindowTitle();

	/**
	 * Should return the dialog window image.
	 *
	 * @return Image or null if none
	 */
	protected abstract Image getWindowImage();

For values that should not be displayed a simple return of null value will leave the title, image or description fields empty.

Creating a custom dialog implies the usage of the EP UI Framework as the main tool to create and manage the UI controls.

For creating custom buttons or to change the default buttons a specific method has to be overridden. The following is an example of creating a custom labeled OK button along with a Cancel one.

protected void createButtonsForButtonBar(final Composite parent) {
		createEpOkButton(parent, "My Button", null);
		createEpCancelButton(parent);
	}

Hadling OK button click event is done in okPressed() method. Cancel button event closes the dialog by default but this behaviour can be changed by overriding cancelPressed() method.

For creating one of the predefined button sets you can do the following:

protected void createButtonsForButtonBar(final Composite parent) {
		createEpButtonsForButtonsBar(ButtonsBarType.CONFIRM, parent);
	}

What not to use AbstractEpDialog for?

Do not use AbstractEpDialog for displaying dialogs that are a part of the standard SWT API:

  • Errors, warnings, and informational messages
  • Question/confirmation dialogs

All of these can be displayed using the MessageDialog API:

MessageDialog.openError(...)
MessageDialog.openWarning(...)
MessageDialog.openInformation(...)
MessageDialog.openQuestion(...)
MessageDialog.openConfirm(...)

Example

For reference you can take a look at the numerous dialogs implemented on top of the AbstractEpDialog (e.g. CustomerAddEditAddressDialog, VirtualCatalogDialog, etc.)