1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.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.diagram.core.commands.DeleteCommand; |
11 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
16 | import org.eclipse.gmf.runtime.notation.Edge; |
17 | import org.eclipse.gmf.runtime.notation.View; |
18 | |
19 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorCreateCommand; |
20 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorReorientCommand; |
21 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.RequiredDelegationConnectorCreateCommand; |
22 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.RequiredDelegationConnectorReorientCommand; |
23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyConnectorEditPart; |
24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.RequiredDelegationConnectorEditPart; |
25 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
26 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
27 | |
28 | /** |
29 | * The semantic edit policy for outer system operation required roles. |
30 | * |
31 | * |
32 | * @generated |
33 | */ |
34 | public class OperationRequiredRole2ItemSemanticEditPolicy extends |
35 | PalladioComponentModelBaseItemSemanticEditPolicy { |
36 | |
37 | /** |
38 | * @generated |
39 | */ |
40 | public OperationRequiredRole2ItemSemanticEditPolicy() { |
41 | super(PalladioComponentModelElementTypes.OperationRequiredRole_3012); |
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) == RequiredDelegationConnectorEditPart.VISUAL_ID) { |
56 | DestroyElementRequest r = new DestroyElementRequest( |
57 | incomingLink.getElement(), false); |
58 | cmd.add(new DestroyElementCommand(r)); |
59 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
60 | continue; |
61 | } |
62 | } |
63 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
64 | Edge outgoingLink = (Edge) it.next(); |
65 | if (PalladioComponentModelVisualIDRegistry |
66 | .getVisualID(outgoingLink) == AssemblyConnectorEditPart.VISUAL_ID) { |
67 | DestroyElementRequest r = new DestroyElementRequest( |
68 | outgoingLink.getElement(), false); |
69 | cmd.add(new DestroyElementCommand(r)); |
70 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
71 | continue; |
72 | } |
73 | if (PalladioComponentModelVisualIDRegistry |
74 | .getVisualID(outgoingLink) == RequiredDelegationConnectorEditPart.VISUAL_ID) { |
75 | DestroyElementRequest r = new DestroyElementRequest( |
76 | outgoingLink.getElement(), false); |
77 | cmd.add(new DestroyElementCommand(r)); |
78 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
79 | continue; |
80 | } |
81 | } |
82 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
83 | if (annotation == null) { |
84 | // there are indirectly referenced children, need extra commands: false |
85 | addDestroyShortcutsCommand(cmd, view); |
86 | // delete host element |
87 | cmd.add(new DestroyElementCommand(req)); |
88 | } else { |
89 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
90 | } |
91 | return getGEFWrapper(cmd.reduce()); |
92 | } |
93 | |
94 | /** |
95 | * @generated |
96 | */ |
97 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
98 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
99 | : getCompleteCreateRelationshipCommand(req); |
100 | return command != null ? command : super |
101 | .getCreateRelationshipCommand(req); |
102 | } |
103 | |
104 | /** |
105 | * Get the create relation ship start command. |
106 | * |
107 | * This method has manually adopted to disallow any connectors to be started at the |
108 | * system required role. AssemblyConnectors are not allowed anyway and delegation connectors |
109 | * should be started at the inner operation required role. |
110 | * |
111 | * @generated not |
112 | */ |
113 | protected Command getStartCreateRelationshipCommand( |
114 | CreateRelationshipRequest req) { |
115 | return null; |
116 | } |
117 | |
118 | /** |
119 | * @generated |
120 | */ |
121 | protected Command getCompleteCreateRelationshipCommand( |
122 | CreateRelationshipRequest req) { |
123 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
124 | .getElementType()) { |
125 | return null; |
126 | } |
127 | if (PalladioComponentModelElementTypes.RequiredDelegationConnector_4005 == req |
128 | .getElementType()) { |
129 | return getGEFWrapper(new RequiredDelegationConnectorCreateCommand( |
130 | req, req.getSource(), req.getTarget())); |
131 | } |
132 | return null; |
133 | } |
134 | |
135 | /** |
136 | * Returns command to reorient EClass based link. New link target or source |
137 | * should be the domain model element associated with this node. |
138 | * |
139 | * @generated |
140 | */ |
141 | protected Command getReorientRelationshipCommand( |
142 | ReorientRelationshipRequest req) { |
143 | switch (getVisualID(req)) { |
144 | case AssemblyConnectorEditPart.VISUAL_ID: |
145 | return getGEFWrapper(new AssemblyConnectorReorientCommand(req)); |
146 | case RequiredDelegationConnectorEditPart.VISUAL_ID: |
147 | return getGEFWrapper(new RequiredDelegationConnectorReorientCommand( |
148 | req)); |
149 | } |
150 | return super.getReorientRelationshipCommand(req); |
151 | } |
152 | |
153 | } |