Package OntoUML.diagram.edit.policies

Source Code of OntoUML.diagram.edit.policies.ContainerCanonicalEditPolicy

package OntoUML.diagram.edit.policies;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;

/**
* @generated
*/
public class ContainerCanonicalEditPolicy extends CanonicalConnectionEditPolicy {

  /**
   * @generated
   */
  Set myFeaturesToSynchronize;

  /**
   * @generated
   */
  protected List getSemanticChildrenList() {
    View viewObject = (View) getHost().getModel();
    List result = new LinkedList();
    for (Iterator it = OntoUML.diagram.part.OntoUMLDiagramUpdater
        .getContainer_1000SemanticChildren(viewObject).iterator(); it
        .hasNext();) {
      result.add(((OntoUML.diagram.part.OntoUMLNodeDescriptor) it.next())
          .getModelElement());
    }
    return result;
  }

  /**
   * @generated
   */
  protected boolean shouldDeleteView(View view) {
    return true;
  }

  /**
   * @generated
   */
  protected boolean isOrphaned(Collection semanticChildren, final View view) {
    int visualID = OntoUML.diagram.part.OntoUMLVisualIDRegistry
        .getVisualID(view);
    switch (visualID) {
    case OntoUML.diagram.edit.parts.CategoryEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.CollectiveEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.KindEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.MixinEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.ModeEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.PhaseEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.QuantityEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.RelatorEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.RoleEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.RoleMixinEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.SimpleDatatypeEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.StructuralDatatypeEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.SubKindEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.GeneralizationSetEditPart.VISUAL_ID:
    case OntoUML.diagram.edit.parts.DerivationRuleEditPart.VISUAL_ID:
      if (!semanticChildren.contains(view.getElement())) {
        return true;
      }
    }
    return false;
  }

  /**
   * @generated
   */
  protected String getDefaultFactoryHint() {
    return null;
  }

  /**
   * @generated
   */
  protected Set getFeaturesToSynchronize() {
    if (myFeaturesToSynchronize == null) {
      myFeaturesToSynchronize = new HashSet();
      myFeaturesToSynchronize.add(OntoUML.OntoUMLPackage.eINSTANCE
          .getContainer_InstanciarElement());
    }
    return myFeaturesToSynchronize;
  }

  /**
   * @generated
   */
  protected List getSemanticConnectionsList() {
    return Collections.EMPTY_LIST;
  }

  /**
   * @generated
   */
  protected EObject getSourceElement(EObject relationship) {
    return null;
  }

  /**
   * @generated
   */
  protected EObject getTargetElement(EObject relationship) {
    return null;
  }

  /**
   * @generated
   */
  protected boolean shouldIncludeConnection(Edge connector,
      Collection children) {
    return false;
  }

  /**
   * @generated
   */
  protected void refreshSemantic() {
    List createdViews = new LinkedList();
    createdViews.addAll(refreshSemanticChildren());
    List createdConnectionViews = new LinkedList();
    createdConnectionViews.addAll(refreshSemanticConnections());
    createdConnectionViews.addAll(refreshConnections());

    if (createdViews.size() > 1) {
      // perform a layout of the container
      DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host()
          .getEditingDomain(), createdViews, host());
      executeCommand(new ICommandProxy(layoutCmd));
    }

