コード例 #1
0
  @Override
  protected ICommand getBeforeSetCommand(SetRequest request) {

    ICommand setCommand = super.getBeforeSetCommand(request);

    Set<View> viewsToDestroy = new HashSet<View>();

    // Get modified object and retrieve inconsistent view
    EObject modifiedObject = request.getElementToEdit();
    if ((modifiedObject != null)
        && (modifiedObject instanceof Property)
        && (request.getFeature() == UMLPackage.eINSTANCE.getProperty_Aggregation())
        && (request.getValue() != AggregationKind.COMPOSITE_LITERAL)) {

      viewsToDestroy.addAll(getViewsToDestroy(modifiedObject));
    }

    if ((modifiedObject != null)
        && (modifiedObject instanceof Property)
        && (request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type())
        && (request.getValue() instanceof Type)
        && !((ISpecializationType) SysMLElementTypes.BLOCK)
            .getMatcher()
            .matches((Type) request.getValue())) {

      viewsToDestroy.addAll(getViewsToDestroy(modifiedObject));
    }

    if (!viewsToDestroy.isEmpty()) {
      DestroyDependentsRequest ddr =
          new DestroyDependentsRequest(
              request.getEditingDomain(), request.getElementToEdit(), false);
      ddr.setClientContext(request.getClientContext());
      ddr.addParameters(request.getParameters());
      ICommand destroyViewsCommand = ddr.getDestroyDependentsCommand(viewsToDestroy);
      setCommand = CompositeCommand.compose(setCommand, destroyViewsCommand);
    }

    return setCommand;
  }
コード例 #2
0
  /**
   * Returns the command to destroy the views of the parts which are not owned by the new type
   *
   * @see
   *     org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeSetCommand(org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest)
   * @param request the request to modify the model
   * @return the command to destroy the views of the parts which are not owned by the new type
   */
  @Override
  protected ICommand getBeforeSetCommand(SetRequest request) {
    Type oldType = null;
    Type newType = null;

    EObject elementToEdit = request.getElementToEdit();
    Set<View> viewsToDelete = new HashSet<View>();
    if ((elementToEdit instanceof Property)
        && (request.getFeature() == UMLPackage.eINSTANCE.getTypedElement_Type())
        && ((request.getValue() == null) || (request.getValue() instanceof Type))) {

      Property propertyToEdit = (Property) elementToEdit;
      Set<View> propertyToEditViews =
          CrossReferencerUtil.getCrossReferencingViews(
              propertyToEdit, CompositeStructureDiagramEditPart.MODEL_ID);

      oldType = propertyToEdit.getType();
      newType = (Type) request.getValue();

      if ((oldType != null)
          && (oldType instanceof Classifier)
          && ((request.getValue() == null) || (newType instanceof Classifier))) {

        EList<NamedElement> newTypeMembers =
            (newType != null)
                ? ((Classifier) newType).getMembers()
                : new BasicEList<NamedElement>();
        EList<NamedElement> oldTypeMembers = ((Classifier) oldType).getMembers();

        // Remove members of the new type from the list.
        // oldTypeMembers now contains the list of members for which views will become
        // inconsistent (if shown in the propertyToEdit) after setting the new type.
        List<NamedElement> possiblyInconsistentMembers = new ArrayList<NamedElement>();
        possiblyInconsistentMembers.addAll(oldTypeMembers);
        possiblyInconsistentMembers.removeAll(newTypeMembers);

        // Parse the list of possibly inconsistent members
        for (NamedElement possiblyInconsistentMember : possiblyInconsistentMembers) {

          // Retrieve views of the current possiblyInconsistentMember
          Iterator<View> viewIt =
              CrossReferencerUtil.getCrossReferencingViews(
                      possiblyInconsistentMember, CompositeStructureDiagramEditPart.MODEL_ID)
                  .iterator();
          while (viewIt.hasNext()) {
            View possiblyInconsistentMemberView = viewIt.next();
            if (isConcerned(possiblyInconsistentMemberView, propertyToEditViews)) {
              viewsToDelete.add(possiblyInconsistentMemberView);
            }
          }
        }
      }
    }

    if ((viewsToDelete != null) && !(viewsToDelete.isEmpty())) {
      DestroyDependentsRequest req =
          new DestroyDependentsRequest(request.getEditingDomain(), elementToEdit, false);
      return req.getDestroyDependentsCommand(viewsToDelete);
    }

    return null;
  }