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