/**
   * Returns a chart element instance with default value.
   *
   * @param expected
   * @param name
   * @param eObj
   * @return a chart element instance with default value.
   */
  public EObject getDefault(EClass expected, String name, EObject eObj) {
    EObject def = defaultObjCache.get(eObj.getClass().getSimpleName());
    if (def != null) {
      return def;
    }

    Method m;
    try {
      m = eObj.getClass().getMethod("create"); // $NON-NLS-1$
      EObject object = (EObject) m.invoke(eObj);
      defaultObjCache.put(eObj.getClass().getSimpleName(), object);
      return object;
    } catch (SecurityException e) {
      logger.log(e);
    } catch (NoSuchMethodException e) {
      logger.log(e);
    } catch (IllegalArgumentException e) {
      logger.log(e);
    } catch (IllegalAccessException e) {
      logger.log(e);
    } catch (InvocationTargetException e) {
      logger.log(e);
    }
    return null;
  }
Example #2
0
 /**
  * Applique une suite d'actions sur tous les éléments d'une collection
  *
  * @param coll
  * @param todo
  */
 private void structureDoAll(Collection coll, EList<EObject> todo) {
   if (coll.getObj() != null) {
     for (Object o : coll.getObj()) {
       for (EObject action : todo) {
         if (ActionWithObject.class.isAssignableFrom(action.getClass())) {
           ActionWithObject awo = (ActionWithObject) action;
           awo.setObject(o);
           execute(awo);
         } else {
           execute(action);
         }
       }
     }
   } else {
     List<WebElement> list = findCollection(coll);
     for (WebElement we : list) {
       for (EObject action : todo) {
         if (ActionWithObject.class.isAssignableFrom(action.getClass())) {
           ActionWithObject awo = (ActionWithObject) action;
           awo.setObject((Object) we);
           execute(awo);
         } else {
           execute(action);
         }
       }
     }
   }
 }