    createdViews.addAll(createdConnectionViews);
    makeViewsImmutable(createdViews);
  }

  /**
   * @generated
   */
  private Diagram getDiagram() {
    return ((View) getHost().getModel()).getDiagram();
  }

  /**
   * @generated
   */
  private Collection refreshConnections() {
    Map domain2NotationMap = new HashMap();
    Collection linkDescriptors = collectAllLinks(getDiagram(),
        domain2NotationMap);
    Collection existingLinks = new LinkedList(getDiagram().getEdges());
    for (Iterator linksIterator = existingLinks.iterator(); linksIterator
        .hasNext();) {
      Edge nextDiagramLink = (Edge) linksIterator.next();
      int diagramLinkVisualID = OntoUML.diagram.part.OntoUMLVisualIDRegistry
          .getVisualID(nextDiagramLink);
      if (diagramLinkVisualID == -1) {
        if (nextDiagramLink.getSource() != null
            && nextDiagramLink.getTarget() != null) {
          linksIterator.remove();
        }
        continue;
      }
      EObject diagramLinkObject = nextDiagramLink.getElement();
      EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
      EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
      for (Iterator LinkDescriptorsIterator = linkDescriptors.iterator(); LinkDescriptorsIterator
          .hasNext();) {
        OntoUML.diagram.part.OntoUMLLinkDescriptor nextLinkDescriptor = (OntoUML.diagram.part.OntoUMLLinkDescriptor) LinkDescriptorsIterator
            .next();
        if (diagramLinkObject == nextLinkDescriptor.getModelElement()
            && diagramLinkSrc == nextLinkDescriptor.getSource()
            && diagramLinkDst == nextLinkDescriptor
                .getDestination()
            && diagramLinkVisualID == nextLinkDescriptor
                .getVisualID()) {
          linksIterator.remove();
          LinkDescriptorsIterator.remove();
        }
      }
    }
    deleteViews(existingLinks.iterator());
    return createConnections(linkDescriptors, domain2NotationMap);
  }

  /**
   * @generated
   */
  private Collection collectAllLinks(View view, Map domain2NotationMap) {
    if (!OntoUML.diagram.edit.parts.ContainerEditPart.MODEL_ID
        .equals(OntoUML.diagram.part.OntoUMLVisualIDRegistry
            .getModelID(view))) {
      return Collections.EMPTY_LIST;
    }
    Collection result = new LinkedList();
    switch (OntoUML.diagram.part.OntoUMLVisualIDRegistry.getVisualID(view)) {
    case OntoUML.diagram.edit.parts.ContainerEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getContainer_1000ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.CategoryEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getCategory_2001ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.CollectiveEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getCollective_2002ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.KindEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getKind_2003ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.MixinEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getMixin_2004ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.ModeEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getMode_2005ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.PhaseEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getPhase_2006ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.QuantityEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getQuantity_2007ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.RelatorEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getRelator_2008ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.RoleEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getRole_2009ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.RoleMixinEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getRoleMixin_2010ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.SimpleDatatypeEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getSimpleDatatype_2011ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.StructuralDatatypeEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getStructuralDatatype_2012ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.SubKindEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getSubKind_2013ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.GeneralizationSetEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getGeneralizationSet_2014ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.DerivationRuleEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getDerivationRule_2015ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.CharacterizationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getCharacterization_4001ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.ComponentOfEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getComponentOf_4002ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.DatatypeRelationshipEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getDatatypeRelationship_4019ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.DerivationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getDerivation_4004ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.FormalAssociationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getFormalAssociation_4005ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.GeneralizationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getGeneralization_4006ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.MaterialAssociationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getMaterialAssociation_4007ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.MediationEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getMediation_4008ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.MemberOfEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getMemberOf_4009ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.SubCollectionOfEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getSubCollectionOf_4010ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.SubQuantityOfEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getSubQuantityOf_4011ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.BinaryAssociationAtomEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getBinaryAssociationAtom_4013ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.BinaryAssociationAtom2EditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getBinaryAssociationAtom_4014ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.BinaryAssociationAtom3EditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getBinaryAssociationAtom_4015ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.ClassifierAtomEditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getClassifierAtom_4016ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.ClassifierAtom2EditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getClassifierAtom_4017ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    case OntoUML.diagram.edit.parts.ClassifierAtom3EditPart.VISUAL_ID: {
      if (!domain2NotationMap.containsKey(view.getElement())) {
        result.addAll(OntoUML.diagram.part.OntoUMLDiagramUpdater
            .getClassifierAtom_4018ContainedLinks(view));
      }
      if (!domain2NotationMap.containsKey(view.getElement())
          || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
        domain2NotationMap.put(view.getElement(), view);
      }
      break;
    }
    }
    for (Iterator children = view.getChildren().iterator(); children
        .hasNext();) {
      result.addAll(collectAllLinks((View) children.next(),
          domain2NotationMap));
    }
    for (Iterator edges = view.getSourceEdges().iterator(); edges.hasNext();) {
      result.addAll(collectAllLinks((View) edges.next(),
          domain2NotationMap));
    }
    return result;
  }

  /**
   * @generated
   */
  private Collection createConnections(Collection linkDescriptors,
      Map domain2NotationMap) {
    List adapters = new LinkedList();
    for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator
        .hasNext();) {
      final OntoUML.diagram.part.OntoUMLLinkDescriptor nextLinkDescriptor = (OntoUML.diagram.part.OntoUMLLinkDescriptor) linkDescriptorsIterator
          .next();
      EditPart sourceEditPart = getEditPart(nextLinkDescriptor
          .getSource(), domain2NotationMap);
      EditPart targetEditPart = getEditPart(nextLinkDescriptor
          .getDestination(), domain2NotationMap);
      if (sourceEditPart == null || targetEditPart == null) {
        continue;
      }
      CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
          nextLinkDescriptor.getSemanticAdapter(), null,
          ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost())
              .getDiagramPreferencesHint());
      CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(
          descriptor);
      ccr.setType(RequestConstants.REQ_CONNECTION_START);
      ccr.setSourceEditPart(sourceEditPart);
      sourceEditPart.getCommand(ccr);
      ccr.setTargetEditPart(targetEditPart);
      ccr.setType(RequestConstants.REQ_CONNECTION_END);
      Command cmd = targetEditPart.getCommand(ccr);
      if (cmd != null && cmd.canExecute()) {
        executeCommand(cmd);
        IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
        if (viewAdapter != null) {
          adapters.add(viewAdapter);
        }
      }
    }
    return adapters;
  }

  /**
   * @generated
   */
  private EditPart getEditPart(EObject domainModelElement,
      Map domain2NotationMap) {
    View view = (View) domain2NotationMap.get(domainModelElement);
    if (view != null) {
      return (EditPart) getHost().getViewer().getEditPartRegistry().get(
          view);
    }
    return null;
  }
}
TOP

Related Classes of OntoUML.diagram.edit.policies.ContainerCanonicalEditPolicy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.