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.emf.ecore.EObject; |
10 | import org.eclipse.gef.commands.Command; |
11 | import org.eclipse.gef.commands.UnexecutableCommand; |
12 | import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; |
13 | import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand; |
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.ReorientRelationshipRequest; |
18 | import org.eclipse.gmf.runtime.notation.Edge; |
19 | import org.eclipse.gmf.runtime.notation.View; |
20 | |
21 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
22 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyEventConnectorCreateCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyEventConnectorReorientCommand; |
25 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyEventConnectorEditPart; |
26 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
27 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
28 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
29 | |
30 | /** |
31 | * Semantic edit policy for inner assembly context source roles. |
32 | * |
33 | * @generated |
34 | */ |
35 | public class SourceRoleItemSemanticEditPolicy extends |
36 | PalladioComponentModelBaseItemSemanticEditPolicy { |
37 | |
38 | /** |
39 | * @generated |
40 | */ |
41 | public SourceRoleItemSemanticEditPolicy() { |
42 | super(PalladioComponentModelElementTypes.SourceRole_3013); |
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.getSourceEdges().iterator(); it.hasNext();) { |
54 | Edge outgoingLink = (Edge) it.next(); |
55 | if (PalladioComponentModelVisualIDRegistry |
56 | .getVisualID(outgoingLink) == AssemblyEventConnectorEditPart.VISUAL_ID) { |
57 | DestroyElementRequest r = new DestroyElementRequest( |
58 | outgoingLink.getElement(), false); |
59 | cmd.add(new DestroyElementCommand(r)); |
60 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
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 | addDestroyShortcutsCommand(cmd, view); |
68 | // delete host element |
69 | cmd.add(new DestroyElementCommand(req)); |
70 | } else { |
71 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
72 | } |
73 | return getGEFWrapper(cmd.reduce()); |
74 | } |
75 | |
76 | /** |
77 | * Get the create relationship command or null / UnexecutableCommand instance |
78 | * if this is not an valid end for the connector creation. |
79 | * |
80 | * @param req The request object to create the command |
81 | * @return The prepared creation command object |
82 | * |
83 | * @generated not |
84 | */ |
85 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
86 | if (PalladioComponentModelElementTypes.AssemblyEventConnector_4007 == req |
87 | .getElementType()) { |
88 | return req.getTarget() == null ? getStartCreateRelationshipCommandAssemblyEventConnector(req) |
89 | : null; |
90 | } |
91 | return super.getCreateRelationshipCommand(req); |
92 | } |
93 | |
94 | /** |
95 | * Helper to create an instance of an outgoing assembly event connector. |
96 | * |
97 | * @param req The request describing the command to be created. |
98 | * @return The prepared command to create an AssemblyEventConnector |
99 | * |
100 | * @generated not |
101 | */ |
102 | protected Command getStartCreateRelationshipCommandAssemblyEventConnector( |
103 | CreateRelationshipRequest req) { |
104 | EObject sourceEObject = req.getSource(); |
105 | if (false == sourceEObject instanceof SourceRole) { |
106 | return UnexecutableCommand.INSTANCE; |
107 | } |
108 | SourceRole source = (SourceRole) sourceEObject; |
109 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
110 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
111 | req.getElementType()); |
112 | if (container == null) { |
113 | return UnexecutableCommand.INSTANCE; |
114 | } |
115 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
116 | .canCreateAssemblyEventConnector_4007(container, source, null)) { |
117 | return UnexecutableCommand.INSTANCE; |
118 | } |
119 | req.setParameter("SOURCE_CONTEXT", ((View) getHost().getParent() |
120 | .getModel()).getElement()); |
121 | return new Command() { |
122 | }; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected Command getStartCreateRelationshipCommand( |
129 | CreateRelationshipRequest req) { |
130 | if (PalladioComponentModelElementTypes.AssemblyEventConnector_4007 == req |
131 | .getElementType()) { |
132 | return getGEFWrapper(new AssemblyEventConnectorCreateCommand(req, |
133 | req.getSource(), req.getTarget())); |
134 | } |
135 | return null; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected Command getCompleteCreateRelationshipCommand( |
142 | CreateRelationshipRequest req) { |
143 | if (PalladioComponentModelElementTypes.AssemblyEventConnector_4007 == req |
144 | .getElementType()) { |
145 | return null; |
146 | } |
147 | return null; |
148 | } |
149 | |
150 | /** |
151 | * Returns command to reorient EClass based link. New link target or source |
152 | * should be the domain model element associated with this node. |
153 | * |
154 | * @generated |
155 | */ |
156 | protected Command getReorientRelationshipCommand( |
157 | ReorientRelationshipRequest req) { |
158 | switch (getVisualID(req)) { |
159 | case AssemblyEventConnectorEditPart.VISUAL_ID: |
160 | return getGEFWrapper(new AssemblyEventConnectorReorientCommand(req)); |
161 | } |
162 | return super.getReorientRelationshipCommand(req); |
163 | } |
164 | |
165 | } |