@Override
  protected Object removeListItem(EObject object, EStructuralFeature feature, int index) {
    // remove parameter from inputSets
    EList<EObject> list = (EList<EObject>) object.eGet(feature);
    EObject item = list.get(index);
    InputSet inputSet = throwEvent.getInputSet();
    if (inputSet.getDataInputRefs().contains(item)) inputSet.getDataInputRefs().remove(item);

    // remove Input or Output DataAssociations
    List<DataInputAssociation> dataInputAssociations = throwEvent.getDataInputAssociation();
    List<DataInputAssociation> removed = new ArrayList<DataInputAssociation>();
    for (DataInputAssociation dia : dataInputAssociations) {
      if (item == dia.getTargetRef()) removed.add(dia);
    }
    dataInputAssociations.removeAll(removed);

    return super.removeListItem(object, feature, index);
  }
  @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);
            }
          }
        }
      }
    }