| 1 | /* |
| 2 | *Copyright 2007, SDQ, IPD, U KA |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.policies; |
| 5 | |
| 6 | import java.util.List; |
| 7 | import java.util.Collection; |
| 8 | import org.eclipse.gmf.runtime.notation.Edge; |
| 9 | import org.eclipse.emf.ecore.EObject; |
| 10 | import de.uka.ipd.sdq.pcm.allocation.Allocation; |
| 11 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationContextEditPart; |
| 12 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.AllocationEditPart; |
| 13 | import de.uka.ipd.sdq.pcm.gmf.allocation.edit.parts.ResourceContainerEditPart; |
| 14 | |
| 15 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelDiagramUpdater; |
| 16 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelNodeDescriptor; |
| 17 | import de.uka.ipd.sdq.pcm.gmf.allocation.part.PalladioComponentModelVisualIDRegistry; |
| 18 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.Collections; |
| 22 | import java.util.HashMap; |
| 23 | import java.util.Iterator; |
| 24 | import java.util.LinkedList; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | import org.eclipse.core.runtime.IAdaptable; |
| 28 | |
| 29 | import org.eclipse.emf.ecore.EClass; |
| 30 | |
| 31 | import org.eclipse.emf.ecore.resource.Resource; |
| 32 | |
| 33 | import org.eclipse.gef.EditPart; |
| 34 | |
| 35 | import org.eclipse.gef.commands.Command; |
| 36 | |
| 37 | import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; |
| 38 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| 39 | |
| 40 | import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
| 41 | |
| 42 | import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand; |
| 43 | import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand; |
| 44 | import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; |
| 45 | import org.eclipse.gmf.runtime.diagram.ui.commands.SetViewMutabilityCommand; |
| 46 | |
| 47 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
| 48 | |
| 49 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy; |
| 50 | |
| 51 | import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages; |
| 52 | |
| 53 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest; |
| 54 | import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; |
| 55 | import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; |
| 56 | |
| 57 | import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; |
| 58 | |
| 59 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
| 60 | |
| 61 | import org.eclipse.gmf.runtime.notation.Diagram; |
| 62 | import org.eclipse.gmf.runtime.notation.View; |
| 63 | |
| 64 | /** |
| 65 | * @generated |
| 66 | */ |
| 67 | public class AllocationCanonicalEditPolicy extends |
| 68 | CanonicalConnectionEditPolicy { |
| 69 | |
| 70 | /** |
| 71 | * @generated not |
| 72 | */ |
| 73 | protected List getSemanticChildrenList() { |
| 74 | List result = new LinkedList(); |
| 75 | EObject modelObject = ((View) getHost().getModel()).getElement(); |
| 76 | View viewObject = (View) getHost().getModel(); |
| 77 | ResourceEnvironment re = ((Allocation) modelObject) |
| 78 | .getTargetResourceEnvironment_Allocation(); |
| 79 | |
| 80 | return re.getResourceContainer_ResourceEnvironment(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @generated not |
| 85 | */ |
| 86 | protected boolean shouldDeleteView(View view) { |
| 87 | if (view.getEAnnotation("Shortcut") != null) { //$NON-NLS-1$ |
| 88 | return view.isSetElement() |
| 89 | && (view.getElement() == null || view.getElement() |
| 90 | .eIsProxy()); |
| 91 | } |
| 92 | int nodeVID = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @generated |
| 98 | */ |
| 99 | protected boolean isOrphaned(Collection semanticChildren, final View view) { |
| 100 | int visualID = PalladioComponentModelVisualIDRegistry.getVisualID(view); |
| 101 | switch (visualID) { |
| 102 | case ResourceContainerEditPart.VISUAL_ID: |
| 103 | return !semanticChildren.contains(view.getElement()) |
| 104 | || visualID != PalladioComponentModelVisualIDRegistry |
| 105 | .getNodeVisualID((View) getHost().getModel(), view |
| 106 | .getElement()); |
| 107 | } |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @generated |
| 113 | */ |
| 114 | protected String getDefaultFactoryHint() { |
| 115 | return null; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @generated |
| 120 | */ |
| 121 | protected List getSemanticConnectionsList() { |
| 122 | return Collections.EMPTY_LIST; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @generated |
| 127 | */ |
| 128 | protected EObject getSourceElement(EObject relationship) { |
| 129 | return null; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @generated |
| 134 | */ |
| 135 | protected EObject getTargetElement(EObject relationship) { |
| 136 | return null; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @generated |
| 141 | */ |
| 142 | protected boolean shouldIncludeConnection(Edge connector, |
| 143 | Collection children) { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @generated |
| 149 | */ |
| 150 | protected void refreshSemantic() { |
| 151 | List createdViews = new LinkedList(); |
| 152 | createdViews.addAll(refreshSemanticChildren()); |
| 153 | List createdConnectionViews = new LinkedList(); |
| 154 | createdConnectionViews.addAll(refreshSemanticConnections()); |
| 155 | |
| 156 | if (createdViews.size() > 1) { |
| 157 | // perform a layout of the container |
| 158 | DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host() |
| 159 | .getEditingDomain(), createdViews, host()); |
| 160 | executeCommand(new ICommandProxy(layoutCmd)); |
| 161 | } |
| 162 | |
| 163 | createdViews.addAll(createdConnectionViews); |
| 164 | makeViewsImmutable(createdViews); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @generated |
| 169 | */ |
| 170 | private Diagram getDiagram() { |
| 171 | return ((View) getHost().getModel()).getDiagram(); |
| 172 | } |
| 173 | |
| 174 | } |