/**
   * Returns a composite command with the given initial command and the RegionContainer specific
   * auto-size commands to propagate the auto-size to the regions.
   *
   * @param request the initial request
   * @param autoSizeCommand the initial command
   * @return a composite command with the initial command and the region container specific
   *     additional commands.
   */
  protected Command getRegionContainerAutoSizeCommand(Request request, Command autoSizeCommand) {
    IDiagramElementEditPart host = (IDiagramElementEditPart) getHost();
    TransactionalEditingDomain domain = host.getEditingDomain();
    CompositeTransactionalCommand ctc =
        new CompositeTransactionalCommand(
            domain,
            Messages.RegionContainerResizableEditPolicy_regionContainerAutoSizeCommandLabel);
    ctc.add(new CommandProxy(autoSizeCommand));
    Command regionContainerAutoSizeCommand = new ICommandProxy(ctc);

    // Propagate the auto-size request to the regions.
    Request req = new Request();
    req.setType(request.getType());
    req.getExtendedData().put(REGION_AUTO_SIZE_PROPAGATOR, host);

    Object object = request.getExtendedData().get(REGION_AUTO_SIZE_PROPAGATOR);
    for (EditPart regionPart : getRegionParts()) {
      if (object != regionPart) {
        ctc.add(new CommandProxy(regionPart.getCommand(req)));
      }
    }

    ctc.add(
        CommandFactory.createICommand(
            domain, new RegionContainerUpdateLayoutOperation((Node) host.getModel())));
    return regionContainerAutoSizeCommand;
  }
  @Override
  protected Command getCreateCommand(CreateViewRequest request) {
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
    CompositeTransactionalCommand cc =
        new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);

    Iterator descriptors = request.getViewDescriptors().iterator();

    while (descriptors.hasNext()) {
      CreateViewRequest.ViewDescriptor descriptor =
          (CreateViewRequest.ViewDescriptor) descriptors.next();

      CreateCommand createStateMachine =
          new CreateCommand(editingDomain, descriptor, (View) (getHost().getModel()));

      CustomStateMachineWithDefaultRegionCreateNodeCommand createRegion =
          new CustomStateMachineWithDefaultRegionCreateNodeCommand(
              (IAdaptable) createStateMachine.getCommandResult().getReturnValue(),
              ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint(),
              editingDomain,
              DiagramUIMessages.CreateCommand_Label,
              createStateMachine.getAffectedFiles());

      cc.compose(createStateMachine);
      cc.compose(createRegion);
    }
    return new ICommandProxy(cc.reduce());
  }
  /**
   * Complete the given composite command with RegionContainer specific resize commands: the
   * commands to report the RegionContainer resize on its regions.
   */
  @Override
  protected void completeResizeCommand(
      CompositeTransactionalCommand ctc, ChangeBoundsRequest request) {
    if (request.getEditParts().size() > 1 && !request.isConstrainedResize()) {
      ctc.add(UnexecutableCommand.INSTANCE);
      return;
    }

    Collection<ChangeBoundsRequest> siblingRequests = getConstrainedRegionRequests(request);
    if (!siblingRequests.isEmpty()) {
      for (ChangeBoundsRequest siblingRequest : siblingRequests) {
        if (siblingRequest.getEditParts() != null) {
          for (IGraphicalEditPart constrainedPart :
              Iterables.filter(siblingRequest.getEditParts(), IGraphicalEditPart.class)) {
            Command constrainedCommand = constrainedPart.getCommand(siblingRequest);
            if (constrainedCommand == null) {
              ctc.add(UnexecutableCommand.INSTANCE);
            } else {
              ctc.add(new CommandProxy(constrainedCommand));
            }
          }
        }
      }
    } else if (!(request.isConstrainedMove() || request.isConstrainedResize())) {
      // Deactivate the manual resize of RegionContainer when there are no
      // regions.
      ctc.add(UnexecutableCommand.INSTANCE);
    }

    // Adjust border nodes and edges.
    ctc.add(new ChildrenAdjustmentCommand((IGraphicalEditPart) getHost(), request, true, false));
  }
 /** @generated */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   View view = (View) getHost().getModel();
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(false);
   for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext(); ) {
     Edge incomingLink = (Edge) it.next();
     if (CrystalVisualIDRegistry.getVisualID(incomingLink) == TransitionEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
   }
   for (Iterator<?> it = view.getSourceEdges().iterator(); it.hasNext(); ) {
     Edge outgoingLink = (Edge) it.next();
     if (CrystalVisualIDRegistry.getVisualID(outgoingLink) == TransitionEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
   }
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: false
     addDestroyShortcutsCommand(cmd, view);
     // delete host element
     cmd.add(new DestroyElementCommand(req));
   } else {
     cmd.add(new DeleteCommand(getEditingDomain(), view));
   }
   return getGEFWrapper(cmd.reduce());
 }
 /** @generated */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(true);
   List<EObject> todestroy = new ArrayList<EObject>();
   todestroy.add(req.getElementToDestroy());
   // cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
   cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy)));
   return getGEFWrapper(cmd.reduce());
   // return getGEFWrapper(new
   // org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
 }
  /**
   * (Modified template: NodeItemSemanticEditPolicy.xpt)
   *
   * @generated
   */
  protected Command getDestroyElementCommand(DestroyElementRequest req) {

    View view = (View) getHost().getModel();
    CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
    cmd.setTransactionNestingEnabled(false);
    // there are indirectly referenced children, need extra commands: false
    // Se eliminan los nodos o conexiones que referencian al mismo elemento del modelo que se está
    // eliminando
    addDestroyViewsCommand(cmd, view);
    // delete host element
    cmd.add(new DestroyElementCommand(req));

    return getGEFWrapper(cmd.reduce());
  }
 /** @generated */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   View view = (View) getHost().getModel();
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(false);
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: false
     addDestroyShortcutsCommand(cmd, view);
     // delete host element
     cmd.add(new DestroyElementCommand(req));
   } else {
     cmd.add(new DeleteCommand(getEditingDomain(), view));
   }
   return getGEFWrapper(cmd.reduce());
 }
 /** @generated */
 protected ICommand getParseCommand(IAdaptable adapter, Object[] values, int flags) {
   if (values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {
     return UnexecutableCommand.INSTANCE;
   }
   EObject element = (EObject) adapter.getAdapter(EObject.class);
   TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
   if (editingDomain == null) {
     return UnexecutableCommand.INSTANCE;
   }
   CompositeTransactionalCommand command =
       new CompositeTransactionalCommand(editingDomain, "Set Values"); // $NON-NLS-1$
   for (int i = 0; i < values.length; i++) {
     command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
   }
   return command;
 }
 public Command getSetBusinessElementStructuralFeatureCommand(
     View view, String featureName, Object value) {
   EObject instance = view.getElement();
   Assert.assertNotNull(
       "No business element bound to notation element", instance); // $NON-NLS-1$
   EStructuralFeature feature = instance.eClass().getEStructuralFeature(featureName);
   if (feature == null) {
     throw new IllegalArgumentException("Not existing feature: " + featureName); // $NON-NLS-1$
   }
   SetRequest setReq = new SetRequest(instance, feature, value);
   EditPart editPart = findEditPart(view);
   TransactionalEditingDomain txEditDomain = getEditDomain(editPart);
   CompositeTransactionalCommand modelCmd =
       new CompositeTransactionalCommand(txEditDomain, "Set feature"); // $NON-NLS-1$
   modelCmd.compose(new SetValueCommand(setReq));
   return new ICommandProxy(modelCmd);
 }
 /** @generated */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   View view = (View) getHost().getModel();
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(true);
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: false
     addDestroyShortcutsCommand(cmd, view);
     // delete host element
     List<EObject> todestroy = new ArrayList<EObject>();
     todestroy.add(req.getElementToDestroy());
     // cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
     cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy)));
   } else {
     cmd.add(
         new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(
             getEditingDomain(), view));
   }
   return getGEFWrapper(cmd.reduce());
 }
