Пример #1
0
 public static Hashtable<String, Object> getChoiceOfValues(
     EObject object, EStructuralFeature feature) {
   ExtendedPropertiesAdapter adapter =
       (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
   if (adapter != null) return adapter.getFeatureDescriptor(feature).getChoiceOfValues(object);
   return null;
 }
Пример #2
0
  public static String getText(EObject object, EStructuralFeature feature) {
    if (feature == null) return getText(object);

    ExtendedPropertiesAdapter adapter =
        (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
    if (adapter != null) return adapter.getFeatureDescriptor(feature).getText(object);
    return getDisplayName(object, feature);
  }
Пример #3
0
 public static String getLabel(EObject object, EStructuralFeature feature) {
   String label = "";
   ExtendedPropertiesAdapter adapter =
       (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
   if (adapter != null) label = adapter.getFeatureDescriptor(feature).getLabel(object);
   else label = ModelUtil.toDisplayName(feature.getName());
   label = label.replaceAll(" Ref$", "");
   return label;
 }
Пример #4
0
 public static String getText(Object object) {
   if (object instanceof EObject) {
     EObject eObject = (EObject) object;
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(eObject, ExtendedPropertiesAdapter.class);
     if (adapter != null) return adapter.getObjectDescriptor().getText(eObject);
     return getDisplayName(eObject);
   }
   return object.toString();
 }
Пример #5
0
 public static boolean isMultiChoice(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_IS_MULTI_CHOICE);
       if (result instanceof Boolean) return ((Boolean) result);
     }
   }
   return getChoiceOfValues(object, feature) != null;
 }
Пример #6
0
 public static boolean canEditInline(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_CAN_EDIT_INLINE);
       if (result instanceof Boolean) return ((Boolean) result);
     }
   }
   return false;
 }
Пример #7
0
 public static boolean canCreateNew(EObject object, EStructuralFeature feature) {
   if (feature.getEType() instanceof EClass) {
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
     if (adapter != null) {
       Object result = adapter.getProperty(feature, ExtendedPropertiesAdapter.UI_CAN_CREATE_NEW);
       if (result instanceof Boolean) return ((Boolean) result);
     }
     return true;
   }
   return false;
 }
