/**
   * Returns the modelObject ID string from the given Graphiti context.
   *
   * @param context
   * @return - ID string for this modelObject.
   */
  public static String getId(IContext context) {
    Object id = null;

    /**
     * IAddContext can also mean that a file is dragged, therefore we have to check if we are really
     * dragging a customTask
     */
    if (context instanceof IAddContext
        && ((IAddContext) context).getNewObject() instanceof EObject) {
      EObject object = (EObject) ((IAddContext) context).getNewObject();
      TargetRuntime rt = TargetRuntime.getCurrentRuntime();
      for (CustomTaskDescriptor ct : rt.getCustomTasks()) {
        id = ct.getFeatureContainer().getId(object);
        if (id != null) {
          context.putProperty(CUSTOM_TASK_ID, id);
          return (String) id;
        }
      }
    }

    if (context instanceof IPictogramElementContext) {
      PictogramElement pe = ((IPictogramElementContext) context).getPictogramElement();
      id = Graphiti.getPeService().getPropertyValue(pe, CUSTOM_TASK_ID);
    } else {
      id = context.getProperty(CUSTOM_TASK_ID);
    }
    return (String) id;
  }
  @Override
  public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() {
    if (toolBehaviorProviders == null) {
      DefaultBPMN2Editor editor = (DefaultBPMN2Editor) getDiagramEditor();
      TargetRuntime rt = editor.getTargetRuntime();
      IConfigurationElement[] config =
          Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.UI_EXTENSION_ID);
      Bpmn2ToolBehaviorProvider provider = null;
      try {
        for (IConfigurationElement e : config) {
          if (e.getName().equals("toolProvider")) { // $NON-NLS-1$
            String id = e.getAttribute("id"); // $NON-NLS-1$
            String runtimeId = e.getAttribute("runtimeId"); // $NON-NLS-1$
            if (rt != null && rt.getId().equals(runtimeId)) {
              String className = e.getAttribute("class"); // $NON-NLS-1$
              ClassLoader cl = rt.getRuntimeExtension().getClass().getClassLoader();
              Constructor ctor = null;
              Class providerClass = Class.forName(className, true, cl);
              ctor = providerClass.getConstructor(IDiagramTypeProvider.class);
              provider = (Bpmn2ToolBehaviorProvider) ctor.newInstance(this);
              break;
            }
          }
        }
      } catch (Exception ex) {
        Activator.logError(ex);
      }

      if (provider == null) provider = new Bpmn2ToolBehaviorProvider(this);
      toolBehaviorProviders = new IToolBehaviorProvider[] {provider};
    }
    return toolBehaviorProviders;
  }
 private ExtendedPropertiesAdapter getTargetRuntimeAdapter(EObject object) {
   PropertyExtensionDescriptor ped =
       TargetRuntime.getCurrentRuntime().getPropertyExtension(object.getClass());
   if (ped == null && TargetRuntime.getCurrentRuntime() != TargetRuntime.getDefaultRuntime())
     ped = TargetRuntime.getDefaultRuntime().getPropertyExtension(object.getClass());
   if (ped != null) return ped.getAdapter(adapterFactory, object);
   return null;
 }
 private ExtendedPropertiesAdapter getTargetRuntimeAdapter(EClass eclass) {
   PropertyExtensionDescriptor ped =
       TargetRuntime.getCurrentRuntime().getPropertyExtension(eclass.getInstanceClass());
   if (ped == null && TargetRuntime.getCurrentRuntime() != TargetRuntime.getDefaultRuntime())
     ped = TargetRuntime.getDefaultRuntime().getPropertyExtension(eclass.getInstanceClass());
   if (ped != null) return ped.getAdapter(adapterFactory, eclass);
   return null;
 }
 public Bpmn2ExtendedPropertiesSwitch(AdapterFactory adapterFactory) {
   super();
   this.adapterFactory = adapterFactory;
   // This adapter can handle the <propertyExtension>s from foreign models also!
   for (TargetRuntime rt : TargetRuntime.getAllRuntimes()) {
     for (PropertyExtensionDescriptor ped : rt.getPropertyExtensions()) {
       AdapterRegistry.INSTANCE.registerFactory(ped.getInstanceClass(), adapterFactory);
     }
   }
 }
Exemplo n.º 6
0
 private CustomTaskDescriptor getCustomTaskDescriptor(EObject object) {
   TargetRuntime rt = getTargetRuntime(object);
   if (rt != null) {
     for (CustomTaskDescriptor ctd : rt.getCustomTaskDescriptors()) {
       if (ctd.getFeatureContainer() != null) {
         String id = ctd.getFeatureContainer().getId(object);
         if (ctd.getId().equals(id)) {
           return ctd;
         }
       }
     }
   }
   return null;
 }
 /**
  * Returns the Java class that implements a Work Item Editor dialog for the given BaseElement if
  * the WID file defines one.
  *
  * @param baseElement
  * @return a Work Item Editor dialog class or null if the BaseElement is not a custom task
  *     (defined by a WID file) or if the WID file does declare a "eclipse:customEditor" class.
  *     <p>TODO: make this return an object instance and make sure it implements the {@code
  *     WorkEditor} interface.
  */
 public static WorkEditor getWorkItemEditor(BaseElement baseElement) {
   String customTaskId = CustomElementFeatureContainer.findId(baseElement);
   TargetRuntime rt = TargetRuntime.getRuntime(baseElement);
   JBPM5RuntimeExtension rte = (JBPM5RuntimeExtension) rt.getRuntimeExtension();
   WorkItemDefinition wid = ((JBPM5RuntimeExtension) rte).getWorkItemDefinition(customTaskId);
   if (wid != null) {
     String customEditor = wid.getEclipseCustomEditor();
     if (customEditor != null && !customEditor.isEmpty()) {
       try {
         Resource res = ExtendedPropertiesAdapter.getResource(baseElement);
         URI uri = res.getURI();
         IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(uri.segment(1));
         JavaProjectClassLoader cl = new JavaProjectClassLoader(project);
         if (cl != null) {
           return new SampleCustomEditor(Display.getDefault().getActiveShell());
         }
       } catch (Exception ignore) {
       }
     }
   }
   return null;
 }