/**
   * @see
   *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   * @param event
   * @return null
   * @throws ExecutionException
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    EObject selectedObject = getSelectedElement();

    // test if this is a constraint
    if (selectedObject instanceof Constraint) {
      Constraint constraint = (Constraint) selectedObject;

      // test if this is an opaqueExpression
      if (constraint.getSpecification() instanceof OpaqueExpression) {
        OpaqueExpression opaqueExpression = ((OpaqueExpression) constraint.getSpecification());

        // look for the good body named OCL
        int indexOfOCLBody = -1;
        for (int i = 0; i < opaqueExpression.getLanguages().size() && indexOfOCLBody == -1; i++) {
          if (opaqueExpression.getLanguages().get(i).equals("OCL")) {
            indexOfOCLBody = i;
          }
        }
        if (indexOfOCLBody != -1) {
          try {
            OCLEvaluationView view =
                (OCLEvaluationView)
                    HandlerUtil.getActiveWorkbenchWindow(event)
                        .getActivePage()
                        .showView(OCLEvaluationView.ID);
            view.compute(constraint.getContext(), opaqueExpression.getBodies().get(indexOfOCLBody));
          } catch (PartInitException e) {
            e.printStackTrace();
          }
        }
      }
    }

    return null;
  }
 /**
  * Returns operation modifiers as string, separated with comma.
  *
  * @return a string containing the modifiers
  */
 private static String getModifiersAsString(Operation operation) {
   StringBuffer buffer = new StringBuffer();
   boolean needsComma = false;
   // Return parameter modifiers
   Parameter returnParameter = OperationUtil.getReturnParameter(operation);
   if (returnParameter != null) {
     // non unique parameter
     if (!returnParameter.isUnique()) {
       buffer.append("nonunique");
       needsComma = true;
     }
     // return parameter has ordered values
     if (returnParameter.isOrdered()) {
       if (needsComma) {
         buffer.append(", ");
       }
       buffer.append("ordered");
       needsComma = true;
     }
   }
   // is the operation a query ?
   if (operation.isQuery()) {
     if (needsComma) {
       buffer.append(", ");
     }
     buffer.append("query");
     needsComma = true;
   }
   // is the operation redefining another operation ?
   Iterator<Operation> it = operation.getRedefinedOperations().iterator();
   while (it.hasNext()) {
     Operation currentOperation = it.next();
     if (needsComma) {
       buffer.append(", ");
     }
     buffer.append("redefines ");
     buffer.append(currentOperation.getName());
     needsComma = true;
   }
   // has the operation a constraint ?
   Iterator<Constraint> it2 = operation.getOwnedRules().iterator();
   while (it2.hasNext()) {
     Constraint constraint = it2.next();
     if (needsComma) {
       buffer.append(", ");
     }
     if (constraint.getSpecification() != null) {
       buffer.append(constraint.getSpecification().stringValue());
     }
     needsComma = true;
   }
   return buffer.toString();
 }
Exemple #3
0
 public Constraint buildConstraint(String name, Object bexpr) {
   // TODO: BooleanExpresion is removed from UML2.x, is it OK to use
   // ValueSpecification?
   if (!(bexpr instanceof ValueSpecification)) {
     throw new IllegalArgumentException(
         "The 'bexpr' value specification must be " //$NON-NLS-1$
             + "instance of ValueSpecification"); //$NON-NLS-1$
   }
   Constraint constraint = createConstraint();
   if (name != null) {
     constraint.setName(name);
   }
   constraint.setSpecification((ValueSpecification) bexpr);
   return constraint;
 }
  /** @generated */
  public void init_Constraint_2008(Constraint instance) {
    try {
      OpaqueExpression newInstance_0_0 = UMLFactory.eINSTANCE.createOpaqueExpression();
      instance.setSpecification(newInstance_0_0);
      Object value_0_0_0 =
          UMLOCLFactory.getExpression(13, UMLPackage.eINSTANCE.getOpaqueExpression(), null)
              .evaluate(newInstance_0_0);
      if (value_0_0_0 instanceof Collection) {
        newInstance_0_0.getLanguages().clear();
        newInstance_0_0.getLanguages().addAll(((Collection) value_0_0_0));
      } else {
        newInstance_0_0.getLanguages().add((String) value_0_0_0);
      }
      Object value_0_0_1 =
          UMLOCLFactory.getExpression(14, UMLPackage.eINSTANCE.getOpaqueExpression(), null)
              .evaluate(newInstance_0_0);
      if (value_0_0_1 instanceof Collection) {
        newInstance_0_0.getBodies().clear();
        newInstance_0_0.getBodies().addAll(((Collection) value_0_0_1));
      } else {
        newInstance_0_0.getBodies().add((String) value_0_0_1);
      }

    } catch (RuntimeException e) {
      UMLDiagramEditorPlugin.getInstance()
          .logError("Element initialization failed", e); // $NON-NLS-1$				
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
   * org.eclipse.core.runtime.IAdaptable)
   */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    if (diagramEP != null && getEditingDomain() != null) {
      diagramEP.refresh();
      Namespace context = constraint.getContext();
      Collection<EditPart> allTopSemanticEditPart =
          DiagramEditPartsUtil.getAllTopSemanticEditPart(diagramEP);
      EditPart constraintEditPart = getEditPart(constraint, allTopSemanticEditPart);
      EditPart contextEditPart = getEditPart(context, allTopSemanticEditPart);

      if (constraintEditPart != null && contextEditPart != null) {
        Collection<EditPart> constraintAndContext = new ArrayList<EditPart>();
        constraintAndContext.add(constraintEditPart);
        constraintAndContext.add(contextEditPart);
        final Request request =
            new ShowHideRelatedLinkRequest(
                constraintAndContext, ShowHideKind.SHOW_ALL_LINK_BETWEEN_SELECTED_ELEMENT);
        final Command cmd = diagramEP.getCommand(request);
        if (cmd != null) {
          cmd.execute();
        }
      }
    }
    return null;
  }
 /** @generated */
 public boolean canCreateConstraintConstrainedElement_4011(Constraint source, Element target) {
   if (source != null) {
     if (source.getConstrainedElements().contains(target)) {
       return false;
     }
   }
   return canExistConstraintConstrainedElement_4011(source, target);
 }
 /** @generated */
 public boolean canCreateConstraintContext_8500(Constraint source, Namespace target) {
   if (source != null) {
     if (source.getContext() != null) {
       return false;
     }
   }
   if (target != null && (target.getOwnedRules().contains(target))) {
     return false;
   }
   return canExistConstraintContext_8500(source, target);
 }
