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.gef.commands.UnexecutableCommand; |
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.View; |
19 | |
20 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
21 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
22 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyInfrastructureConnectorCreateCommand; |
23 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyInfrastructureConnectorReorientCommand; |
24 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.AssemblyInfrastructureConnectorEditPart; |
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 | * @generated |
30 | */ |
31 | public class InfrastructureProvidedRoleItemSemanticEditPolicy extends |
32 | PalladioComponentModelBaseItemSemanticEditPolicy { |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | public InfrastructureProvidedRoleItemSemanticEditPolicy() { |
38 | super( |
39 | PalladioComponentModelElementTypes.InfrastructureProvidedRole_3015); |
40 | } |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
46 | View view = (View) getHost().getModel(); |
47 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
48 | getEditingDomain(), null); |
49 | cmd.setTransactionNestingEnabled(false); |
50 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
51 | Edge incomingLink = (Edge) it.next(); |
52 | if (PalladioComponentModelVisualIDRegistry |
53 | .getVisualID(incomingLink) == AssemblyInfrastructureConnectorEditPart.VISUAL_ID) { |
54 | DestroyElementRequest r = new DestroyElementRequest( |
55 | incomingLink.getElement(), false); |
56 | cmd.add(new DestroyElementCommand(r)); |
57 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
58 | continue; |
59 | } |
60 | } |
61 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
62 | if (annotation == null) { |
63 | // there are indirectly referenced children, need extra commands: false |
64 | addDestroyShortcutsCommand(cmd, view); |
65 | // delete host element |
66 | cmd.add(new DestroyElementCommand(req)); |
67 | } else { |
68 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
69 | } |
70 | return getGEFWrapper(cmd.reduce()); |
71 | } |
72 | |
73 | /** |
74 | * @generated |
75 | */ |
76 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
77 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
78 | : getCompleteCreateRelationshipCommand(req); |
79 | return command != null ? command : super |
80 | .getCreateRelationshipCommand(req); |
81 | } |
82 | |
83 | /** |
84 | * @generated |
85 | */ |
86 | protected Command getStartCreateRelationshipCommand( |
87 | CreateRelationshipRequest req) { |
88 | if (PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008 == req |
89 | .getElementType()) { |
90 | return null; |
91 | } |
92 | return null; |
93 | } |
94 | |
95 | /**Adapted to transfer information on containing component and assembly context of target. |
96 | * @generated not |
97 | */ |
98 | protected Command getCompleteCreateRelationshipCommand( |
99 | CreateRelationshipRequest req) { |
100 | if (PalladioComponentModelElementTypes.AssemblyInfrastructureConnector_4008 == req |
101 | .getElementType()) { |
102 | |
103 | // set the container |
104 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
105 | req.getSource(), CompositionPackage.eINSTANCE |
106 | .getComposedStructure(), req.getElementType()); |
107 | if (container == null) { |
108 | return UnexecutableCommand.INSTANCE; |
109 | } |
110 | req.setParameter("CONTAINER", container); |
111 | |
112 | // set assembly context |
113 | req.setParameter("TARGET_ASSEMBLY_CONTEXT", ((View) getHost().getParent() |
114 | .getModel()).getElement()); |
115 | return getGEFWrapper(new AssemblyInfrastructureConnectorCreateCommand( |
116 | req, req.getSource(), req.getTarget())); |
117 | } |
118 | return null; |
119 | } |
120 | |
121 | /** |
122 | * Returns command to reorient EClass based link. New link target or source |
123 | * should be the domain model element associated with this node. |
124 | * |
125 | * @generated |
126 | */ |
127 | protected Command getReorientRelationshipCommand( |
128 | ReorientRelationshipRequest req) { |
129 | switch (getVisualID(req)) { |
130 | case AssemblyInfrastructureConnectorEditPart.VISUAL_ID: |
131 | return getGEFWrapper(new AssemblyInfrastructureConnectorReorientCommand( |
132 | req)); |
133 | } |
134 | return super.getReorientRelationshipCommand(req); |
135 | } |
136 | |
137 | } |