/** @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 PackageImportsEditPart.VISUAL_ID:
         for (Iterator<?> cit = node.getChildren().iterator(); cit.hasNext(); ) {
           Node cnode = (Node) cit.next();
           switch (UMLVisualIDRegistry.getVisualID(cnode)) {
             case ElementImportEditPart.VISUAL_ID:
               cmd.add(
                   new DestroyElementCommand(
                       new DestroyElementRequest(
                           getEditingDomain(), cnode.getElement(), false))); // directlyOwned: true
               // don't need explicit deletion of cnode as parent's view deletion would clean child
               // views as well
               // cmd.add(new
               // org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(),
               // cnode));
               break;
           }
         }
         break;
     }
   }
 }
 /** @generated */
 protected void createDefaultEditPolicies() {
   super.createDefaultEditPolicies();
   installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new U2TResizableCompartmentEditPolicy());
   installEditPolicy(
       EditPolicyRoles.SEMANTIC_ROLE, new InterfaceOperations2ItemSemanticEditPolicy());
   installEditPolicy(
       EditPolicyRoles.CREATION_ROLE,
       new CreationEditPolicyWithCustomReparent(UMLVisualIDRegistry.TYPED_ADAPTER));
   installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
   installEditPolicy(
       EditPolicyRoles.CANONICAL_ROLE, new InterfaceOperations2CanonicalEditPolicy());
   if (UMLVisualIDRegistry.isShortcutDescendant(getNotationView())) {
     installEditPolicy(
         UpdateDescriptionEditPolicy.ROLE,
         new UpdateDescriptionEditPolicy(UMLDiagramUpdater.TYPED_ADAPTER, false));
   }
 }
  /** @generated */
  protected void refreshSemantic() {
    if (resolveSemanticElement() == null) {
      return;
    }
    LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
    List<UMLNodeDescriptor> childDescriptors =
        UMLDiagramUpdater.getInstanceSpecificationSlots_7028SemanticChildren(
            (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)
    //
    // 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 isMyDiagramElement(View view) {
   return SlotEditPart.VISUAL_ID == UMLVisualIDRegistry.getVisualID(view);
 }
 /** @generated */
 private boolean isDefinitelyNotMyDiagramElement(View view) {
   int visualID = UMLVisualIDRegistry.getVisualID(view);
   switch (visualID) {
     case Package2EditPart.VISUAL_ID:
     case Class2EditPart.VISUAL_ID:
     case AssociationClass2EditPart.VISUAL_ID:
     case DataType2EditPart.VISUAL_ID:
     case PrimitiveType2EditPart.VISUAL_ID:
     case Enumeration2EditPart.VISUAL_ID:
     case InterfaceEditPart.VISUAL_ID:
     case ConstraintEditPart.VISUAL_ID:
     case InstanceSpecification2EditPart.VISUAL_ID:
     case DependencyEditPart.VISUAL_ID:
     case GeneralizationSetEditPart.VISUAL_ID:
     case Interface2EditPart.VISUAL_ID:
     case Package4EditPart.VISUAL_ID:
     case AssociationClassRhombEditPart.VISUAL_ID:
     case PackageAsFrameEditPart.VISUAL_ID:
     case InstanceSpecification4EditPart.VISUAL_ID:
     case CommentEditPart.VISUAL_ID:
     case Package3EditPart.VISUAL_ID:
     case ClassEditPart.VISUAL_ID:
     case DataTypeEditPart.VISUAL_ID:
     case PrimitiveTypeEditPart.VISUAL_ID:
     case EnumerationEditPart.VISUAL_ID:
     case AssociationClassEditPart.VISUAL_ID:
     case Interface3EditPart.VISUAL_ID:
     case InstanceSpecificationEditPart.VISUAL_ID:
     case PropertyEditPart.VISUAL_ID:
     case OperationEditPart.VISUAL_ID:
     case Class3EditPart.VISUAL_ID:
     case PortEditPart.VISUAL_ID:
     case RedefinableTemplateSignatureEditPart.VISUAL_ID:
     case Property2EditPart.VISUAL_ID:
     case Operation2EditPart.VISUAL_ID:
     case Property3EditPart.VISUAL_ID:
     case Operation3EditPart.VISUAL_ID:
     case Property4EditPart.VISUAL_ID:
     case Operation4EditPart.VISUAL_ID:
     case EnumerationLiteralEditPart.VISUAL_ID:
     case Property5EditPart.VISUAL_ID:
     case Operation5EditPart.VISUAL_ID:
     case Property6EditPart.VISUAL_ID:
     case Operation6EditPart.VISUAL_ID:
     case Class4EditPart.VISUAL_ID:
     case ElementImportEditPart.VISUAL_ID:
     case Package6EditPart.VISUAL_ID:
     case Class5EditPart.VISUAL_ID:
     case Enumeration3EditPart.VISUAL_ID:
     case InstanceSpecification3EditPart.VISUAL_ID:
     case DataType3EditPart.VISUAL_ID:
     case PrimitiveType3EditPart.VISUAL_ID:
     case Interface4EditPart.VISUAL_ID:
     case Interface5EditPart.VISUAL_ID:
     case LiteralStringEditPart.VISUAL_ID:
     case LiteralIntegerEditPart.VISUAL_ID:
     case ExpressionEditPart.VISUAL_ID:
       return true;
   }
   return 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 (UMLVisualIDRegistry.getVisualID(incomingLink) == Dependency2EditPart.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)
         == ConstraintConstrainedElementEditPart.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;
     }
     if (UMLVisualIDRegistry.getVisualID(incomingLink) == DependencySupplierEditPart.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;
     }
     if (UMLVisualIDRegistry.getVisualID(incomingLink) == DependencyClientEditPart.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;
     }
     if (UMLVisualIDRegistry.getVisualID(incomingLink) == RealizationEditPart.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) == UsageEditPart.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) == TemplateBindingEditPart.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) == Dependency2EditPart.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) == RealizationEditPart.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) == UsageEditPart.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) == TemplateBindingEditPart.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());
 }