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.

Table Viewer

Table Viewer

Overview

The EP table viewer abstracts the Eclipse's TableViewer and TableColumn components.

How to use it

An instance of IEpTableViewer can be obtained from the IEpLayoutComposite or EpControlFactory:

IEpTableViewer IEpLayoutComposite.addTableViewer(boolean multiSelection, EpState epState, IEpLayoutData data)
IEpTableViewer EpControlFactory.createTableViewer(final Composite parentComposite, final int style, final EpState epState)

Usually a table has to have at least one column. Columns can be added by calling

IEpTableColumn IEpTableViewer.addTableColumn(String headerText, int initialWidth)

The interface IEpTableColumn represents a column in the table.

There are two modes for an EP table viewer depending on the EpState (EDITABLE, READ_ONLY, DISABLED). If the table is created in read-only mode the label provider can be set directly on the IEpTableViewer instance. The provided label provider will be responsible for checking which column the label should be provided for and return it accordingly . If the table created is in EDITABLE state then each column has to have its own column label provider and editing support implementations. Of course editing support can be omitted in case it is not needed.

The look and feel of the table viewer is predefined and is dependent on the EpState value supplied at creation time.

Example

This example is extracted from AddSkuWizardPage2 class. It shows the way the new SKU wizard handles the attributes values that have to be set to the SKU object model. An IEpTableViewer is created and a few columns added. The editing support is needed so that we have the value column editable when the user clicks over it. The AttributeEditingSupport class extends the org.eclipse.jface.viewers.EditingSupport.

            com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/wizards/sku/AddSkuWizardPage2.java
	this.attributesTableViewer = mainComposite.addTableViewer(false, EpState.EDITABLE, tableLayoutData);
	final GridData tableLayoutData2 = (GridData) attributesTableViewer.getSwtTable().getLayoutData();
	tableLayoutData2.heightHint = TABLE_HIGH_HINT;
	tableLayoutData2.widthHint = TABLE_WIDTH_HINT;
	
	//getSection().setLayoutData(getLayoutData());

	// the name column content of the attribute table
	final IEpTableColumn nameColumn = this.attributesTableViewer
			.addTableColumn(
					CatalogMessages.ProductEditorAttributeSection_TableColumnTitle_Name,
					200);
	// The attribute type column content of the attribute table
	final IEpTableColumn typeColumn = this.attributesTableViewer
			.addTableColumn(
					CatalogMessages.ProductEditorAttributeSection_TableColumnTitle_Type,
					80);
	
	// The attribute required column content of the attribute table
	final IEpTableColumn requiredColumn = this.attributesTableViewer
			.addTableColumn(
					CatalogMessages.ProductEditorAttributeSection_TableColumnTitle_Required,
					60);
	
	// The attribute required column content of the attribute table
	final IEpTableColumn multiLanguageColumn = this.attributesTableViewer
			.addTableColumn(
					CatalogMessages.ProductEditorAttributeSection_TableColumnTitle_MLang,
					90);

	// The attribute value column content of the attribute table
	final IEpTableColumn valueColumn = this.attributesTableViewer
			.addTableColumn(
					CatalogMessages.ProductEditorAttributeSection_TableColumnTitle_Value,
					300);
	
	final AttributesLabelProviderUtil labelProviderUtil = new AttributesLabelProviderUtil(EpState.EDITABLE);
	labelProviderUtil.setNameColumnLabel(nameColumn);
	labelProviderUtil.setTypeColumnLabel(typeColumn);
	labelProviderUtil.setRequiredColumnLabel(requiredColumn);
	labelProviderUtil.setMultiLanguageColumnLabel(multiLanguageColumn);
	labelProviderUtil.setValueColumnLabel(valueColumn);

	// add EditSupport to the attribute value column
	valueColumn.setEditingSupport(new AttributeEditingSupport(this.attributesTableViewer, this.getProductSku()));