Exemple #8
0
  public static TransitionDetails transitionDetails(Transition trans) {
    String condition = "";
    TransitionDetails transition = new TransitionDetails();

    /// ****** guard condition ***********************
    EList<Constraint> ownedRules = trans.getOwnedRules();
    com.mbe.umlce.dataobjects.stateMachine.Guard guard =
        new com.mbe.umlce.dataobjects.stateMachine.Guard();
    for (Constraint Rule : ownedRules) {

      ValueSpecification Specifications = Rule.getSpecification();
      guard.setName(Rule.getLabel());
      OpaqueExpression expr = (OpaqueExpression) Specifications;

      condition += expr.getBodies().toString();
      guard.setBody(removeSquareBrackets(condition));
      // condition = expr.getLanguages();
      //	System.out.println("Condition : "+condition);
    }
    transition.setGuard(guard);

    Effect effect = new Effect();
    String methodBody = null;
    if ((OpaqueBehavior) trans.getEffect() != null) {
      methodBody = "";
      effect.setName(trans.getEffect().getLabel());
      // methodBody += ("\nif ( "+removeSquareBrackets(condition)+" ){\n");
      methodBody +=
          removeSquareBrackets(((OpaqueBehavior) trans.getEffect()).getBodies().toString());
      // System.out.println("Effect : "+methodBody);
      effect.setBody(methodBody);
    }

    // Trigger yet to read//

    //
    transition.setEffect(effect);
    /*		TimeEvent timeEvent=null;
    		ChangeEvent changeEvent = null;
    */
    // Triggers reading
    CallEvent callEvent = null;
    Operation operation = null;
    EList<Trigger> trigger = trans.getTriggers();
    com.mbe.umlce.dataobjects.stateMachine.Trigger trig =
        new com.mbe.umlce.dataobjects.stateMachine.Trigger();
    for (Trigger triger : trigger) {
      // System.out.println("Triger : "+triger.getQualifiedName());
      // if(triger.getEvent().getName().contains("CallEvent")){
      callEvent = (CallEvent) (triger.getEvent());
      operation = callEvent.getOperation();

      if (operation != null) {

        // System.out.println("Operation : "+operation.getLabel());
        EList<Parameter> parameters = operation.getOwnedParameters();
        ArrayList<String> param = new ArrayList<>();
        ArrayList<String> paramClass = new ArrayList<>();

        for (Parameter pm : parameters) {
          param.add(pm.getLabel());
          paramClass.add(pm.getClass().getName());
          // System.out.println("Parameters : "+pm.getLabel());
        }
        trig.setOpName(operation.getLabel());
        trig.setOpParameters(param);
        trig.setParametersClass(paramClass);
      }
    }
    transition.setTrigger(trig);
    // }
    return transition;
  }
Exemple #9
0
 public OCLExpression<Classifier> getBodyExpression(Constraint constraint) {
   return ((ExpressionInOCL) constraint.getSpecification()).getBodyExpression();
 }
 public static boolean isParametrizedConstraint(Constraint constraint) {
   Behavior toExecute = ActivityUtils.resolveBehaviorReference(constraint.getSpecification());
   return toExecute.getOwnedParameters().size() > 1;
 }