Example #1
0
  public Usage buildUsage(final Object client, final Object supplier) {
    if (!(client instanceof NamedElement) || !(supplier instanceof NamedElement)) {
      throw new IllegalArgumentException(
          "The client and the supplier must be NamedElements."); //$NON-NLS-1$
    }
    if (((NamedElement) client).getNearestPackage() == null) {
      throw new NullPointerException("The client is not contained in a package."); // $NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Usage usage = createUsage();
            usage.getClients().add((NamedElement) client);
            usage.getSuppliers().add((NamedElement) supplier);
            ((NamedElement) client).getNearestPackage().getPackagedElements().add(usage);
            getParams().add(usage);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl, run, "Create the usage # between the client # and the supplier #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), client, supplier);

    return (Usage) run.getParams().get(0);
  }
Example #2
0
  public Comment buildComment(final Object element, final Object model) {
    if (!(model instanceof Namespace)) {
      throw new IllegalArgumentException("A namespace must be supplied."); // $NON-NLS-1$
    }
    if (element != null && !(element instanceof Element)) {
      throw new IllegalArgumentException(
          "The annotated element must be instance of Element."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Comment comment = createComment();
            if (element != null) {
              comment.getAnnotatedElements().add((Element) element);
            }
            ((Namespace) model).getOwnedComments().add(comment);
            getParams().add(comment);
          }
        };
    ChangeCommand cmd;
    if (element == null) {
      cmd = new ChangeCommand(modelImpl, run, "Create the comment #");
    } else {
      cmd = new ChangeCommand(modelImpl, run, "Create the comment # attached to the element #");
    }
    editingDomain.getCommandStack().execute(cmd);
    if (element == null) {
      cmd.setObjects(run.getParams().get(0));
    } else {
      cmd.setObjects(run.getParams().get(0), element);
    }

    return (Comment) run.getParams().get(0);
  }
Example #3
0
  public Parameter buildParameter(final Object o, final Object type) {
    // TODO: In UML2.x Event has no parameters. The Event metaclass in
    // UML1.x corresponds to the Trigger metaclass in UML2.x (see UML
    // Superstructure page 456).
    if (!(o instanceof BehavioralFeature)) {
      throw new IllegalArgumentException(
          "The parameter must be attached to a BehavioralFeature."); //$NON-NLS-1$
    }
    if (!(type instanceof Type)) {
      throw new IllegalArgumentException(
          "The type of the parameter must be instance of Type."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Parameter param = createParameter();
            param.setType((Type) type);
            // TODO: Remove?  Can't be localized
            param.setName("arg" + ((BehavioralFeature) o).getOwnedParameters().size());
            ((BehavioralFeature) o).getOwnedParameters().add(param);
            getParams().add(param);
          }
        };
    ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the parameter # owned by #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), o);

    return (Parameter) run.getParams().get(0);
  }
Example #4
0
  private PackageImport buildPackageImport(
      final Object client, final Object supplier, final VisibilityKind visibility) {
    if (!(client instanceof Namespace)) {
      throw new IllegalArgumentException(
          "The client must be instance of Namespace."); //$NON-NLS-1$
    }
    if (!(supplier instanceof org.eclipse.uml2.uml.Package)) {
      throw new IllegalArgumentException(
          "The supplier must be instance of Package."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            PackageImport packageImport = createPackageImport();
            packageImport.setImportedPackage((org.eclipse.uml2.uml.Package) supplier);
            packageImport.setImportingNamespace((Namespace) client);
            if (visibility != null) {
              packageImport.setVisibility(visibility);
            }
            getParams().add(packageImport);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl, run, "Create the package import # between the client # and the supplier #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), client, supplier);

    return (PackageImport) run.getParams().get(0);
  }
Example #5
0
  public Interface buildInterface(final String name, final Object owner) {
    if (!(owner instanceof org.eclipse.uml2.uml.Package)
        && !(owner instanceof org.eclipse.uml2.uml.Class)
        && !(owner instanceof Interface)) {
      throw new IllegalArgumentException(
          "The owner must be instance of Package"
              + //$NON-NLS-1$
              " or UML2 Class or Interface."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Interface interfaze = createInterface();
            if (owner instanceof org.eclipse.uml2.uml.Package) {
              interfaze.setPackage((org.eclipse.uml2.uml.Package) owner);
            } else if (owner instanceof org.eclipse.uml2.uml.Class) {
              ((org.eclipse.uml2.uml.Class) owner).getNestedClassifiers().add(interfaze);
            } else if (owner instanceof Interface) {
              ((Interface) owner).getNestedClassifiers().add(interfaze);
            }
            if (name != null) {
              interfaze.setName(name);
            }
            getParams().add(interfaze);
          }
        };
    ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the interface # owned by #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), owner);

    return (Interface) run.getParams().get(0);
  }
Example #6
0
  public Operation buildOperation2(final Object cls, final Object returnType, final String name) {
    if ((returnType != null && !(returnType instanceof Type)) || !(cls instanceof Type)) {
      throw new IllegalArgumentException(
          "cls and returnType must be instances of Type."); //$NON-NLS-1$
    }
    if (UMLUtil.getOwnedOperations((Type) cls) == null) {
      throw new UnsupportedOperationException(
          "The type "
              + cls.getClass() // $NON-NLS-1$
              + " does not support owning operations."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Operation operation = createOperation();
            UMLUtil.getOwnedOperations((Type) cls).add(operation);
            operation.createReturnResult("return", (Type) returnType);
            if (name != null) {
              operation.setName(name);
            } else {
              // TODO: Remove?  Can't be localized
              operation.setName("newOperation");
            }
            getParams().add(operation);
          }
        };
    ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the operation # owned by #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), cls);

    return (Operation) run.getParams().get(0);
  }
Example #7
0
  public Dependency buildDependency(final Object clientObj, final Object supplierObj) {
    if (!(clientObj instanceof NamedElement) || !(supplierObj instanceof NamedElement)) {
      throw new IllegalArgumentException(
          "The client and the supplier must be" //$NON-NLS-1$
              + " instances of NamedElement."); //$NON-NLS-1$
    }
    if (((NamedElement) clientObj).getNearestPackage() == null) {
      throw new NullPointerException(
          "The containing package of the client must be non-null."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Dependency dependency = createDependency();
            dependency.getClients().add((NamedElement) clientObj);
            dependency.getSuppliers().add((NamedElement) supplierObj);
            ((NamedElement) clientObj).getNearestPackage().getPackagedElements().add(dependency);
            getParams().add(dependency);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl, run, "Create the dependency # between the" + " client # and the supplier #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), clientObj, supplierObj);

    return (Dependency) run.getParams().get(0);
  }
Example #8
0
  public InterfaceRealization buildRealization(
      final Object client, final Object supplier, Object namespace) {
    // The interface realization will be created in the client namespace
    // (client is a namespace)
    if (!(client instanceof BehavioredClassifier)) {
      throw new IllegalArgumentException(
          "The client must be instance of BehavioredClassifier"); //$NON-NLS-1$
    }
    if (!(supplier instanceof Interface)) {
      throw new IllegalArgumentException("The supplier must be an Interface"); // $NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            InterfaceRealization realization = UMLFactory.eINSTANCE.createInterfaceRealization();
            realization.setImplementingClassifier((BehavioredClassifier) client);
            realization.setContract((Interface) supplier);
            ((BehavioredClassifier) client).getInterfaceRealizations().add(realization);
            getParams().add(realization);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl,
            run,
            "Create the interface realization # between" //$NON-NLS-1$
                + " the client # and the supplier #"); //$NON-NLS-1$
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), client, supplier);

    return (InterfaceRealization) run.getParams().get(0);
  }
Example #9
0
  public Constraint buildConstraint(final Object constrElement) {
    if (!(constrElement instanceof Element)) {
      throw new IllegalArgumentException(
          "The constrained element must be instance of Element."); //$NON-NLS-1$
    }
    if (((Element) constrElement).getNearestPackage() == null) {
      throw new NullPointerException(
          "The containing package of the constrained" //$NON-NLS-1$
              + " element must be non-null."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Constraint constraint = createConstraint();
            constraint.getConstrainedElements().add((Element) constrElement);
            getParams().add(constraint);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the constraint # that constrains the element #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), constrElement);

    return (Constraint) run.getParams().get(0);
  }
Example #10
0
  public Property buildAttribute2(final Object handle, final Object type) {
    if (!(handle instanceof Type)) {
      throw new IllegalArgumentException("handle must be instance of Type."); // $NON-NLS-1$
    }
    if (type != null && !(type instanceof Type)) {
      throw new IllegalArgumentException("type must be instance of Type."); // $NON-NLS-1$
    }
    if (UMLUtil.getOwnedAttributes((Type) handle) == null) {
      throw new UnsupportedOperationException(
          "The type "
              + handle.getClass() // $NON-NLS-1$
              + " does not support owning attributes."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Property property = createAttribute();
            UMLUtil.getOwnedAttributes((Type) handle).add(property);
            if (type != null) {
              property.setType((Type) type);
            }
            property.setName("newAttr");
            getParams().add(property);
          }
        };
    ChangeCommand cmd = new ChangeCommand(modelImpl, run, "Create the attribute # of the type #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), handle);

    return (Property) run.getParams().get(0);
  }
Example #11
0
  public TemplateBinding buildTemplateBinding(
      final Object client, final Object supplier, final List arguments) {
    // TODO: Is it appropriate the TemplateableElement as the client and a
    // list of TemplateParameterSubstitution as the list of parameters?
    if (!(client instanceof TemplateableElement)) {
      throw new IllegalArgumentException(
          "The supplier must be instance of "
              + //$NON-NLS-1$
              "TemplateableElement."); //$NON-NLS-1$
    }
    if (!(supplier instanceof TemplateSignature)) {
      throw new IllegalArgumentException(
          "The supplier must be instance of "
              + //$NON-NLS-1$
              "TemplateSignature."); //$NON-NLS-1$
    }
    if (arguments != null) {
      for (Object o : arguments) {
        if (!(o instanceof TemplateParameterSubstitution)) {
          throw new IllegalArgumentException(
              "The list of arguments must be instances"
                  + //$NON-NLS-1$
                  " of TemplateParameterSubstitutions."); //$NON-NLS-1$
        }
      }
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            TemplateBinding templateBinding = createTemplateBinding();
            templateBinding.setBoundElement((TemplateableElement) client);
            templateBinding.setSignature((TemplateSignature) supplier);
            if (arguments != null) {
              for (Object o : arguments) {
                templateBinding.getParameterSubstitutions().add((TemplateParameterSubstitution) o);
              }
            }
            getParams().add(templateBinding);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl,
            run,
            "Create the template binding # between " + "the client # and the supplier #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), client, supplier);

    return (TemplateBinding) run.getParams().get(0);
  }
Example #12
0
  public AssociationClass buildAssociationClass(final Object end1, final Object end2) {
    if (!(end1 instanceof Type) || !(end2 instanceof Type)) {
      throw new IllegalArgumentException("end1 and end2 must be instances of Type"); // $NON-NLS-1$
    }
    if (((Type) end1).getNearestPackage() == null) {
      throw new NullPointerException(
          "The containing package of "
              + //$NON-NLS-1$
              "the end1 must be non-null."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            AssociationClass associationClass = createAssociationClass();
            Property property1 = createAssociationEnd();
            Property property2 = createAssociationEnd();
            property1.setType((Type) end2);
            property2.setType((Type) end1);
            property1.setAssociation(associationClass);
            property2.setAssociation(associationClass);
            ((Type) end1).getNearestPackage().getPackagedElements().add(associationClass);
            if (UMLUtil.getOwnedAttributes((Type) end1) == null) {
              associationClass.getOwnedAttributes().add(property1);
            } else {
              UMLUtil.getOwnedAttributes((Type) end1).add(property1);
            }
            if (UMLUtil.getOwnedAttributes((Type) end2) == null) {
              associationClass.getOwnedAttributes().add(property2);
            } else {
              UMLUtil.getOwnedAttributes((Type) end2).add(property2);
            }
            getParams().add(associationClass);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the association class # between # and #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), end1, end2);

    return (AssociationClass) run.getParams().get(0);
  }
Example #13
0
  public Generalization buildGeneralization(final Object child, final Object parent) {
    if (!(child instanceof Classifier) || !(parent instanceof Classifier)) {
      throw new IllegalArgumentException(
          "The general (the parent) and the specific (the child) must be instances of Classifier."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Generalization generalization = createGeneralization();
            generalization.setGeneral((Classifier) parent);
            generalization.setSpecific((Classifier) child);
            getParams().add(generalization);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl, run, "Create the generalization # between # (general) and # (specific)");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), parent, child);

    return (Generalization) run.getParams().get(0);
  }
Example #14
0
  public Abstraction buildAbstraction(
      final String name, final Object supplier, final Object client) {
    if (!(client instanceof NamedElement) || !(supplier instanceof NamedElement)) {
      throw new IllegalArgumentException(
          "The client and the supplier "
              + //$NON-NLS-1$
              "must be NamedElements."); //$NON-NLS-1$
    }
    if (((NamedElement) client).getNearestPackage() == null) {
      throw new NullPointerException(
          "The containing package of the client "
              + //$NON-NLS-1$
              "must be non-null."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Abstraction abstraction = createAbstraction();
            if (name != null) {
              abstraction.setName(name);
            }
            abstraction.getSuppliers().add((NamedElement) supplier);
            abstraction.getClients().add((NamedElement) client);
            ((NamedElement) client).getNearestPackage().getPackagedElements().add(abstraction);
            getParams().add(abstraction);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(
            modelImpl,
            run,
            "Create the abstraction # between "
                + //$NON-NLS-1$
                "the client # and the supplier #"); //$NON-NLS-1$
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), client, supplier);

    return (Abstraction) run.getParams().get(0);
  }
Example #15
0
  public EnumerationLiteral buildEnumerationLiteral(final String name, final Object enumeration) {
    if (!(enumeration instanceof Enumeration)) {
      throw new IllegalArgumentException(
          "The enumeration must be instance of Enumeration."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            EnumerationLiteral enumerationLiteral = createEnumerationLiteral();
            if (name != null) {
              enumerationLiteral.setName(name);
            }
            enumerationLiteral.setEnumeration((Enumeration) enumeration);
            getParams().add(enumerationLiteral);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the enumeration literal # owned by #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), enumeration);

    return (EnumerationLiteral) run.getParams().get(0);
  }
Example #16
0
  private Property buildAssociationEnd(
      final Object assoc,
      final String name,
      final Object type,
      final Object multi,
      final Object stereo,
      final Boolean navigable,
      final Object order,
      final Object aggregation,
      final Object scope,
      final Object changeable,
      final Object visibility) {
    // The attribute 'targetScope' of an AssociationEnd in UML1.x is no
    // longer supported in UML2.x
    if (!(assoc instanceof Association)) {
      throw new IllegalArgumentException(
          "The assoc must be instance of Association."); //$NON-NLS-1$
    }
    if (!(type instanceof Type)) {
      throw new IllegalArgumentException(
          "The type of the property "
              + //$NON-NLS-1$
              "must be instance of Type."); //$NON-NLS-1$
    }
    if (aggregation != null && !(aggregation instanceof AggregationKind)) {
      throw new IllegalArgumentException(
          "The aggregation of the property "
              + //$NON-NLS-1$
              "must be instance of AggregationKind."); //$NON-NLS-1$
    }
    if (visibility != null && !(visibility instanceof VisibilityKind)) {
      throw new IllegalArgumentException(
          "The visibility of the property must"
              + //$NON-NLS-1$
              " be instance of VisibilityKind."); //$NON-NLS-1$
    }
    if (multi != null && !(multi instanceof MultiplicityElement)) {
      throw new IllegalArgumentException(
          "The multilicity of the property must"
              + //$NON-NLS-1$
              " be instance of MultiplicityElement."); //$NON-NLS-1$
    }
    MultiplicityElement m = (MultiplicityElement) multi;
    final int lower = m.getLower();
    final int upper = m.getUpper();
    if ((order != null && !(order instanceof Boolean))
        || (changeable != null && !(changeable instanceof Boolean))) {
      throw new IllegalArgumentException(
          "The isOrdered, isReadOnly attributes of "
              + //$NON-NLS-1$
              "the property must be instances of Boolean."); //$NON-NLS-1$
    }
    if (stereo != null && !(stereo instanceof Stereotype)) {
      throw new IllegalArgumentException("stereo must be instance of Stereotype."); // $NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Property property =
                buildAssociationEndInternal(
                    (Association) assoc,
                    name,
                    (Type) type,
                    new Integer[] {lower, upper},
                    (Stereotype) stereo,
                    navigable,
                    (Boolean) order,
                    (AggregationKind) aggregation,
                    (Boolean) scope,
                    (Boolean) changeable,
                    (VisibilityKind) visibility);
            getParams().add(property);
          }
        };
    modelImpl.getModelEventPump().getRootContainer().setHoldEvents(true);
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the association end # of the association #");
    editingDomain.getCommandStack().execute(cmd);
    if (run.getParams().isEmpty()) {
      editingDomain.getCommandStack().undo();
      editingDomain.getCommandStack().flush();
      modelImpl.getModelEventPump().getRootContainer().clearHeldEvents();
      modelImpl.getModelEventPump().getRootContainer().setHoldEvents(false);
      throw new UnsupportedOperationException(
          "This stereotype cannot be applied "
              + //$NON-NLS-1$
              "to the association end."); //$NON-NLS-1$
    }
    cmd.setObjects(run.getParams().get(0), assoc);
    modelImpl.getModelEventPump().getRootContainer().setHoldEvents(false);

    return (Property) run.getParams().get(0);
  }
Example #17
0
  private Association buildAssociation(
      final Object type1,
      final Boolean navigability1,
      final Object aggregationKind1,
      final Object type2,
      final Boolean navigability2,
      final Object aggregationKind2,
      final String associationName) {
    if (!(type1 instanceof Type) || !(type2 instanceof Type)) {
      throw new IllegalArgumentException("The types must be instances of Type."); // $NON-NLS-1$
    }
    if ((aggregationKind1 != null && !(aggregationKind1 instanceof AggregationKind))
        || (aggregationKind2 != null && !(aggregationKind2 instanceof AggregationKind))) {
      throw new IllegalArgumentException(
          "The aggregations of the association ends"
              + //$NON-NLS-1$
              " must be instances of AggregationKind."); //$NON-NLS-1$
    }
    if (((Type) type1).getNearestPackage() == null) {
      throw new NullPointerException(
          "The containing package of the type1"
              + //$NON-NLS-1$
              " must be non-null."); //$NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Association association = createAssociation();
            Property property1 =
                buildAssociationEndInternal(
                    association,
                    null,
                    (Type) type1,
                    null,
                    null,
                    navigability1,
                    null,
                    (AggregationKind) aggregationKind1,
                    null,
                    null,
                    null);
            Property property2 =
                buildAssociationEndInternal(
                    association,
                    null,
                    (Type) type2,
                    null,
                    null,
                    navigability2,
                    null,
                    (AggregationKind) aggregationKind2,
                    null,
                    null,
                    null);
            if (associationName != null) {
              association.setName(associationName);
            }
            association.getOwnedEnds().add(property1);
            association.getOwnedEnds().add(property2);
            // The code below will make navigable ends owned by the classifier
            // at the opposite end, but let's just make them owned by the association
            // for simplicity (don't assume everything will be like this though!)
            // Bob says - see page 42 and 43 of UML2.2 superstructure
            // for info on property ownership. Default will be association ownership
            // but we need a way for the user to change to classifier ownership at a
            // later time.
            //                if (UMLUtil.getOwnedAttributes((Type) type2) == null) {
            //                    association.getOwnedEnds().add(property1);
            //                } else {
            //                    UMLUtil.getOwnedAttributes((Type) type2).add(property1);
            //                }
            //                if (UMLUtil.getOwnedAttributes((Type) type1) == null) {
            //                    association.getOwnedEnds().add(property2);
            //                } else {
            //                    UMLUtil.getOwnedAttributes((Type) type1).add(property2);
            //                }
            //
            ((Type) type1).getNearestPackage().getPackagedElements().add(association);
            getParams().add(association);
          }
        };
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the association # between # and #");
    editingDomain.getCommandStack().execute(cmd);
    cmd.setObjects(run.getParams().get(0), type1, type2);

    return (Association) run.getParams().get(0);
  }