コード例 #1
0
 @Override
 public Object caseEReference(EReference object) {
   Attribute attrib = new Attribute(object.getName());
   attrib.type = getType(object.getEType());
   attrib.setBounds(object.getLowerBound(), object.getUpperBound());
   attrib.setStatic(false);
   attrib.setScope(Scope.PUBLIC);
   attrib.setContainment(object.isContainment());
   attrib.setDerived(object.isDerived());
   return attrib;
 }
  @Override
  public void initialize(IInitializationParticipantContext context, Object facet) {
    if (!(facet instanceof EReference)) return;
    final EReference ref = (EReference) facet;
    if (!ref.isRequired() || ref.isContainer()) return;

    final EObject object = context.getObject();

    if (ref.getUpperBound() != 1) {
      /*
       * A list
       */
      @SuppressWarnings("unchecked")
      final EList<? extends EObject> l =
          (EList<? extends EObject>) context.getStructuralFeature(ref);
      int missing = ref.getLowerBound() - l.size();
      if (missing < 0) return;

      final List<EObject> newChildren = new ArrayList<EObject>(missing);
      for (; missing > 0; missing--) {
        final EObject newChild = EcoreUtil.create(ref.getEReferenceType());
        context.addCommand(
            IManager.Factory.getManager()
                .initializeObject(context.getEditingDomain(), object, ref, newChild, false));
      }
      context.addCommand(AddCommand.create(context.getEditingDomain(), object, ref, newChildren));
    } else {
      /*
       * Simple object
       */
      final Object o = context.getStructuralFeature(ref);
      if (o != null) return;

      final EObject newChild = EcoreUtil.create(ref.getEReferenceType());
      context.addCommand(
          IManager.Factory.getManager()
              .initializeObject(context.getEditingDomain(), object, ref, newChild, true));
    }
  }