Beispiel #11
0
 /** @generated */
 protected Command getCommand(Request request) {
   List operationSet = getOperationSet();
   if (operationSet.isEmpty()) {
     return UnexecutableCommand.INSTANCE;
   }
   Iterator editParts = operationSet.iterator();
   CompositeTransactionalCommand command =
       new CompositeTransactionalCommand(getEditingDomain(), getCommandLabel());
   while (editParts.hasNext()) {
     EditPart editPart = (EditPart) editParts.next();
     Command curCommand = editPart.getCommand(request);
     if (curCommand != null) {
       command.compose(new CommandProxy(curCommand));
     }
   }
   if (command.isEmpty() || command.size() != operationSet.size()) {
     return UnexecutableCommand.INSTANCE;
   }
   return new ICommandProxy(command);
 }
  public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
    if (editingDomain == null) {
      return UnexecutableCommand.INSTANCE;
    }
    int equalityPosition = newString.indexOf(NAME_TYPE_SEPARATOR);
    if (equalityPosition == -1) {
      return getSetNameCommand(element, newString);
    }
    String name = newString.substring(0, equalityPosition);
    String type = newString.substring(equalityPosition + 1);

    CompositeTransactionalCommand command =
        new CompositeTransactionalCommand(editingDomain, "Set Values"); // $NON-NLS-1$
    command.compose(getSetNameCommand(element, name));
    if (type != null) {
      ICommand setTypeCommand = getSetTypeCommand(element, type);
      if (setTypeCommand != null) {
        command.compose(setTypeCommand);
      }
    }
    return command;
  }
 /** @generated NOT adding the deletion of local conditions */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   View view = (View) getHost().getModel();
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(false);
   for (Iterator it = view.getTargetEdges().iterator(); it.hasNext(); ) {
     Edge incomingLink = (Edge) it.next();
     if (UMLVisualIDRegistry.getVisualID(incomingLink) == ObjectFlowEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (UMLVisualIDRegistry.getVisualID(incomingLink) == ControlFlowEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
   }
   for (Iterator it = view.getSourceEdges().iterator(); it.hasNext(); ) {
     Edge outgoingLink = (Edge) it.next();
     if (UMLVisualIDRegistry.getVisualID(outgoingLink)
         == ActionLocalPreconditionEditPart.VISUAL_ID) {
       /*
        * Simply delete the link and the local condition view.
        * Model arrangement are automatic since local condition is contained by the action.
        */
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink.getTarget()));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
     if (UMLVisualIDRegistry.getVisualID(outgoingLink)
         == ActionLocalPostconditionEditPart.VISUAL_ID) {
       /*
        * Simply delete the link and the local condition view.
        * Model arrangement are automatic since local condition is contained by the action.
        */
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink.getTarget()));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
     if (UMLVisualIDRegistry.getVisualID(outgoingLink) == ObjectFlowEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
     if (UMLVisualIDRegistry.getVisualID(outgoingLink) == ControlFlowEditPart.VISUAL_ID) {
       DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
       cmd.add(new DestroyElementCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
   }
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: false
     addDestroyChildNodesCommand(cmd);
     addDestroyShortcutsCommand(cmd, view);
     // delete host element
     cmd.add(new DestroyElementCommand(req));
   } else {
     cmd.add(new DeleteCommand(getEditingDomain(), view));
   }
   return getGEFWrapper(cmd.reduce());
 }
 /** @generated */
 protected Command getDestroyElementCommand(DestroyElementRequest req) {
   View view = (View) getHost().getModel();
   CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
   cmd.setTransactionNestingEnabled(false);
   for (Iterator it = view.getTargetEdges().iterator(); it.hasNext(); ) {
     Edge incomingLink = (Edge) it.next();
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == CompositeProcessComposedOfEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == IfThenElseThenEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == IfThenElseElseEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == RepeatUntilUntilProcessEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == RepeatWhileWhileProcessEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == ControlConstructBagFirstEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(incomingLink)
         == ControlConstructListFirstEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               incomingLink.getSource().getElement(),
               null,
               incomingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
       continue;
     }
   }
   for (Iterator it = view.getSourceEdges().iterator(); it.hasNext(); ) {
     Edge outgoingLink = (Edge) it.next();
     if (CoordinationVisualIDRegistry.getVisualID(outgoingLink)
         == PerformProcessEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               outgoingLink.getSource().getElement(),
               null,
               outgoingLink.getTarget().getElement(),
               false);
       cmd.add(new DestroyReferenceCommand(r));
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
     if (CoordinationVisualIDRegistry.getVisualID(outgoingLink)
         == PerformHasDataFromEditPart.VISUAL_ID) {
       DestroyReferenceRequest r =
           new DestroyReferenceRequest(
               outgoingLink.getSource().getElement(),
               null,
               outgoingLink.getTarget().getElement(),
               false);
       cmd.add(
           new DestroyReferenceCommand(r) {
             protected CommandResult doExecuteWithResult(
                 IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
               EObject referencedObject = getReferencedObject();
               Resource resource = referencedObject.eResource();
               CommandResult result = super.doExecuteWithResult(progressMonitor, info);
               if (resource != null) {
                 resource.getContents().add(referencedObject);
               }
               return result;
             }
           });
       cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
       continue;
     }
   }
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: false
     addDestroyShortcutsCommand(cmd, view);
     // delete host element
     cmd.add(new DestroyElementCommand(req));
   } else {
     cmd.add(new DeleteCommand(getEditingDomain(), view));
   }
   return getGEFWrapper(cmd.reduce());
 }
  private Command getLayoutConstraintsCommand(boolean collapsed, Command initialCommand) {
    if (getHost() instanceof IResizableCompartmentEditPart
        && getHost().getParent() instanceof AbstractDiagramElementContainerEditPart) {
      AbstractDiagramElementContainerEditPart regionPart =
          (AbstractDiagramElementContainerEditPart) getHost().getParent();
      View notationView = regionPart.getNotationView();
      if (notationView instanceof Node
          && ((Node) notationView).getLayoutConstraint() instanceof Size
          && notationView.getElement() instanceof DDiagramElementContainer) {
        TransactionalEditingDomain editingDomain = getEditingDomain();
        CompositeTransactionalCommand ctc =
            new CompositeTransactionalCommand(
                editingDomain,
                collapsed
                    ? Messages
                        .RegionCollapseAwarePropertyHandlerEditPolicy_collapseRegionCommandLabel
                    : Messages
                        .RegionCollapseAwarePropertyHandlerEditPolicy_expandRegionCommandLabel);
        Command result = new ICommandProxy(ctc);
        if (initialCommand != null) {
          ctc.add(new CommandProxy(initialCommand));
        }

        Size size = (Size) ((Node) notationView).getLayoutConstraint();
        DDiagramElementContainer ddec = (DDiagramElementContainer) notationView.getElement();
        Iterable<AbsoluteBoundsFilter> boundsFilters =
            Iterables.filter(ddec.getGraphicalFilters(), AbsoluteBoundsFilter.class);
        AbsoluteBoundsFilter expandedBoundsMarker =
            Iterables.isEmpty(boundsFilters) ? null : boundsFilters.iterator().next();

        // Update GMF size
        Dimension newGmfSize = new Dimension(size.getWidth(), size.getHeight());
        int parentStackDirection = regionPart.getParentStackDirection();
        if (parentStackDirection == PositionConstants.NORTH_SOUTH) {
          if (!collapsed) {
            newGmfSize.setHeight(
                expandedBoundsMarker == null ? -1 : expandedBoundsMarker.getHeight());
          } else if (size.getHeight() != -1) {
            newGmfSize.setHeight(LayoutUtils.COLLAPSED_VERTICAL_REGION_HEIGHT);
          }
        } else if (parentStackDirection == PositionConstants.EAST_WEST) {
          if (!collapsed) {
            newGmfSize.setWidth(
                expandedBoundsMarker == null ? -1 : expandedBoundsMarker.getWidth());
          } else if (!isTruncatedLabel(regionPart)) {
            // Change the GMF width only when label is not truncated
            // to avoid to have a collapsed Region bigger than the
            // expanded size (resized by the user).
            // Do not specify a collapsed width as it will depend on
            // the label size.
            newGmfSize.setWidth(-1);
          }
        }

        SetBoundsCommand setBoundsCommand =
            new SetBoundsCommand(
                editingDomain,
                Messages.RegionCollapseAwarePropertyHandlerEditPolicy_gmfSizeUpdateCommandLabel,
                new EObjectAdapter(notationView),
                newGmfSize);
        ctc.add(setBoundsCommand);

        // Remember expanded size: create/update/remove an
        // AbsoluteBoundsFilter marker on the DDiagramElement.
        if (collapsed) {
          if (expandedBoundsMarker != null) {
            ctc.add(
                new GMFCommandWrapper(
                    editingDomain,
                    new SetCommand(
                        editingDomain,
                        expandedBoundsMarker,
                        DiagramPackage.eINSTANCE.getAbsoluteBoundsFilter_Height(),
                        size.getHeight())));
            ctc.add(
                new GMFCommandWrapper(
                    editingDomain,
                    new SetCommand(
                        editingDomain,
                        expandedBoundsMarker,
                        DiagramPackage.eINSTANCE.getAbsoluteBoundsFilter_Width(),
                        size.getWidth())));
          } else {
            expandedBoundsMarker = DiagramFactory.eINSTANCE.createAbsoluteBoundsFilter();
            expandedBoundsMarker.setHeight(size.getHeight());
            expandedBoundsMarker.setWidth(size.getWidth());
            ctc.add(
                new GMFCommandWrapper(
                    editingDomain,
                    new AddCommand(
                        editingDomain, ddec.getGraphicalFilters(), expandedBoundsMarker)));
          }
        } else if (expandedBoundsMarker != null) {
          ctc.add(
              new GMFCommandWrapper(
                  editingDomain,
                  new RemoveCommand(
                      editingDomain, ddec.getGraphicalFilters(), expandedBoundsMarker)));
        }

        return result;
      }
    }
    return initialCommand;
  }
 /** @generated */
 protected void refreshSemantic() {
   if (resolveSemanticElement() == null) {
     return;
   }
   LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
   List<UMLNodeDescriptor> childDescriptors =
       UMLDiagramUpdater.getStateMachine_2000SemanticChildren((View) getHost().getModel());
   LinkedList<View> orphaned = new LinkedList<View>();
   // we care to check only views we recognize as ours
   LinkedList<View> knownViewChildren = new LinkedList<View>();
   for (View v : getViewChildren()) {
     if (isMyDiagramElement(v)) {
       knownViewChildren.add(v);
     }
   }
   // alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren)
   HashMap<UMLNodeDescriptor, LinkedList<View>> potentialViews =
       new HashMap<UMLNodeDescriptor, LinkedList<View>>();
   //
   // iteration happens over list of desired semantic elements, trying to find best matching View,
   // while original CEP
   // iterates views, potentially losing view (size/bounds) information - i.e. if there are few
   // views to reference same EObject, only last one
   // to answer isOrphaned == true will be used for the domain element representation, see
   // #cleanCanonicalSemanticChildren()
   for (Iterator<UMLNodeDescriptor> descriptorsIterator = childDescriptors.iterator();
       descriptorsIterator.hasNext(); ) {
     UMLNodeDescriptor next = descriptorsIterator.next();
     String hint = UMLVisualIDRegistry.getType(next.getVisualID());
     LinkedList<View> perfectMatch =
         new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor
     LinkedList<View> potentialMatch =
         new LinkedList<View>(); // semanticElement matches, hint does not
     for (View childView : getViewChildren()) {
       EObject semanticElement = childView.getElement();
       if (next.getModelElement().equals(semanticElement)) {
         if (hint.equals(childView.getType())) {
           perfectMatch.add(childView);
           // actually, can stop iteration over view children here, but
           // may want to use not the first view but last one as a 'real' match (the way original
           // CEP does
           // with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren
         } else {
           potentialMatch.add(childView);
         }
       }
     }
     if (perfectMatch.size() > 0) {
       descriptorsIterator
           .remove(); // precise match found no need to create anything for the NodeDescriptor
       // use only one view (first or last?), keep rest as orphaned for further consideration
       knownViewChildren.remove(perfectMatch.getFirst());
     } else if (potentialMatch.size() > 0) {
       potentialViews.put(next, potentialMatch);
     }
   }
   // those left in knownViewChildren are subject to removal - they are our diagram elements we
   // didn't find match to,
   // or those we have potential matches to, and thus need to be recreated, preserving
   // size/location information.
   orphaned.addAll(knownViewChildren);
   //
   CompositeTransactionalCommand boundsCommand =
       new CompositeTransactionalCommand(
           host().getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize);
   ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors =
       new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size());
   for (UMLNodeDescriptor next : childDescriptors) {
     String hint = UMLVisualIDRegistry.getType(next.getVisualID());
     IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint);
     CreateViewRequest.ViewDescriptor descriptor =
         new CreateViewRequest.ViewDescriptor(
             elementAdapter,
             Node.class,
             hint,
             ViewUtil.APPEND,
             false,
             host().getDiagramPreferencesHint());
     viewDescriptors.add(descriptor);
     LinkedList<View> possibleMatches = potentialViews.get(next);
     if (possibleMatches != null) {
       // from potential matches, leave those that were not eventually used for some other
       // NodeDescriptor (i.e. those left as orphaned)
       possibleMatches.retainAll(knownViewChildren);
     }
     if (possibleMatches != null && !possibleMatches.isEmpty()) {
       View originalView = possibleMatches.getFirst();
       knownViewChildren.remove(
           originalView); // remove not to copy properties of the same view again and again
       // add command to copy properties
       if (originalView instanceof Node) {
         if (((Node) originalView).getLayoutConstraint() instanceof Bounds) {
           Bounds b = (Bounds) ((Node) originalView).getLayoutConstraint();
           boundsCommand.add(
               new SetBoundsCommand(
                   boundsCommand.getEditingDomain(),
                   boundsCommand.getLabel(),
                   descriptor,
                   new Rectangle(b.getX(), b.getY(), b.getWidth(), b.getHeight())));
         } else if (((Node) originalView).getLayoutConstraint() instanceof Location) {
           Location l = (Location) ((Node) originalView).getLayoutConstraint();
           boundsCommand.add(
               new SetBoundsCommand(
                   boundsCommand.getEditingDomain(),
                   boundsCommand.getLabel(),
                   descriptor,
                   new Point(l.getX(), l.getY())));
         } else if (((Node) originalView).getLayoutConstraint() instanceof Size) {
           Size s = (Size) ((Node) originalView).getLayoutConstraint();
           boundsCommand.add(
               new SetBoundsCommand(
                   boundsCommand.getEditingDomain(),
                   boundsCommand.getLabel(),
                   descriptor,
                   new Dimension(s.getWidth(), s.getHeight())));
         }
       }
     }
   }
   boolean changed = deleteViews(orphaned.iterator());
   //
   CreateViewRequest request = getCreateViewRequest(viewDescriptors);
   Command cmd = getCreateViewCommand(request);
   if (cmd != null && cmd.canExecute()) {
     SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute();
     executeCommand(cmd);
     if (boundsCommand.canExecute()) {
       executeCommand(new ICommandProxy(boundsCommand.reduce()));
     }
     @SuppressWarnings("unchecked")
     List<IAdaptable> nl = (List<IAdaptable>) request.getNewObject();
     createdViews.addAll(nl);
   }
   if (changed || createdViews.size() > 0) {
     postProcessRefreshSemantic(createdViews);
   }
   if (createdViews.size() > 1) {
     // perform a layout of the container
     DeferredLayoutCommand layoutCmd =
         new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
     executeCommand(new ICommandProxy(layoutCmd));
   }
   makeViewsImmutable(createdViews);
 }
  @Override
  protected Command getCreateCommand(CreateRequest request) {
    if (request instanceof CreateViewAndElementRequest) {

      CreateViewAndElementRequest req = (CreateViewAndElementRequest) request;

      if (req.getViewAndElementDescriptor()
              .getSemanticHint()
              .equals(((IHintedType) UMLElementTypes.Pseudostate_16000).getSemanticHint())
          || req.getViewAndElementDescriptor()
              .getSemanticHint()
              .equals(((IHintedType) UMLElementTypes.Pseudostate_17000).getSemanticHint())
          || req.getViewAndElementDescriptor()
              .getSemanticHint()
              .equals(
                  ((IHintedType) UMLElementTypes.ConnectionPointReference_18000)
                      .getSemanticHint())) {

        TransactionalEditingDomain editingDomain =
            ((IGraphicalEditPart) getHost()).getEditingDomain();

        CompositeTransactionalCommand cc =
            new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
        Iterator<?> iter = req.getViewDescriptors().iterator();

        // Retrieve parent location
        Point parentLoc = getHostFigure().getBounds().getLocation().getCopy();

        // Compute relative creation location
        Point requestedLocation = request.getLocation().getCopy();
        getHostFigure().translateToRelative(requestedLocation);

        // Create proposed creation bounds and use the locator to find the expected position
        CustomEntryExitPointPositionLocator locator =
            new CustomEntryExitPointPositionLocator(getHostFigure(), PositionConstants.NONE);
        Rectangle proposedBounds = new Rectangle(requestedLocation, new Dimension(20, 20));
        Rectangle preferredBounds = locator.getPreferredLocation(proposedBounds);

        // Convert the calculated preferred bounds as relative to parent location
        Rectangle creationBounds = preferredBounds.getTranslated(parentLoc.getNegated());

        while (iter.hasNext()) {

          CreateViewRequest.ViewDescriptor viewDescriptor =
              (CreateViewRequest.ViewDescriptor) iter.next();
          cc.compose(
              new SetBoundsCommand(
                  editingDomain,
                  DiagramUIMessages.SetLocationCommand_Label_Resize,
                  viewDescriptor,
                  creationBounds));
        }

        if (cc.reduce() == null) {
          return null;
        }

        return new ICommandProxy(cc.reduce());
      }
    }
    return null;
  }
  /** @generated */
  protected Command getDestroyElementCommand(DestroyElementRequest req) {
    View view = (View) getHost().getModel();
    CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
    cmd.setTransactionNestingEnabled(false);
    for (Iterator<?> it = view.getTargetEdges().iterator(); it.hasNext(); ) {
      Edge incomingLink = (Edge) it.next();
      if (UMLVisualIDRegistry.getVisualID(incomingLink) == ControlFlowEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(incomingLink) == ObjectFlowEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(incomingLink) == ExceptionHandlerEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(incomingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(incomingLink)
          == CommentAnnotatedElementEditPart.VISUAL_ID) {
        DestroyReferenceRequest r =
            new DestroyReferenceRequest(
                incomingLink.getSource().getElement(),
                null,
                incomingLink.getTarget().getElement(),
                false);
        cmd.add(new DestroyReferenceCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), incomingLink));
        continue;
      }
    }
    for (Iterator<?> it = view.getSourceEdges().iterator(); it.hasNext(); ) {
      Edge outgoingLink = (Edge) it.next();
      if (UMLVisualIDRegistry.getVisualID(outgoingLink) == ControlFlowEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(outgoingLink) == ObjectFlowEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(outgoingLink)
          == ActionLocalPreconditionEditPart.VISUAL_ID) {
        DestroyReferenceRequest r =
            new DestroyReferenceRequest(
                outgoingLink.getSource().getElement(),
                null,
                outgoingLink.getTarget().getElement(),
                false);
        cmd.add(
            new DestroyReferenceCommand(r) {

              protected CommandResult doExecuteWithResult(
                  IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
                EObject referencedObject = getReferencedObject();
                Resource resource = referencedObject.eResource();
                CommandResult result = super.doExecuteWithResult(progressMonitor, info);
                if (resource != null) {
                  resource.getContents().add(referencedObject);
                }
                return result;
              }
            });
        cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(outgoingLink)
          == ActionLocalPostconditionEditPart.VISUAL_ID) {
        DestroyReferenceRequest r =
            new DestroyReferenceRequest(
                outgoingLink.getSource().getElement(),
                null,
                outgoingLink.getTarget().getElement(),
                false);
        cmd.add(
            new DestroyReferenceCommand(r) {

              protected CommandResult doExecuteWithResult(
                  IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
                EObject referencedObject = getReferencedObject();
                Resource resource = referencedObject.eResource();
                CommandResult result = super.doExecuteWithResult(progressMonitor, info);
                if (resource != null) {
                  resource.getContents().add(referencedObject);
                }
                return result;
              }
            });
        cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
        continue;
      }
      if (UMLVisualIDRegistry.getVisualID(outgoingLink) == ExceptionHandlerEditPart.VISUAL_ID) {
        DestroyElementRequest r = new DestroyElementRequest(outgoingLink.getElement(), false);
        cmd.add(new DestroyElementCommand(r));
        cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink));
        continue;
      }
    }
    EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
    if (annotation == null) {
      // there are indirectly referenced children, need extra commands: false
      addDestroyChildNodesCommand(cmd);
      addDestroyShortcutsCommand(cmd, view);
      // delete host element
      cmd.add(new DestroyElementCommand(req));
    } else {
      cmd.add(new DeleteCommand(getEditingDomain(), view));
    }
    return getGEFWrapper(cmd.reduce());
  }