/** @generated */
 private void addDestroyChildNodesCommand(ICompositeCommand cmd) {
   View view = (View) getHost().getModel();
   for (Iterator<?> nit = view.getChildren().iterator(); nit.hasNext(); ) {
     Node node = (Node) nit.next();
     switch (UMLVisualIDRegistry.getVisualID(node)) {
       case ParameterEditPart.VISUAL_ID:
         for (Iterator<?> it = node.getTargetEdges().iterator(); it.hasNext(); ) {
           Edge incomingLink = (Edge) it.next();
           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;
           }
         }
         cmd.add(
             new DestroyElementCommand(
                 new DestroyElementRequest(
                     getEditingDomain(), node.getElement(), false))); // directlyOwned: false
         // don't need explicit deletion of node as parent's view deletion would clean child views
         // as well
         // cmd.add(new
         // org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), node));
         break;
     }
   }
 }
 /** @generated */
 static {
   registerSnapBackPosition(
       UMLVisualIDRegistry.getType(
           org.eclipse.uml2.diagram.activity.edit.parts
               .AddStructuralFeatureValueAction_object_InputPinOrderingEditPart.VISUAL_ID),
       new Point(0, 0));
 }
 /** @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)
         == 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;
     }
   }
   EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$
   if (annotation == null) {
     // there are indirectly referenced children, need extra commands: true
     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 */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.ForkNode_3039,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.uml2.diagram.activity.edit.parts.ForkNodeNameEditPart.VISUAL_ID));
   }
   return parser;
 }
 /** @generated */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.CentralBufferNode_3066,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.uml2.diagram.activity.edit.parts
                     .ActivityPartition_CentralBufferNodeStereotypeEditPart.VISUAL_ID));
   }
   return parser;
 }
 /** @generated */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.InputPin_3005,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.uml2.diagram.activity.edit.parts
                     .AddStructuralFeatureValueAction_object_InputPinOrderingEditPart.VISUAL_ID));
   }
   return parser;
 }
 /** @generated */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.OpaqueAction_3029,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.uml2.diagram.activity.edit.parts.OpaqueActionStereotypeEditPart
                     .VISUAL_ID));
   }
   return parser;
 }
 /** @generated */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.DataStoreNode_3024,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.uml2.diagram.activity.edit.parts
                     .StructuredActivityNode_DataStoreNodeInStateEditPart.VISUAL_ID));
   }
   return parser;
 }
 /** @generated */
 protected void decorateView(
     View containerView,
     View view,
     IAdaptable semanticAdapter,
     String semanticHint,
     int index,
     boolean persisted) {
   if (semanticHint == null) {
     semanticHint =
         UMLVisualIDRegistry.getType(
             StructuredActivityNode_StructuredActivityNode_OutputPinEditPart.VISUAL_ID);
     view.setType(semanticHint);
   }
   super.decorateView(containerView, view, semanticAdapter, semanticHint, index, persisted);
   IAdaptable eObjectAdapter = null;
   EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
   if (eObject != null) {
     eObjectAdapter = new EObjectAdapter(eObject);
   }
   getViewService()
       .createNode(
           eObjectAdapter,
           view,
           UMLVisualIDRegistry.getType(
               StructuredActivityNode_StructuredActivityNode_OutputPinNameEditPart.VISUAL_ID),
           ViewUtil.APPEND,
           true,
           getPreferencesHint());
   getViewService()
       .createNode(
           eObjectAdapter,
           view,
           UMLVisualIDRegistry.getType(
               StructuredActivityNode_StructuredActivityNode_OutputPinOrderingEditPart.VISUAL_ID),
           ViewUtil.APPEND,
           true,
           getPreferencesHint());
 }
 /** @generated */
 public final void selectionChanged(IStructuredSelection selection) {
   myDiagram = null;
   if (selection.size() == 1) {
     Object selectedElement = selection.getFirstElement();
     if (selectedElement instanceof UMLNavigatorItem) {
       selectedElement = ((UMLNavigatorItem) selectedElement).getView();
     } else if (selectedElement instanceof IAdaptable) {
       selectedElement = ((IAdaptable) selectedElement).getAdapter(View.class);
     }
     if (selectedElement instanceof Diagram) {
       Diagram diagram = (Diagram) selectedElement;
       if (PackageEditPart.MODEL_ID.equals(UMLVisualIDRegistry.getModelID(diagram))) {
         myDiagram = diagram;
       }
     }
   }
   setEnabled(myDiagram != null);
 }
  /** @generated */
  protected void refreshSemantic() {
    if (resolveSemanticElement() == null) {
      return;
    }
    LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
    List<UMLNodeDescriptor> childDescriptors = Collections.emptyList();
    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)
    //
    // 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
      for (View childView : getViewChildren()) {
        EObject semanticElement = childView.getElement();
        if (next.getModelElement().equals(semanticElement)) {
          // if (hint.equals(childView.getType())) {
          if (UMLVisualIDRegistry.checkNodeVisualID(
              (View) (getHost().getModel()), semanticElement, next.getVisualID())) {
            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
          }
        }
      }
      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.getLast());
      }
    }
    // 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);
    //
    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);
    }

    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);
      @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);
  }
 /** @generated */
 private boolean isDefinitelyNotMyDiagramElement(View view) {
   int visualID = UMLVisualIDRegistry.getVisualID(view);
   switch (visualID) {
     case ActivityEditPart.VISUAL_ID:
     case LocalPreconditionEditPart.VISUAL_ID:
     case LocalPostconditionEditPart.VISUAL_ID:
     case CommentEditPart.VISUAL_ID:
     case AcceptEventActionEditPart.VISUAL_ID:
     case AcceptTimeEventActionEditPart.VISUAL_ID:
     case ActivityFinalNodeEditPart.VISUAL_ID:
     case DecisionNodeEditPart.VISUAL_ID:
     case MergeNodeEditPart.VISUAL_ID:
     case InitialNodeEditPart.VISUAL_ID:
     case DataStoreNodeEditPart.VISUAL_ID:
     case CentralBufferNodeEditPart.VISUAL_ID:
     case OpaqueActionEditPart.VISUAL_ID:
     case OpaqueAction_OutputPinEditPart.VISUAL_ID:
     case OpaqueAction_InputPinEditPart.VISUAL_ID:
     case FlowFinalNodeEditPart.VISUAL_ID:
     case ForkNodeEditPart.VISUAL_ID:
     case JoinNodeEditPart.VISUAL_ID:
     case PinEditPart.VISUAL_ID:
     case CreateObjectActionEditPart.VISUAL_ID:
     case CreateObjectAction_OutputPinEditPart.VISUAL_ID:
     case AddStructuralFeatureValueActionEditPart.VISUAL_ID:
     case AddStructuralFeatureValueAction_insertAt_InputPinEditPart.VISUAL_ID:
     case AddStructuralFeatureValueAction_value_InputPinEditPart.VISUAL_ID:
     case AddStructuralFeatureValueAction_object_InputPinEditPart.VISUAL_ID:
     case CallBehaviorActionEditPart.VISUAL_ID:
     case CallAction_OutputPinEditPart.VISUAL_ID:
     case CallAction_InputPinEditPart.VISUAL_ID:
     case CallOperationActionEditPart.VISUAL_ID:
     case CallOperationAction_InputPinEditPart.VISUAL_ID:
     case StructuredActivityNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_StructuredActivityNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_OpaqueActionEditPart.VISUAL_ID:
     case StructuredActivityNode_AcceptEventActionEditPart.VISUAL_ID:
     case StructuredActivityNode_AcceptTimeEventActionEditPart.VISUAL_ID:
     case StructuredActivityNode_ActivityFinalNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_DecisionNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_FlowFinalNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_PinEditPart.VISUAL_ID:
     case StructuredActivityNode_CreateObjectActionEditPart.VISUAL_ID:
     case StructuredActivityNode_CallBehaviorActionEditPart.VISUAL_ID:
     case StructuredActivityNode_CallOperationActionEditPart.VISUAL_ID:
     case StructuredActivityNode_ForkNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_JoinNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_AddStructuralFeatureValueActionEditPart.VISUAL_ID:
     case StructuredActivityNode_DataStoreNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_CentralBufferNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_InputPinEditPart.VISUAL_ID:
     case StructuredActivityNode_OutputPinEditPart.VISUAL_ID:
     case StructuredActivityNode_ConditionalNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_InitialNodeEditPart.VISUAL_ID:
     case OpaqueBehaviorEditPart.VISUAL_ID:
     case ActivityParameterNodeEditPart.VISUAL_ID:
     case SendSignalActionEditPart.VISUAL_ID:
     case ActivityPartitionEditPart.VISUAL_ID:
     case ActivityPartition_ActivityPartitionEditPart.VISUAL_ID:
     case ActivityPartition_AcceptEventActionEditPart.VISUAL_ID:
     case ActivityPartition_AcceptTimeEventActionEditPart.VISUAL_ID:
     case ActivityPartition_ActivityFinalNodeEditPart.VISUAL_ID:
     case ActivityPartition_DecisionNodeEditPart.VISUAL_ID:
     case ActivityPartition_MergeNodeEditPart.VISUAL_ID:
     case ActivityPartition_InitialNodeEditPart.VISUAL_ID:
     case ActivityPartition_DataStoreNodeEditPart.VISUAL_ID:
     case ActivityPartition_CentralBufferNodeEditPart.VISUAL_ID:
     case ActivityPartition_OpaqueActionEditPart.VISUAL_ID:
     case ActivityPartition_FlowFinalNodeEditPart.VISUAL_ID:
     case ActivityPartition_ForkNodeEditPart.VISUAL_ID:
     case ActivityPartition_JoinNodeEditPart.VISUAL_ID:
     case ActivityPartition_PinEditPart.VISUAL_ID:
     case ActivityPartition_CreateObjectActionEditPart.VISUAL_ID:
     case ActivityPartition_AddStructuralFeatureValueActionEditPart.VISUAL_ID:
     case ActivityPartition_CallBehaviorActionEditPart.VISUAL_ID:
     case ActivityPartition_CallOperationActionEditPart.VISUAL_ID:
     case ActivityPartition_StructuredActivityNodeEditPart.VISUAL_ID:
     case ActivityPartition_StructuredActivityNode_StructuredActivityNodeEditPart.VISUAL_ID:
     case StructuredActivityNode_StructuredActivityNode_InputPinEditPart.VISUAL_ID:
     case StructuredActivityNode_StructuredActivityNode_OutputPinEditPart.VISUAL_ID:
     case ActivityPartition_SendSignalActionEditPart.VISUAL_ID:
     case ActivityPartition_LoopNodeEditPart.VISUAL_ID:
     case ActivityPartition_ConditionalNodeEditPart.VISUAL_ID:
     case ActivityPartition_ExpansionRegionEditPart.VISUAL_ID:
     case ActivityPartition_ValueSpecificationActionEditPart.VISUAL_ID:
     case ValueSpecificationAction_OutputPinEditPart.VISUAL_ID:
     case LoopNodeEditPart.VISUAL_ID:
     case ConditionalNodeEditPart.VISUAL_ID:
     case ExpansionRegionEditPart.VISUAL_ID:
     case ExpansionNodeEditPart.VISUAL_ID:
     case ParameterSetEditPart.VISUAL_ID:
     case ParameterEditPart.VISUAL_ID:
     case ValueSpecificationActionEditPart.VISUAL_ID:
     case LocalPrecondition_LiteralStringEditPart.VISUAL_ID:
     case LocalPostcondition_LiteralStringEditPart.VISUAL_ID:
       return true;
   }
   return false;
 }
 /** @generated */
 private boolean isMyDiagramElement(View view) {
   return LocalPostcondition_LiteralStringEditPart.VISUAL_ID
       == UMLVisualIDRegistry.getVisualID(view);
 }
 /** @generated */
 static {
   registerSnapBackPosition(
       UMLVisualIDRegistry.getType(
           org.eclipse.uml2.diagram.activity.edit.parts.ForkNodeNameEditPart.VISUAL_ID),
       new Point(0, 0));
 }
  /** @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());
  }