@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;
    }
    /* (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);
            }
          }
        }
      }
    }