Example #3
0
  @Test
  public void getAddedAndRemoved() {
    final EObject obj00 = EcoreUtil.create(eClass0);
    final EObject obj1 = EcoreUtil.create(eClass1);
    final EObject obj01 = EcoreUtil.create(eClass0);
    final EObject obj02 = EcoreUtil.create(eClass0);
    final List<Notification> messages = new ArrayList<Notification>();
    obj1.eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                messages.add(msg);
              }
            });

    // Add
    obj1.eSet(multiRef, Arrays.asList(new EObject[] {obj00, obj01}));
    EMFUtils.setOrAdd(obj1, multiRef, obj02);

    // Remove
    final List list = (List) obj1.eGet(multiRef);
    list.remove(obj00);
    list.removeAll(Arrays.asList(new EObject[] {obj01, obj02}));

    final List<EObject> addedObjects = new ArrayList<EObject>();
    final List<EObject> removedObjects = new ArrayList<EObject>();
    for (Notification msg : messages) {
      addedObjects.addAll(EMFUtils.getAddedObjects(msg, obj00.getClass()));
      removedObjects.addAll(EMFUtils.getRemovedObjects(msg, obj00.getClass()));
    }

    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), addedObjects);
    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), removedObjects);
  }
 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;
 }
  public ModelSpecificEvent findOrCreateMSE(EObject caller, String className, String methodName) {

    EOperation operation = findOperation(caller, className, methodName);

    // TODO Should be created somewhere before...
    // at some point didier had written some code to serialize it... I think
    if (_actionModel == null) {
      _actionModel =
          fr.inria.aoste.timesquare.ecl.feedback.feedback.FeedbackFactory.eINSTANCE
              .createActionModel();
    }

    if (_actionModel != null) {
      for (ModelSpecificEvent existingMSE : _actionModel.getEvents()) {
        if (existingMSE.getCaller().equals(caller)
            && ((existingMSE.getAction() != null && existingMSE.getAction().equals(operation))
                || (existingMSE.getAction() == null && operation == null))) {
          // no need to create one, we already have it
          return existingMSE;
        }
      }
    }
    // let's create a MSE
    final ModelSpecificEvent mse = FeedbackFactory.eINSTANCE.createModelSpecificEvent();
    mse.setCaller(caller);
    mse.setAction(operation);
    if (operation != null)
      mse.setName("MSE_" + caller.getClass().getSimpleName() + "_" + operation.getName());
    else mse.setName("MSE_" + caller.getClass().getSimpleName() + "_" + methodName);
    // and add it for possible reuse
    if (_actionModel != null) {

      if (_actionModel.eResource() != null) {
        TransactionUtil.getEditingDomain(_actionModel.eResource());
        RecordingCommand command =
            new RecordingCommand(
                TransactionUtil.getEditingDomain(_actionModel.eResource()), "Saving new MSE ") {
              @Override
              protected void doExecute() {
                _actionModel.getEvents().add(mse);
                try {
                  _actionModel.eResource().save(null);
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            };
        TransactionUtil.getEditingDomain(_actionModel.eResource())
            .getCommandStack()
            .execute(command);
      }
    } else {
      _actionModel.getEvents().add(mse);
    }
    return mse;
  }
 protected boolean isMatch(EObject source, EObject target) {
   if (source.getClass().equals(target.getClass())) {
     return false;
   } else if (source instanceof UsesPortStub) {
     return InterfacesUtil.areSuggestedMatch((UsesPortStub) source, target);
   } else if (target instanceof UsesPortStub) {
     return InterfacesUtil.areSuggestedMatch((UsesPortStub) target, source);
   }
   return false;
 }
Example #7
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public IComment addComment() {
   org.eclipse.emf.ecore.EPackage ePackage =
       org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage(
           "http://www.openhealthtools.org/mdht/uml/cda/apitest");
   org.eclipse.emf.ecore.EFactory eFactory =
       org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEFactory(
           "http://www.openhealthtools.org/mdht/uml/cda/apitest");
   org.eclipse.emf.ecore.EClass eClass =
       (org.eclipse.emf.ecore.EClass) ePackage.getEClassifier("Comment");
   org.eclipse.emf.ecore.EObject eObject = eFactory.create(eClass);
   try {
     java.lang.reflect.Method initMethod =
         eObject.getClass().getMethod("init", new java.lang.Class[0]);
     initMethod.invoke(eObject, new Object[0]);
   } catch (Exception e) {
     // no init() method
   }
   org.eclipse.emf.ecore.EPackage domainPackage = this.eClass().getEPackage();
   org.eclipse.emf.ecore.EFactory domainFactory = domainPackage.getEFactoryInstance();
   org.eclipse.emf.ecore.EClass domainEClass =
       (org.eclipse.emf.ecore.EClass) domainPackage.getEClassifier("IComment");
   IComment value = (IComment) domainFactory.create(domainEClass);
   value.setCDAType((org.openhealthtools.mdht.uml.cda.Act) eObject);
   this.getCDAType().addAct((org.openhealthtools.mdht.uml.cda.Act) eObject);
   return value;
 }
Example #8
0
 @Override
 public <@NonNull T extends NamedElement> T refreshElement(
     @NonNull Class<T> pivotClass, EClass pivotEClass, @NonNull EModelElement eModelElement) {
   EObject pivotElement = null;
   if (oldIdMap != null) {
     String id = ((XMLResource) eModelElement.eResource()).getID(eModelElement);
     if (id != null) {
       pivotElement = oldIdMap.get(id);
       if ((pivotElement != null) && (pivotElement.eClass() != pivotEClass)) {
         pivotElement = null;
       }
     }
   }
   if (pivotElement == null) {
     EFactory eFactoryInstance = pivotEClass.getEPackage().getEFactoryInstance();
     pivotElement = eFactoryInstance.create(pivotEClass);
   }
   if (!pivotClass.isAssignableFrom(pivotElement.getClass())) {
     throw new ClassCastException();
   }
   @SuppressWarnings("unchecked")
   T castElement = (T) pivotElement;
   Element oldElement = newCreateMap.put(eModelElement, castElement);
   assert oldElement == null;
   return castElement;
 }
 public static String getStereotype(EObject element) {
   String type = element.getClass().toString().replaceAll("class RefOntoUML.impl.", "");
   type = type.replaceAll("Impl", "");
   type = Normalizer.normalize(type, Normalizer.Form.NFD);
   if (!type.equalsIgnoreCase("association")) type = type.replace("Association", "");
   return type;
 }
Example #10
0
 private static <T> T getBusinessObjectByClass(PictogramElement pelem, Class<T> class1) {
   PictogramLink link = pelem.getLink();
   if (link == null) return null;
   for (EObject businessObject : link.getBusinessObjects()) {
     if (class1.isAssignableFrom(businessObject.getClass())) return (T) businessObject;
   }
   return null;
 }
  @Override
  public boolean apply(EObject eObject) {
    for (Class<?> clazz : this.classes) {
      if (clazz.isAssignableFrom(eObject.getClass())) {
        return true;
      }
    }

    return false;
  }
 @SuppressWarnings("unchecked")
 public static <T extends EObject> List<T> getContentsOfType(EObject ele, Class<T> type) {
   List<T> result = new ArrayList<T>();
   if (ele == null) return result;
   for (EObject object : ele.eContents()) {
     if (type.isAssignableFrom(object.getClass())) {
       result.add((T) object);
     }
   }
   return result;
 }
Example #13
0
 @SuppressWarnings("unchecked")
 private static <T extends EPlanElement, C> T getPlanElementFromParameterNotifier(
     Object notifier, Class<T> planElementType, Class<C> defType) {
   if (notifier instanceof EObject
       && defType.isAssignableFrom(((EObject) notifier).eClass().getClass())) {
     EObject object = (EObject) notifier;
     EObject container = object.eContainer();
     if (planElementType.isAssignableFrom(container.getClass())) {
       T element = ((T) container);
       if (element.getData() == object) {
         return element;
       }
     }
   }
   return null;
 }
Example #14
0
  public static ThingMLElement findReferenceContainer(Reference container) {
    EObject parent = container.eContainer();
    List<String> parents = new ArrayList<String>();

    while (parent != null
        && !(parent instanceof Handler
            || parent instanceof Stream
            || parent instanceof SourceComposition
            || parent instanceof SimpleSource)) {
      parents.add(parent.getClass().getName());
      parent = parent.eContainer();
    }
    if (parent == null) {
      for (String p : parents) {
        System.out.println("Parent:" + parent);
      }
    }
    return (ThingMLElement) parent;
  }
Example #15
0
  /**
   * switch case for ALL orders
   *
   * @param e the EObject w'd like to know more about
   */
  private void execute(EObject e) {
    if (e instanceof Refresh) {
      refresh();
    } else if (e instanceof Navigate) {
      navigateTo(((Navigate) e).getUrl());
    } else if (e instanceof Store) {
      store((Store) e);
    } else if (e instanceof ReDefine) {
      redefine((ReDefine) e);
    } else if (e instanceof Delete) {
      delete((Delete) e);
    } else if (e instanceof ActionSelect) {
      select((ActionSelect) e);
    } else if (e instanceof ActionWithObject) {
      ActionWithObject awo = (ActionWithObject) e;
      execute(awo.getObject(), awo);
    } else if (e instanceof CheckBox) {
      tickBox((CheckBox) e);
    } else if (e instanceof Rickroll) {
      rickRoll();
    } else if (e instanceof DoWait) {
      waitFor(((DoWait) e).getMillisec());
    }
    // conditions :
    else if (Condition.class.isAssignableFrom(e.getClass())) {
      eval((Condition) e);
    }
    // structures :
    else if (e instanceof If) {
      If i = ((If) e);
      structureIf(i.getCond(), i.getActionThen(), i.getActionElse());
    } else if (e instanceof Loop) {
      Loop i = (Loop) e;
      structureLoop(i.getCond(), i.getMilliseconds(), i.getActions());
    } else if (e instanceof DoAll) {
      DoAll i = (DoAll) e;
      structureDoAll(i.getColl(), i.getTodo());
    } else if (e instanceof Execute) {

      executeSubProcedure((Execute) e);
    }
  }
  /**
   * A helper method to check whether a certain parameter has been defined multiple times. To use
   * this method, the parameters have to be implemented as an own EClass in the Ecore model and they
   * have to be assigned using an EReference with the name <tt>params</tt>.
   *
   * <p>Example of such a parameter definition in Xtext:
   *
   * <pre>
   * GridLayoutPane:
   *    'GridLayoutPane' name = ID '(' (params += GridLayoutPaneParam (',' params += GridLayoutPaneParam)*)? ')' '{'
   *       elements += ViewElementType*
   *    '}'
   * ;
   *
   * GridLayoutPaneParam:
   *    {Columns} 'columns' value = INT | {Rows} 'rows' value = INT
   * ;
   * </pre>
   *
   * As the last parameter <tt>eClassToNameMapping</tt> of this method a HashMap is needed that
   * contains key-value-pairs for each defined parameter for which duplicity has to be checked. As
   * key the EClass name of the parameter (e.g. "Columns") has to be set, as the value the parameter
   * name in the defined language is expected (e.g. "rows").
   *
   * @param element The element for which the params have been defined. It is expected that the
   *     element contains an EReference with the name <tt>params</tt>.
   * @param literal The structural feature in the defined language on which the validation error
   *     should be marked.
   * @param acceptor Instance of the validator that calls this method.
   * @param eClassToNameMapping A HashMap that contains key-value-pairs for each defined parameter
   *     for which duplicity has to be checked.
   */
  public void repeatedParamsError(
      EObject element,
      EStructuralFeature literal,
      ValidationMessageAcceptor acceptor,
      HashMap<String, String> eClassToNameMapping) {

    Set<String> set = Sets.newHashSet();

    try {
      Method m = element.getClass().getMethod("getParams");
      Object params = m.invoke(element);

      assert params instanceof EList : "Expects params to be an instance of EList";

      for (Object param : EList.class.cast(params)) {
        String name = ((EObject) param).eClass().getName();
        if (set.contains(name)) {
          acceptor.acceptError(
              "Parameter \"" + eClassToNameMapping.get(name) + "\" has been defined multiple times",
              element,
              literal,
              -1,
              null);
          break;
        } else {
          set.add(name);
        }
      }
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
Example #17
0
 public static <C> C findContainer(EObject eObject, Class<C> cClass) {
   while (eObject != null && !cClass.isAssignableFrom(eObject.getClass())) {
     eObject = eObject.eContainer();
   }
   return (C) eObject;
 }
 protected String contextToString() {
   return element.getClass().getSimpleName().replaceAll("Impl", "")
       + "#"
       + ModelUtil.getFeature(element, "id");
 }