Пример #8
0
 /*
  * Various model object and feature UI property methods
  */
 public static String getLabel(Object object) {
   String label = "";
   if (object instanceof EObject) {
     EObject eObject = (EObject) object;
     ExtendedPropertiesAdapter adapter =
         (ExtendedPropertiesAdapter) AdapterUtil.adapt(eObject, ExtendedPropertiesAdapter.class);
     if (adapter != null) label = adapter.getObjectDescriptor().getLabel(eObject);
     else label = ModelUtil.toDisplayName(eObject.eClass().getName());
   } else label = object.toString();
   label = label.replaceAll(" Ref$", "");
   return label;
 }
    /* (non-Javadoc)
     * @see org.eclipse.bpmn2.util.Bpmn2Switch#defaultCase(org.eclipse.emf.ecore.EObject)
     *
     * The default case for this switch is to search the current target runtime plugin for
     * ExtendedPropertiesAdapters that can handle the given EObject.
     *
     * If the given EObject is actually an EClass, then a dummy EObject is constructed and cached
     * for use by the adapter. This could cause problems if the adapter is used for anything other
     * than providing simple static information (labels, etc.)
     *
     * For an example usage of this, see the org.eclipse.bpmn2.modeler.ui.util.PropertyUtil#getLabel(Object)
     * call in the List Composite, to fetch section titles and table column headers from the adapter:
     * @see org.eclipse.bpmn2.modeler.ui.property.AbstractListComposite#bindList(EObject,EStructuralFeature)
     *
     * If no adapter is found for the given EObject, a generic one is constructed and returned.
     */
    @Override
    public ExtendedPropertiesAdapter defaultCase(EObject object) {
      ExtendedPropertiesAdapter adapter = null;
      if (object instanceof EClass) {
        // this is an EClass: search the current target runtime for an adapter that
        // can handle this thing.
        adapter = getTargetRuntimeAdapter((EClass) object);
        if (adapter == null) {
          // if none is found, create a dummy EObject and cache it
          object = ModelUtil.getDummyObject((EClass) object);
          adapter = doSwitch(object);
        }
      } else adapter = getTargetRuntimeAdapter(object);

      if (adapter == null) {
        adapter = new ExtendedPropertiesAdapter(adapterFactory, object);
        adapter.setObjectDescriptor(
            new ObjectDescriptor(adapterFactory, object) {
              @Override
              public String getLabel(Object context) {
                EObject object = this.object;
                if (context instanceof EObject) object = (EObject) context;
                if (ModelUtil.isStringWrapper(object)) {
                  return "Item Type";
                }
                return super.getLabel(context);
              }

              @Override
              public String getDisplayName(Object context) {
                EObject object = this.object;
                if (context instanceof EObject) object = (EObject) context;
                if (ModelUtil.isStringWrapper(object)) {
                  return ModelUtil.getStringWrapperValue(object);
                }
                return super.getDisplayName(context);
              }
            });
      }
      return adapter;
    }
 /**
  * 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;
 }
Пример #11
0
 public static EObject createObject(EObject object, EStructuralFeature feature, EClass eclass) {
   ExtendedPropertiesAdapter adapter =
       (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
   if (adapter != null) return adapter.getFeatureDescriptor(feature).createObject(object, eclass);
   return null;
 }
Пример #12
0
 public static boolean getIsMultiLine(EObject object, EStructuralFeature feature) {
   ExtendedPropertiesAdapter adapter =
       (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
   if (adapter != null) return adapter.getFeatureDescriptor(feature).isMultiLine(object);
   return false;
 }
    @SuppressWarnings("unchecked")
    @Override
    protected void internalSet(
        DataAssociation association, EStructuralFeature feature, Object value, int index) {
      EObject container = null;
      EStructuralFeature containerFeature = null;
      if (value instanceof Property) {
        if (((Property) value).eContainer() == null) {
          // this Property isn't owned by anything yet - figure out who the owner is
          container = ModelUtil.findNearestAncestor(association, new Class[] {Activity.class});
          if (container == null)
            container = ModelUtil.findNearestAncestor(association, new Class[] {Event.class});
          if (container == null)
            container = ModelUtil.findNearestAncestor(association, new Class[] {Process.class});
          containerFeature = container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$
        }
      } else if (value instanceof DataStore) {
        if (((DataStore) value).eContainer() == null) {
          // this DataStore isn't owned by anything yet - figure out who the owner is
          container = ModelUtil.findNearestAncestor(association, new Class[] {DocumentRoot.class});
          containerFeature = container.eClass().getEStructuralFeature("dataStore"); // $NON-NLS-1$
        }
      } else if (value instanceof String) {
        // first check if a property with this name already exists
        Hashtable<String, Object> choices = getChoiceOfValues();
        Property property = (Property) choices.get(value);
        if (property == null) {
          // need to create a new one!
          DiagramEditor editor = ModelUtil.getEditor(object);
          ModelEnablements modelEnablement =
              (ModelEnablements) editor.getAdapter(ModelEnablements.class);
          // find nearest element that can contain a Property and create one
          container = association;
          for (; ; ) {
            container =
                ModelUtil.findNearestAncestor(
                    container, new Class[] {Activity.class, Event.class, Process.class});
            if (container == null) return;
            containerFeature =
                container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$
            if (modelEnablement.isEnabled(container.eClass(), containerFeature)) break;
          }

          containerFeature = container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$
          property = Bpmn2ModelerFactory.create(Property.class);
          ExtendedPropertiesAdapter adapter = ExtendedPropertiesAdapter.adapt(property);
          adapter.getObjectDescriptor().setTextValue((String) value);
        }
        value = property;
      }

      final EObject c = container;
      final EStructuralFeature cf = containerFeature;
      final ItemAwareElement v = (ItemAwareElement) value;

      if (feature == Bpmn2Package.eINSTANCE.getDataAssociation_SourceRef()) {
        setSourceRef(association, v, c, cf);
      } else {
        setTargetRef(association, v, c, cf);
      }
    }