1 | /* |
2 | * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.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.commands.DestroyReferenceCommand; |
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.DestroyReferenceRequest; |
17 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
18 | import org.eclipse.gmf.runtime.notation.Edge; |
19 | import org.eclipse.gmf.runtime.notation.View; |
20 | |
21 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
22 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
23 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
24 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
25 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | public class StopActionItemSemanticEditPolicy extends |
31 | PalladioComponentModelBaseItemSemanticEditPolicy { |
32 | |
33 | /** |
34 | * @generated |
35 | */ |
36 | public StopActionItemSemanticEditPolicy() { |
37 | super(PalladioComponentModelElementTypes.StopAction_2002); |
38 | } |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
44 | View view = (View) getHost().getModel(); |
45 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
46 | getEditingDomain(), null); |
47 | cmd.setTransactionNestingEnabled(false); |
48 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
49 | Edge incomingLink = (Edge) it.next(); |
50 | if (PalladioComponentModelVisualIDRegistry |
51 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
52 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
53 | incomingLink.getSource().getElement(), null, |
54 | incomingLink.getTarget().getElement(), false); |
55 | cmd.add(new DestroyReferenceCommand(r)); |
56 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
57 | continue; |
58 | } |
59 | } |
60 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
61 | Edge outgoingLink = (Edge) it.next(); |
62 | if (PalladioComponentModelVisualIDRegistry |
63 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
64 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
65 | outgoingLink.getSource().getElement(), null, |
66 | outgoingLink.getTarget().getElement(), false); |
67 | cmd.add(new DestroyReferenceCommand(r)); |
68 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
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 | addDestroyShortcutsCommand(cmd, view); |
76 | // delete host element |
77 | cmd.add(new DestroyElementCommand(req)); |
78 | } else { |
79 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
80 | } |
81 | return getGEFWrapper(cmd.reduce()); |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
88 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
89 | : getCompleteCreateRelationshipCommand(req); |
90 | return command != null ? command : super |
91 | .getCreateRelationshipCommand(req); |
92 | } |
93 | |
94 | /** |
95 | * @generated |
96 | */ |
97 | protected Command getStartCreateRelationshipCommand( |
98 | CreateRelationshipRequest req) { |
99 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
100 | .getElementType()) { |
101 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
102 | req, req.getSource(), req.getTarget())); |
103 | } |
104 | return null; |
105 | } |
106 | |
107 | /** |
108 | * @generated |
109 | */ |
110 | protected Command getCompleteCreateRelationshipCommand( |
111 | CreateRelationshipRequest req) { |
112 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
113 | .getElementType()) { |
114 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
115 | req, req.getSource(), req.getTarget())); |
116 | } |
117 | return null; |
118 | } |
119 | |
120 | /** |
121 | * Returns command to reorient EReference based link. New link target or source |
122 | * should be the domain model element associated with this node. |
123 | * |
124 | * @generated |
125 | */ |
126 | protected Command getReorientReferenceRelationshipCommand( |
127 | ReorientReferenceRelationshipRequest req) { |
128 | switch (getVisualID(req)) { |
129 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
130 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
131 | req)); |
132 | } |
133 | return super.getReorientReferenceRelationshipCommand(req); |
134 | } |
135 | |
136 | } |