Papyrus Banner

Experimental features

Column actions

An action column is a column that provides an action on single left click with an image displayed in the cell (or others configuration) for each cells of the column.

On the Papyrus git repository, in the example folder, you will find the plugin org.eclipse.papyrus.example.uml.nattable.actions which provides an example of column actions. This example contributes the table Example Generic Tree Table with Actions to the Papyrus Architecture Framework. Here, the illustration of the creation and the result of the table example when you installed it in your Eclipse.

How to create a table configuration with column actions?

In your TableConfiguration, you must create a AxisManagerRepresentation for columns, with these values

Now you can declare columns for this action in your Column Provider.

If you want to define a smaller width for your column, create a new Int Value Style for it, with name field set to axisWidth and filling the Int Value field as you want.

Now, you just need to define the behavior and the appearance of the cell. You need to create a new CellEditorConfiguration (extending org.eclipse.papyrus.infra.nattable.celleditor.action.AbstractSingleClickActionCellEditorConfiguration for a single click action with an image displayed in cell. Then, you need to register this file in the plugin.xml with the extension point org.eclipse.papyrus.infra.nattable.celleditor.configuration.

The others required classes for label manager and cell manager are already provided by Papyrus for the standart usecases, so nothing is required for them.

Which column actions are provided by Papyrus ?

Papyrus doesn't yet integrate actions to its provided table configuration. Nevertheless, the required java code for some actions is available in Papyrus. Existing actions are:

The code for these actions is in the plugin org.eclipse.papyrus.infra.nattable in the java package org.eclipse.papyrus.infra.nattable.celleditor.action

Empty rows/empty lines in the TreeTable

Some projects using Papyrus requires to display some empty lines in their table to allow to the user to create new element from a single click.

On the Papyrus git repository, in the example folder, you will find the plugin org.eclipse.papyrus.example.uml.nattable.empty.line which provides an example of column actions. This example contributes the table Example Generic Tree Table with Actions to the Papyrus Architecture Framework. Here, the illustration of the creation and the result of the table example when you installed it in your Eclipse. This illustration shows an empty line with an action declared on the row header.

How to create a table configuration with empty line?

You should start from an existing tree table configuration, but in this case, you will need to delete the axis manager defined for rows.

That's all for the TableConfiguration. You can register it in your Papyrus *.architecture file and remember the id value you defined for this table in this file.

Now you need to create and register several java classes.

From this point, you will obtain a tree table with an empty line for each level/categories of the tree, but with no behavior associated to this line.

Here, you will find some additional instructions to declare a creation action on the row header of these empty line. We assume, it is more a hack than a real API.

@Override
	public void configureCellEditor(IConfigRegistry configRegistry, Object axis, String configLabel) {
		final INattableModelManager manager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
		final NatTable natTable = manager.getAdapter(NatTable.class);
		final UiBindingRegistry uiBindingRegistry = natTable.getUiBindingRegistry();
		uiBindingRegistry.registerSingleClickBinding(getMouseEventMatcher(), getMouseAction());
	}

	private IMouseEventMatcher getMouseEventMatcher() {
		return new org.eclipse.papyrus.infra.nattable.mouse.action.EmptyLineRowHeaderEventMatch(SWT.None, GridRegion.ROW_HEADER, MouseEventMatcher.LEFT_BUTTON);
	}

public class CreateElementCellMouseAction extends AbstractCellMouseAction {

		/**
		 * @see org.eclipse.papyrus.infra.nattable.mouse.action.AbstractCellMouseAction#doRun(org.eclipse.nebula.widgets.nattable.NatTable, org.eclipse.swt.events.MouseEvent, java.lang.Object, java.lang.Object)
		 *
		 * @param natTable
		 * @param event
		 * @param rowElement
		 * @param columnElement
		 */
		@Override
		public void doRun(NatTable natTable, MouseEvent event, final Object rowElement, final Object columnElement) {
			if (rowElement instanceof ITreeItemAxis && ((ITreeItemAxis) rowElement).getElement() == null) {
				final ITreeItemAxis currentAxis = (ITreeItemAxis) rowElement;
				final ITreeItemAxis parentAxis = currentAxis.getParent();

				final Object parentElement = parentAxis.getElement();
				if (parentElement instanceof TreeFillingConfiguration) {
					IAxis axisProvider = ((TreeFillingConfiguration) parentElement).getAxisUsedAsAxisProvider();
					Object representedElement = AxisUtils.getRepresentedElement(axisProvider);

					// for a real usage, a check about the filter configuration could be better to be sure the created class
					// will appears in the table
					if (UMLPackage.eINSTANCE.getPackage_PackagedElement().equals(representedElement)) {
						// we will create a new class
						final INattableModelManager manager = natTable.getConfigRegistry().getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID);
						final EObject creationParent = manager.getTable().getContext();
						if (creationParent instanceof Package) {
							final CreateElementRequest request = new CreateElementRequest(creationParent, org.eclipse.papyrus.uml.service.types.element.UMLElementTypes.CLASS);
							final IElementEditService service = ElementEditServiceUtils.getCommandProvider(creationParent);

							final ICommand cmd = service.getEditCommand(request);
							request.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));

						}
					}
				}
			}
		}
	}

public class CustomEmptyLineUMLElementTreeAxisManagerForEventList extends EmptyLineUMLElementTreeAxisManagerForEventList {


	/**
	 *
	 * Constructor.
	 *
	 */
	public CustomEmptyLineUMLElementTreeAxisManagerForEventList() {
		setCreateEmptyRow(true);
	}


	/**
	 * the action used to create element from single left click on row header
	 */
	private static final ICellAxisConfiguration conf = new CreateClassFromHeaderCellEditorConfiguration();


	/**
	 * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#managedHideShowCategoriesForDepth(java.util.List, java.util.List)
	 *
	 * @param depthToHide
	 * @param depthToShow
	 */
	@Override
	public void managedHideShowCategoriesForDepth(List<Integer> depthToHide, List<Integer> depthToShow) {
		super.managedHideShowCategoriesForDepth(depthToHide, depthToShow);
		// trick to be able to register action on row header on single left click
		// warning, it requires to hide categories in the table, if not, this method is not called
		conf.configureCellEditor(((NatTable) getTableManager().getAdapter(NatTable.class)).getConfigRegistry(), null, "");
	}
}