package org.eclipse.uml2.diagram.clazz.edit.policies; import java.util.ArrayList; 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.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; 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.commands.SetBoundsCommand; import org.eclipse.gmf.runtime.diagram.ui.commands.SetViewMutabilityCommand; 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.editpolicies.CanonicalEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; import org.eclipse.gmf.runtime.notation.Bounds; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.Location; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Ratio; import org.eclipse.gmf.runtime.notation.Size; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.gmf.runtime.notation.impl.EdgeImpl; import org.eclipse.uml2.diagram.clazz.conventions.InterfaceNotationConvention; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClass2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClassConnectorEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClassEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationClassRhombEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.AssociationInstanceEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Class2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Class3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Class4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Class5EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.ClassEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.CommentEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.ConstraintEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.DataType2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.DataType3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.DataTypeEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Dependency2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.DependencyEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.ElementImportEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Enumeration2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Enumeration3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.EnumerationLiteralEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.ExpressionEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Generalization2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.GeneralizationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.GeneralizationSetEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecification2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecification3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecification4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InstanceSpecificationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Interface2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Interface3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Interface4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Interface5EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InterfaceEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.InterfaceRealizationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.LiteralIntegerEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.LiteralStringEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Operation2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Operation3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Operation4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Operation5EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Operation6EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.OperationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Package2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Package3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Package4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Package6EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PackageAsFrameEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PackageEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PortEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveType2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveType3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PrimitiveTypeEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property2EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property3EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property4EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property5EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property6EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.Property7EditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.PropertyEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.RealizationEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.RedefinableTemplateSignatureEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.SlotEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.TemplateBindingEditPart; import org.eclipse.uml2.diagram.clazz.edit.parts.UsageEditPart; import org.eclipse.uml2.diagram.clazz.links.LinkDetector; import org.eclipse.uml2.diagram.clazz.part.UMLDiagramEditorPlugin; import org.eclipse.uml2.diagram.clazz.part.UMLDiagramUpdater; import org.eclipse.uml2.diagram.clazz.part.UMLLinkDescriptor; import org.eclipse.uml2.diagram.clazz.part.UMLNodeDescriptor; import org.eclipse.uml2.diagram.clazz.part.UMLVisualIDRegistry; import org.eclipse.uml2.diagram.common.async.ICanonicalHelper; import org.eclipse.uml2.diagram.common.editpolicies.UpdateDescriptionRequest; import org.eclipse.uml2.diagram.common.genapi.IUpdaterLinkDescriptor; import org.eclipse.uml2.diagram.common.genapi.IUpdaterNodeDescriptor; import org.eclipse.uml2.diagram.common.links.InterfaceLinkManager; import org.eclipse.uml2.uml.UMLPackage; /** * @generated */ public class PackageCanonicalEditPolicy extends CanonicalEditPolicy { /** * @generated */ private Set<EStructuralFeature> myFeaturesToSynchronize; /** * @generated */ protected void refreshOnActivate() { // Need to activate editpart children before invoking the canonical refresh for EditParts to add event listeners List<?> c = getHost().getChildren(); for (int i = 0; i < c.size(); i++) { ((EditPart) c.get(i)).activate(); } super.refreshOnActivate(); } /** * @NOT-generated */ @Override public void activate() { super.activate(); addListenerFilter("NotationListener_Container" + getDiagram().toString(), this, getDiagram(), NotationPackage.eINSTANCE.getView_PersistedChildren()); } /** * @generated */ @SuppressWarnings("rawtypes") protected List getSemanticChildrenList() { View viewObject = (View) getHost().getModel(); LinkedList<EObject> result = new LinkedList<EObject>(); List<UMLNodeDescriptor> childDescriptors = UMLDiagramUpdater.getSemanticChildren(viewObject); for (UMLNodeDescriptor d : childDescriptors) { result.add(d.getModelElement()); } return result; } /** * XXX: With GMF M7 the gen-method always return true. * * @generated NOT */ protected boolean shouldDeleteView(View view) { return super.shouldDeleteView(view) || InterfaceNotationConvention.hasAlternativeNotation(view); } /** * @generated */ @SuppressWarnings("unchecked") protected boolean isOrphaned(Collection<EObject> semanticChildren, final View view) { if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$ return UMLDiagramUpdater.isShortcutOrphaned(view); } return isMyDiagramElement(view) ? !semanticChildren.contains(view.getElement()) : isDefinitelyNotMyDiagramElement(view); } /** * @generated */ private boolean isDefinitelyNotMyDiagramElement(View view) { int visualID = UMLVisualIDRegistry.getVisualID(view); switch (visualID) { 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 SlotEditPart.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 */ private boolean isMyDiagramElement(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: return true; } return false; } /** * @generated */ protected Set getFeaturesToSynchronize() { if (myFeaturesToSynchronize == null) { myFeaturesToSynchronize = new HashSet<EStructuralFeature>(); myFeaturesToSynchronize.add(UMLPackage.eINSTANCE.getPackage_PackagedElement()); myFeaturesToSynchronize.add(UMLPackage.eINSTANCE.getComponent_PackagedElement()); myFeaturesToSynchronize.add(UMLPackage.eINSTANCE.getElement_OwnedComment()); } return myFeaturesToSynchronize; } /** * @generated */ protected void refreshSemantic() { if (resolveSemanticElement() == null) { return; } LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>(); List<UMLNodeDescriptor> childDescriptors = UMLDiagramUpdater.getSemanticChildren((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); } // FIXME remove this AROUND from CanonicalUpdate.xpt-template, when bug in GMF Tooling (327389) is fixed if (v.getEAnnotation("Shortcut") != null && UMLDiagramUpdater.isShortcutOrphaned(v)) { //$NON-NLS-1$ orphaned.add(v); } else { knownViewChildren.remove(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())) { 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 } 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.getLast()); } 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); } Collection<IAdaptable> createdConnectionViews = 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 Collection<IAdaptable> refreshConnections() { Map<EObject, View> domain2NotationMap = new HashMap<EObject, View>(); Collection<UMLLinkDescriptor> linkDescriptors = collectAllLinks(getDiagram(), domain2NotationMap); Collection existingLinks = new LinkedList(getDiagram().getEdges()); for (Iterator linksIterator = existingLinks.iterator(); linksIterator.hasNext();) { Edge nextDiagramLink = (Edge) linksIterator.next(); int diagramLinkVisualID = UMLVisualIDRegistry.getVisualID(nextDiagramLink); if (diagramLinkVisualID == -1) { if (nextDiagramLink.getSource() != null && nextDiagramLink.getTarget() != null) { linksIterator.remove(); } continue; } EObject diagramLinkObject = nextDiagramLink.getElement(); View sourceView = nextDiagramLink.getSource(); View targetView = nextDiagramLink.getTarget(); if (sourceView != null && targetView != null) { EObject diagramLinkSrc = sourceView.getElement(); EObject diagramLinkDst = targetView.getElement(); if (diagramLinkSrc != null && diagramLinkDst != null) { for (Iterator<UMLLinkDescriptor> linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext();) { UMLLinkDescriptor nextLinkDescriptor = linkDescriptorsIterator.next(); if (diagramLinkObject == nextLinkDescriptor.getModelElement() && diagramLinkSrc == nextLinkDescriptor.getSource() && diagramLinkDst == nextLinkDescriptor.getDestination() && diagramLinkVisualID == nextLinkDescriptor.getVisualID()) { //Add the edge and it's domain element to the domain2Notation-Map. if (!domain2NotationMap.containsKey(nextDiagramLink.getElement())) { domain2NotationMap.put(nextDiagramLink.getElement(), nextDiagramLink); } linksIterator.remove(); linkDescriptorsIterator.remove(); break; } } } } } deleteViews(existingLinks.iterator()); return createConnections(linkDescriptors, domain2NotationMap); } /** * @generated */ private Collection<UMLLinkDescriptor> collectAllLinksGen(View view, Map<EObject, View> domain2NotationMap) { if (!PackageEditPart.MODEL_ID.equals(UMLVisualIDRegistry.getModelID(view))) { return Collections.emptyList(); } if (view != null && view.getEAnnotation("Shortcut") != null) { return collectLinksOutgoingFromShortcut(view, domain2NotationMap); } LinkedList<UMLLinkDescriptor> result = new LinkedList<UMLLinkDescriptor>(); switch (UMLVisualIDRegistry.getVisualID(view)) { case PackageEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_1000ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Package2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_2002ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Class2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getClass_2001ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationClass2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getAssociationClass_2007ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case DataType2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getDataType_2004ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PrimitiveType2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPrimitiveType_2005ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Enumeration2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getEnumeration_2003ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InterfaceEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterface_2010ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case ConstraintEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getConstraint_2006ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InstanceSpecification2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInstanceSpecification_2008ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case DependencyEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getDependency_2009ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case GeneralizationSetEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getGeneralizationSet_2012ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Interface2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterface_2013ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Package4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_2014ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationClassRhombEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getAssociationClass_2015ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PackageAsFrameEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_2016ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InstanceSpecification4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInstanceSpecification_2017ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case CommentEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getComment_2018ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Package3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_3006ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case ClassEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getClass_3007ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case DataTypeEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getDataType_3008ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PrimitiveTypeEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPrimitiveType_3009ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case EnumerationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getEnumeration_3011ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationClassEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getAssociationClass_3012ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Interface3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterface_3041ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InstanceSpecificationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInstanceSpecification_3013ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PropertyEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3001ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case OperationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3002ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Class3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getClass_3003ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PortEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPort_3025ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case RedefinableTemplateSignatureEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getRedefinableTemplateSignature_3027ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3019ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Operation2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3020ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3014ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Operation3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3015ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3021ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Operation4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3022ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case EnumerationLiteralEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getEnumerationLiteral_3016ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property5EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3023ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Operation5EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3024ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case SlotEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getSlot_3017ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property6EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_3028ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Operation6EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getOperation_3029ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Class4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getClass_3030ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case ElementImportEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getElementImport_3031ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Package6EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPackage_3032ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Class5EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getClass_3033ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Enumeration3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getEnumeration_3034ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InstanceSpecification3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInstanceSpecification_3035ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case DataType3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getDataType_3036ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case PrimitiveType3EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getPrimitiveType_3037ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Interface4EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterface_3042ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Interface5EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterface_3043ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case LiteralStringEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getLiteralString_3038ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case LiteralIntegerEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getLiteralInteger_3039ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case ExpressionEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getExpression_3040ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case GeneralizationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getGeneralization_4001ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Dependency2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getDependency_4002ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Property7EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getProperty_4003ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getAssociation_4005ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case InterfaceRealizationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getInterfaceRealization_4008ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case RealizationEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getRealization_4010ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case Generalization2EditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getGeneralization_4011ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case UsageEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getUsage_4013ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationClassConnectorEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getAssociationClass_4014ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case AssociationInstanceEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getSlot_4015ContainedLinks(view)); } domain2NotationMap.put(view.getElement(), view); break; } case TemplateBindingEditPart.VISUAL_ID: { if (!domain2NotationMap.containsKey(view.getElement())) { result.addAll(UMLDiagramUpdater.getTemplateBinding_4016ContainedLinks(view)); } 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<IAdaptable> createConnections(Collection<UMLLinkDescriptor> linkDescriptors, Map<EObject, View> domain2NotationMap) { LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>(); for (UMLLinkDescriptor nextLinkDescriptor : linkDescriptors) { 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(), UMLVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), 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); //add newly generated view to domain2notation map EObject domainElement = (EObject) nextLinkDescriptor.getSemanticAdapter().getAdapter(EObject.class); View viewElement = (View) viewAdapter.getAdapter(EObject.class); domain2NotationMap.put(domainElement, viewElement); } } } return adapters; } /** * @generated */ private EditPart getEditPart(EObject domainModelElement, Map<EObject, View> domain2NotationMap) { View view = (View) domain2NotationMap.get(domainModelElement); if (view != null) { return (EditPart) getHost().getViewer().getEditPartRegistry().get(view); } return null; } /** * @generated NOT */ private Collection collectAllLinks(View view, Map<EObject, View> domain2NotationMap) { Collection result = collectAllLinksGen(view, domain2NotationMap); if (view instanceof Diagram) { result = new InterfaceLinkManager(result, UMLDiagramEditorPlugin.getInstance().getPreferenceStore(), new LinkDetector()).getFilteredLinkDescriptors(); } return result; } /** * @generated */ private Diagram getDiagram() { return ((View) getHost().getModel()).getDiagram(); } /** * @generated */ private Collection<UMLLinkDescriptor> collectLinksOutgoingFromShortcut(View view, Map<EObject, View> domain2NotationMap) { EditPart ep = (EditPart) getHost().getViewer().getEditPartRegistry().get(view); if (false == ep instanceof IGraphicalEditPart) { return Collections.emptyList(); } IGraphicalEditPart editPart = (IGraphicalEditPart) ep; UpdateDescriptionRequest request = new UpdateDescriptionRequest(); //we are not using the result command -- each editpart from the tree //is required to push data into the request editPart.getCommand(request); Set<UMLLinkDescriptor> linksToFromShortcuts = new HashSet<UMLLinkDescriptor>(); for (UpdateDescriptionRequest.Descriptor next : request.getDescriptions()) { List<IUpdaterLinkDescriptor> containedLinks = next.getContainedLinks(); for (IUpdaterLinkDescriptor ld : containedLinks) { if (ld instanceof UMLLinkDescriptor) { linksToFromShortcuts.add((UMLLinkDescriptor) ld); } } List<IUpdaterLinkDescriptor> outgoingLinks = next.getOutgoingLinks(); for (IUpdaterLinkDescriptor ld : outgoingLinks) { if (ld instanceof UMLLinkDescriptor) { linksToFromShortcuts.add((UMLLinkDescriptor) ld); } } if (next.getSemanticElement() != null) { domain2NotationMap.put(next.getSemanticElement(), next.getProvider().getNotationView()); } } return linksToFromShortcuts; } }