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