@SuppressWarnings({"unchecked", "rawtypes"})
    public Task createBusinessObject(ICreateContext context) {
      Task task = super.createBusinessObject(context);
      final String name = customTaskDescriptor.getName();
      if (name != null && !name.isEmpty()) {
        task.setName(name.trim());
      }

      // make sure the ioSpecification has both a default InputSet and OutputSet
      InputOutputSpecification ioSpecification = task.getIoSpecification();
      if (ioSpecification != null) {
        Resource resource = getResource(context);
        if (ioSpecification.getInputSets().size() == 0) {
          InputSet is = Bpmn2ModelerFactory.createObject(resource, InputSet.class);
          ioSpecification.getInputSets().add(is);
        }
        if (ioSpecification.getOutputSets().size() == 0) {
          OutputSet os = Bpmn2ModelerFactory.createObject(resource, OutputSet.class);
          ioSpecification.getOutputSets().add(os);
        }
      }

      // Create the ItemDefinitions for each I/O parameter if needed
      JBPM5RuntimeExtension rx =
          (JBPM5RuntimeExtension) customTaskDescriptor.getRuntime().getRuntimeExtension();
      String id = customTaskDescriptor.getId();
      WorkItemDefinition wid = rx.getWorkItemDefinition(id);
      if (ioSpecification != null && wid != null) {
        for (DataInput input : ioSpecification.getDataInputs()) {
          for (Entry<String, String> entry : wid.getParameters().entrySet()) {
            if (input.getName().equals(entry.getKey())) {
              if (entry.getValue() != null)
                input.setItemSubjectRef(
                    JbpmModelUtil.getDataType(context.getTargetContainer(), entry.getValue()));
              break;
            }
          }
        }
        for (DataOutput output : ioSpecification.getDataOutputs()) {
          for (Entry<String, String> entry : wid.getResults().entrySet()) {
            if (output.getName().equals(entry.getKey())) {
              if (entry.getValue() != null)
                output.setItemSubjectRef(
                    JbpmModelUtil.getDataType(context.getTargetContainer(), entry.getValue()));
              break;
            }
          }
        }
      }
      return task;
    }
  @Override
  protected EObject addListItem(EObject object, EStructuralFeature feature) {
    InputSet inputSet = throwEvent.getInputSet();
    if (inputSet == null) {
      inputSet = FACTORY.createInputSet();
      throwEvent.setInputSet(inputSet);
      ModelUtil.setID(inputSet);
    }
    // generate a unique parameter name
    String base = "inParam";
    int suffix = 1;
    String name = base + suffix;
    for (; ; ) {
      boolean found = false;
      for (DataInput p : inputSet.getDataInputRefs()) {
        if (name.equals(p.getName())) {
          found = true;
          break;
        }
      }
      if (!found) break;
      name = base + ++suffix;
    }

    DataInput param = (DataInput) super.addListItem(object, feature);
    // add the new parameter to the InputSet
    (param).setName(name);
    inputSet.getDataInputRefs().add(param);

    // create a DataInputAssociation
    DataInputAssociation inputAssociation = FACTORY.createDataInputAssociation();
    throwEvent.getDataInputAssociation().add(inputAssociation);
    inputAssociation.setTargetRef((DataInput) param);
    ModelUtil.setID(inputAssociation);
    return param;
  }
  public void updateTask() {
    /*
     * Here we need to examine the current list of DataInputAssociations on the
     * Task and, if there is already a DataInput named NotStartedReassign or
     * NotCompletedReassign, append a new expression. Otherwise create a new
     * DataInput and DataInputAssociation.
     *
     * The XML looks like this:
     *
     * <bpmn2:ioSpecification id="IOSpec_1">
     *   <bpmn2:dataInput id="DataInput_1" name="NotCompletedReassign"/>
     *   <bpmn2:dataInput id="DataInput_2" name="NotStartedReassign"/>
     * </bpmn2:ioSpecification>
     *
     * <bpmn2:dataInputAssociation id="DataInputAssociation_1">
     *   <bpmn2:targetRef>DataInput_1</bpmn2:targetRef>
     *   <bpmn2:assignment id="Assignment_1">
     *     <bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[[users:user2|groups:group2]@[exp2]^[users:user1,user2,user3|groups:group1,group2,group3]@[exp4]]]></bpmn2:from>
     *     <bpmn2:to xsi:type="bpmn2:tFormalExpression">DataInput_1</bpmn2:to>
     *   </bpmn2:assignment>
     * </bpmn2:dataInputAssociation>
     *
     * <bpmn2:dataInputAssociation id="DataInputAssociation_2">
     *   <bpmn2:targetRef>DataInput_2</bpmn2:targetRef>
     *   <bpmn2:assignment id="Assignment_2">
     *     <bpmn2:from xsi:type="bpmn2:tFormalExpression"><![CDATA[[users:user1|groups:group1]@[exp1]^[users:user1,user2,user3|groups:group1,group2,group3]@[exp4]]]></bpmn2:from>
     *     <bpmn2:to xsi:type="bpmn2:tFormalExpression">DataInput_2</bpmn2:to>
     *   </bpmn2:assignment>
     * </bpmn2:dataInputAssociation>
     */
    Resource resource = task.eResource();
    InputOutputSpecification iospec = task.getIoSpecification();
    DataInputAssociation notStarted = null;
    DataInputAssociation notCompleted = null;
    DataInput input;
    Assignment assignment;
    FormalExpression expression;
    String body;
    for (DataInputAssociation dia : task.getDataInputAssociations()) {
      if (dia.getTargetRef() instanceof DataInput) {
        input = (DataInput) dia.getTargetRef();
        if (ReassignmentType.NOT_STARTED_REASSIGN.getLiteral().equals(input.getName())) {
          notStarted = dia;
        } else if (ReassignmentType.NOT_COMPLETED_REASSIGN.getLiteral().equals(input.getName())) {
          notCompleted = dia;
        }
      }
    }

    body = toString(ReassignmentType.NOT_STARTED_REASSIGN);
    if (body.isEmpty()) {
      if (notStarted != null) {
        // need to remove the NotCompletedReassign data input and association
        iospec.getDataInputs().remove(notStarted.getTargetRef());
        iospec.getInputSets().get(0).getDataInputRefs().remove(notStarted.getTargetRef());
        task.getDataInputAssociations().remove(notStarted);
      }
    } else {
      if (notStarted == null) {
        // create the NotStartedReassign data input and association
        input =
            (DataInput) Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getDataInput());
        input.setName(ReassignmentType.NOT_STARTED_REASSIGN.getLiteral());
        iospec.getDataInputs().add(input);
        iospec.getInputSets().get(0).getDataInputRefs().add(input);
        notStarted =
            (DataInputAssociation)
                Bpmn2ModelerFactory.create(
                    resource, Bpmn2Package.eINSTANCE.getDataInputAssociation());
        notStarted.setTargetRef(input);
        assignment =
            (Assignment)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getAssignment());
        expression =
            (FormalExpression)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getFormalExpression());
        // make sure this DataInput has an ID
        ModelUtil.setID(input);
        expression.setBody(input.getId());
        assignment.setTo(expression);
        notStarted.getAssignment().add(assignment);
        task.getDataInputAssociations().add(notStarted);

        ModelUtil.setID(notStarted);
        ModelUtil.setID(assignment);
        ModelUtil.setID(expression);
      }

      assignment = (Assignment) notStarted.getAssignment().get(0);
      expression = (FormalExpression) assignment.getFrom();
      if (expression == null) {
        expression =
            (FormalExpression)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getFormalExpression());
        assignment.setFrom(expression);
        ModelUtil.setID(expression);
      }
      expression.setBody(body);
    }

    body = toString(ReassignmentType.NOT_COMPLETED_REASSIGN);
    if (body.isEmpty()) {
      if (notCompleted != null) {
        // need to remove the NotCompletedReassign data input and association
        iospec.getDataInputs().remove(notCompleted.getTargetRef());
        iospec.getInputSets().get(0).getDataInputRefs().remove(notCompleted.getTargetRef());
        task.getDataInputAssociations().remove(notCompleted);
      }
    } else {
      if (notCompleted == null) {
        // create the NotStartedReassign data input and association
        input =
            (DataInput) Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getDataInput());
        input.setName(ReassignmentType.NOT_COMPLETED_REASSIGN.getLiteral());
        iospec.getDataInputs().add(input);
        iospec.getInputSets().get(0).getDataInputRefs().add(input);
        notCompleted =
            (DataInputAssociation)
                Bpmn2ModelerFactory.create(
                    resource, Bpmn2Package.eINSTANCE.getDataInputAssociation());
        notCompleted.setTargetRef(input);
        assignment =
            (Assignment)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getAssignment());
        expression =
            (FormalExpression)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getFormalExpression());
        // make sure this DataInput has an ID
        ModelUtil.setID(input);
        expression.setBody(input.getId());
        assignment.setTo(expression);
        notCompleted.getAssignment().add(assignment);
        task.getDataInputAssociations().add(notCompleted);

        ModelUtil.setID(notCompleted);
        ModelUtil.setID(assignment);
        ModelUtil.setID(expression);
      }

      assignment = (Assignment) notCompleted.getAssignment().get(0);
      expression = (FormalExpression) assignment.getFrom();
      if (expression == null) {
        expression =
            (FormalExpression)
                Bpmn2ModelerFactory.create(resource, Bpmn2Package.eINSTANCE.getFormalExpression());
        assignment.setFrom(expression);
        ModelUtil.setID(expression);
      }
      expression.setBody(body);
    }
  }
    /* (non-Javadoc)
     * @see org.eclipse.graphiti.features.IFeature#execute(org.eclipse.graphiti.features.context.IContext)
     */
    @Override
    public void execute(IContext context) {
      // TODO: clean this mess up: use {@code getWorkItemEditor()) to check if the selected task
      // has a WID and if the WID defines a customEditor
      BPMN2Editor editor =
          (BPMN2Editor)
              getFeatureProvider()
                  .getDiagramTypeProvider()
                  .getDiagramBehavior()
                  .getDiagramContainer();
      PictogramElement pe = ((ICustomContext) context).getPictogramElements()[0];
      final Task task =
          (Task) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe);
      String taskName = ""; // $NON-NLS-1$
      List<EStructuralFeature> features = ModelDecorator.getAnyAttributes(task);
      for (EStructuralFeature f : features) {
        if ("taskName".equals(f.getName())) { // $NON-NLS-1$
          taskName = (String) task.eGet(f);
          break;
        }
      }

      IBpmn2RuntimeExtension rte = editor.getTargetRuntime().getRuntimeExtension();
      WorkItemDefinition workItemDefinition =
          ((JBPM5RuntimeExtension) rte).getWorkItemDefinition(taskName);

      WorkDefinitionImpl wd = new WorkDefinitionImpl();
      for (String name : workItemDefinition.getParameters().keySet()) {
        String type = workItemDefinition.getParameters().get(name);
        DataTypeFactory factory = DataTypeRegistry.getFactory(type);
        wd.addParameter(new ParameterDefinitionImpl(name, factory.createDataType()));
      }

      WorkImpl w = new WorkImpl();
      w.setName(taskName);
      w.setParameterDefinitions(wd.getParameters());
      for (DataInputAssociation dia : task.getDataInputAssociations()) {
        DataInput dataInput = (DataInput) dia.getTargetRef();
        if (dataInput != null) {
          String name = dataInput.getName();
          ItemDefinition itemDefinition = dataInput.getItemSubjectRef();
          if (itemDefinition != null) {
            Object structureRef = itemDefinition.getStructureRef();
            if (ModelUtil.isStringWrapper(structureRef)) {
              ParameterDefinition parameterDefinition = w.getParameterDefinition(name);
              try {
                Object value =
                    parameterDefinition
                        .getType()
                        .readValue(ModelUtil.getStringWrapperTextValue(structureRef));
                w.setParameter(name, value);
              } catch (Exception e) {
              }
            }
          }
        }
      }

      /*
      	 * Load the class defined in the WID's "eclipse:customEditor" field.
      	 * This means that the containing Project must be a JavaProject, and
      	 * the class must exist and must implement the WorkEditor interface.
      try {
      	Resource res = ExtendedPropertiesAdapter.getResource(task);
      	URI uri = res.getURI();
      	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.segment(1));
      	JavaProjectClassLoader cl = new JavaProjectClassLoader(project);
      	Class c = cl.loadClass("org.bpmn2.java.Calculator");
      	Object o = c.newInstance();
      	String s = o.toString();
      	System.out.println(s);
      } catch (Exception e) {
      	// TODO Auto-generated catch block
      	e.printStackTrace();
      }
      	 */

      WorkEditor dialog = getWorkItemEditor(task);
      dialog.setWorkDefinition(wd);
      dialog.setWork(w);
      dialog.show();

      hasChanges = dialog.getWork() != w;
      if (hasChanges) {
        w = (WorkImpl) dialog.getWork();
        for (DataInputAssociation dia : task.getDataInputAssociations()) {
          DataInput dataInput = (DataInput) dia.getTargetRef();
          if (dataInput != null) {
            String name = dataInput.getName();
            ItemDefinition itemDefinition = dataInput.getItemSubjectRef();
            // this always comes back as a String from the SampleCustomEditor dialog
            String value = (String) w.getParameter(name);
            if (value != null && !value.isEmpty()) {
              EObject structureRef = ModelUtil.createStringWrapper(value);
              if (itemDefinition == null) {
                itemDefinition =
                    Bpmn2ModelerFactory.createObject(task.eResource(), ItemDefinition.class);
                ModelUtil.getDefinitions(task).getRootElements().add(itemDefinition);
                ModelUtil.setID(itemDefinition);
              }
              itemDefinition.setItemKind(ItemKind.INFORMATION);
              itemDefinition.setStructureRef(structureRef);
              dataInput.setItemSubjectRef(itemDefinition);
            } else if (itemDefinition != null) {
              // TODO: remove Item Definition if it is on longer referenced anywhere
              //							ModelUtil.getDefinitions(task).getRootElements().remove(itemDefinition);
              dataInput.setItemSubjectRef(null);
            }
          }
        }
      }
    }