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