1 | /* |
2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.resource.edit.policies; |
5 | |
6 | import java.util.Iterator; |
7 | |
8 | import org.eclipse.emf.ecore.EAnnotation; |
9 | import org.eclipse.gef.commands.Command; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand; |
11 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
12 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyReferenceCommand; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
18 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
19 | import org.eclipse.gmf.runtime.notation.Edge; |
20 | import org.eclipse.gmf.runtime.notation.Node; |
21 | import org.eclipse.gmf.runtime.notation.View; |
22 | |
23 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.commands.LinkingResourceConnectedResourceContainers_LinkingResourceCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.commands.LinkingResourceConnectedResourceContainers_LinkingResourceReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.LinkingResourceConnectedResourceContainers_LinkingResourceEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ProcessingResourceSpecificationEditPart; |
27 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.parts.ResourceContainerResourceContainerCompartmentEditPart; |
28 | import de.uka.ipd.sdq.pcm.gmf.resource.part.PalladioComponentModelVisualIDRegistry; |
29 | import de.uka.ipd.sdq.pcm.gmf.resource.providers.PalladioComponentModelElementTypes; |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public class ResourceContainerItemSemanticEditPolicy extends |
35 | PalladioComponentModelBaseItemSemanticEditPolicy { |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | public ResourceContainerItemSemanticEditPolicy() { |
41 | super(PalladioComponentModelElementTypes.ResourceContainer_2001); |
42 | } |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
48 | View view = (View) getHost().getModel(); |
49 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
50 | getEditingDomain(), null); |
51 | cmd.setTransactionNestingEnabled(false); |
52 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
53 | Edge incomingLink = (Edge) it.next(); |
54 | if (PalladioComponentModelVisualIDRegistry |
55 | .getVisualID(incomingLink) == LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID) { |
56 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
57 | incomingLink.getSource().getElement(), null, |
58 | incomingLink.getTarget().getElement(), false); |
59 | cmd.add(new DestroyReferenceCommand(r)); |
60 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
61 | continue; |
62 | } |
63 | } |
64 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
65 | if (annotation == null) { |
66 | // there are indirectly referenced children, need extra commands: false |
67 | addDestroyChildNodesCommand(cmd); |
68 | addDestroyShortcutsCommand(cmd, view); |
69 | // delete host element |
70 | cmd.add(new DestroyElementCommand(req)); |
71 | } else { |
72 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
73 | } |
74 | return getGEFWrapper(cmd.reduce()); |
75 | } |
76 | |
77 | /** |
78 | * @generated |
79 | */ |
80 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
81 | View view = (View) getHost().getModel(); |
82 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
83 | Node node = (Node) nit.next(); |
84 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
85 | case ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID: |
86 | for (Iterator cit = node.getChildren().iterator(); cit |
87 | .hasNext();) { |
88 | Node cnode = (Node) cit.next(); |
89 | switch (PalladioComponentModelVisualIDRegistry |
90 | .getVisualID(cnode)) { |
91 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
92 | cmd.add(new DestroyElementCommand( |
93 | new DestroyElementRequest(getEditingDomain(), |
94 | cnode.getElement(), false))); // directlyOwned: true |
95 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
96 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
97 | break; |
98 | } |
99 | } |
100 | break; |
101 | } |
102 | } |
103 | } |
104 | |
105 | /** |
106 | * @generated |
107 | */ |
108 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
109 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
110 | : getCompleteCreateRelationshipCommand(req); |
111 | return command != null ? command : super |
112 | .getCreateRelationshipCommand(req); |
113 | } |
114 | |
115 | /** |
116 | * @generated |
117 | */ |
118 | protected Command getStartCreateRelationshipCommand( |
119 | CreateRelationshipRequest req) { |
120 | if (PalladioComponentModelElementTypes.LinkingResourceConnectedResourceContainers_LinkingResource_4002 == req |
121 | .getElementType()) { |
122 | return null; |
123 | } |
124 | return null; |
125 | } |
126 | |
127 | /** |
128 | * @generated |
129 | */ |
130 | protected Command getCompleteCreateRelationshipCommand( |
131 | CreateRelationshipRequest req) { |
132 | if (PalladioComponentModelElementTypes.LinkingResourceConnectedResourceContainers_LinkingResource_4002 == req |
133 | .getElementType()) { |
134 | return getGEFWrapper(new LinkingResourceConnectedResourceContainers_LinkingResourceCreateCommand( |
135 | req, req.getSource(), req.getTarget())); |
136 | } |
137 | return null; |
138 | } |
139 | |
140 | /** |
141 | * Returns command to reorient EReference based link. New link target or source |
142 | * should be the domain model element associated with this node. |
143 | * |
144 | * @generated |
145 | */ |
146 | protected Command getReorientReferenceRelationshipCommand( |
147 | ReorientReferenceRelationshipRequest req) { |
148 | switch (getVisualID(req)) { |
149 | case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: |
150 | return getGEFWrapper(new LinkingResourceConnectedResourceContainers_LinkingResourceReorientCommand( |
151 | req)); |
152 | } |
153 | return super.getReorientReferenceRelationshipCommand(req); |
154 | } |
155 | |
156 | } |