Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search


< BPMN2-Modeler‎ | DeveloperTutorials
Revision as of 16:52, 12 March 2015 by Unnamed Poltroon (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


This Tutorial was developed with Eclipse 4.4 (Luna) and BPMN2-Plugin version 1.1.1.

Creating a Custom Task

This section explains how to add a new CustomTask element extending the BPMN2 Task element. The tutorial assumes that you have already extend the BPMN runtime as explained in the BPMN Runtime Tutorial. Also, please refer to the Model Extension tutorial to understand other ways of extending the BPMN2 model.

Creating a CustomTask covers the following aspects:

  • The visual modelling element
  • The properties of the custom element
  • Optional property sections to configure the element

The <customTask> extension point

This extension is similar to <modelExtension> (see the tutorial here) but is used only for objects that have a visual representation on the editing canvas. The name "customTask" is a misnomer because it can be used with not just Tasks, but any BPMN2 type that has a visual associated with it, for example SequenceFlow, EventDefinition, Gateway, etc.

The customTask definitions also appear in the tool palette as individual tool items in a tool drawer of your choosing. A Java class is required to manage the lifecycle of customTask objects. This class is involved in the Graphiti framework during creation, update and deletion so that every visual aspect of the element can be controlled.

To define a new <customTask> element just open the plugin.xml file and create a new ‘CustomTask’ in your BPMN2 plugin extension node (See the BPMN Runtime Tutorial). In the property ‘runtimeid’ add your previously defined Runtime ID. In the property ‘type’ enter ‘Task’ to use the standard Task object type to be extended from BPMN2. The Property ‘category’ is the name of a tool palette "drawer" where your new element will be contained.

Next you need to generate a new Java class for the FeatureContainer. This can be done form the plugin editor by clicking on ‘featureContainer*’. The class can be extended form the CustomShapeFeatureContainer. See the following example:

public class TestTaskElementFeatureContainer1 extends CustomShapeFeatureContainer {

 // these values must match what's in the plugin.xml
 private final static String TYPE_VALUE = "TestTask";
 private final static String CUSTOM_TASK_ID = "Imixs-BPMN2.customTask1";

 public TestTaskElementFeatureContainer1() {

 public String getId(EObject object) {
 // This is where we inspect the object to determine what its custom task ID should be.
 // In this case, the "type" attribute will have a value of "MyTask".
 // If found, return the CUSTOM_TASK_ID string.
 // Note that the object inspection can be arbitrarily complex and may include several
 // object features. This simple case just demonstrates what needs to happen here.
 EStructuralFeature f = ModelDecorator.getAnyAttribute(object, "type");
 if (f!=null) {
 Object id = object.eGet(f);
 if (TYPE_VALUE.equals(id))
 return null;

 public ICustomFeature[] getCustomFeatures(IFeatureProvider fp) {
 return new ICustomFeature[] {new ShowPropertiesFeature(fp)};

Since it is possible to define more than one type of CustomTask, each type needs to be identifiable by a unique ID string and your plugin must be able to determine this CustomTask type through inspection of an object. Typically this is done by initializing some identifying attribute defined on the CustomTask extension.

For this example, we'll add a "type" attribute to our CustomTask and initialize it to the string "TestTask" to identify this CustomTask element. Use the plugin.xml editor and add a new ‘property’ to your CustomTask with the name ‘type’ and the value ‘TestTask’. Our new TestTaskElementFeatureContainer1 class can now look for this "type" attribute in the object passed in to it, and if its value is "TestTask" it will return the CUSTOM_TASK_ID.

Screen 03.png

You can now also define additional custom properties. These properties will be displayed in the ‘Task’ property Section when you edit the new Task Element with the BPMN2 Modeler.

Back to the top