Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
BPMN2-Modeler/DeveloperTutorials/CreateCustomShape
Contents
Versions
This Tutorial was developed with Eclipse 4.4 (Luna) and BPMN2-Plugin version 1.1.1.
Changing the shape for a Custom Task
This section explains how to change the shape and visual appearance of a custom model element. This tutorial assumes that you already have extended a Task element. See the DeveloperTutorials/CreateCustomTask tutorial https://wiki.eclipse.org/BPMN2-Modeler/DeveloperTutorials/CreateCustomTask how to extend a custom task element.
The CustomShapeFeatureContainer
To change the visual appearance of a model object, the base class CustomShapeFeatureContainer can be extended. This class is typically already extended for a Custom Task implementation. To adapt the visual representation the method createFeatureContainer() need to be overwritten. This method creates a FeatueContainer which is used to display the visual representation of a model object.
@Override protected TaskFeatureContainer createFeatureContainer(IFeatureProvider fp) { return new TaskFeatureContainer() { .... }
It is important to return the corresponding FeatureContainer type as defined in the plugin extension point in plugin.xml
<customTask featureContainer="org.imixs.bpmn.ImixsTaskFeatureContainer" id="org.imixs.workflow.bpmn.ProcessEntityTask" name="Imixs Task" runtimeId="org.imixs.workflow.bpmn.runtime" type="Task" .... > </customTask>
For example, if you are extending a Task object (like in the plugin.xml above), you need to return the corresponding class "org.eclipse.bpmn2.modeler.ui.features.activity.task.TaskFeatureContainer". If you extend another model type e.g. IntermediateCatchEvent you need to return an instance of 'org.eclipse.bpmn2.modeler.ui.features.event.IntermediateCatchEventFeatureContainer'.
Overwriting getAddFeature()
In your custom implementation of the FeatureContainer you next need to overwrite the method addFeature.
@Override public IAddFeature getAddFeature(IFeatureProvider fp) { return new AddTaskFeature(fp) { @Override protected void decorateShape(IAddContext context, ContainerShape containerShape, Task businessObject) { ..... } }; }
Also here take care about the returned ClassType which should match your object model type. (e.g. for a IntermediateCatchEvent this would be the class 'org.eclipse.bpmn2.modeler.ui.features.event.AddIntermediateCatchEventFeature').
To change the shape design you now overwrite the method decorateShape. In this method changes of the figure can be made. See the following example which changes the size and background color of a custom task element:
@Override public IAddFeature getAddFeature(IFeatureProvider fp) { return new AddTaskFeature(fp) { @Override protected void decorateShape(IAddContext context, ContainerShape containerShape, Task businessObject) { super.decorateShape(context, containerShape, businessObject); Rectangle selectionRect = (Rectangle)containerShape.getGraphicsAlgorithm(); int width = 160; int height = 90; selectionRect.setWidth(width); selectionRect.setHeight(height); Task ta = BusinessObjectUtil.getFirstElementOfType(containerShape, Task.class); if (ta!=null) { Shape shape = containerShape.getChildren().get(0); ShapeStyle ss = new ShapeStyle(); ss.setDefaultColors(new ColorConstant(144, 176, 224)); StyleUtil.applyStyle(shape.getGraphicsAlgorithm(), ta, ss); } } }; }
Additional you can also overwrite the cretCreateFeature() which can be use to add extension attributes to your business object (bpmn2 element) - see also the BPMN2 examples code for more details. You will also want to provide your own images for the tool palette by overriding getCreateImageId() and getCreateLargeImageId() here.