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.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.DestroyElementRequest; |
15 | import org.eclipse.gmf.runtime.notation.Node; |
16 | import org.eclipse.gmf.runtime.notation.View; |
17 | |
18 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.VariableCharacterisation3EditPart; |
19 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.VariableUsageVariableCharacterisation4EditPart; |
20 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
21 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
22 | |
23 | /** |
24 | * @generated |
25 | */ |
26 | public class VariableUsage4ItemSemanticEditPolicy extends |
27 | PalladioComponentModelBaseItemSemanticEditPolicy { |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | public VariableUsage4ItemSemanticEditPolicy() { |
33 | super(PalladioComponentModelElementTypes.VariableUsage_3047); |
34 | } |
35 | |
36 | /** |
37 | * @generated |
38 | */ |
39 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
40 | View view = (View) getHost().getModel(); |
41 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
42 | getEditingDomain(), null); |
43 | cmd.setTransactionNestingEnabled(false); |
44 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
45 | if (annotation == null) { |
46 | // there are indirectly referenced children, need extra commands: false |
47 | addDestroyChildNodesCommand(cmd); |
48 | addDestroyShortcutsCommand(cmd, view); |
49 | // delete host element |
50 | cmd.add(new DestroyElementCommand(req)); |
51 | } else { |
52 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
53 | } |
54 | return getGEFWrapper(cmd.reduce()); |
55 | } |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
61 | View view = (View) getHost().getModel(); |
62 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
63 | Node node = (Node) nit.next(); |
64 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
65 | case VariableUsageVariableCharacterisation4EditPart.VISUAL_ID: |
66 | for (Iterator cit = node.getChildren().iterator(); cit |
67 | .hasNext();) { |
68 | Node cnode = (Node) cit.next(); |
69 | switch (PalladioComponentModelVisualIDRegistry |
70 | .getVisualID(cnode)) { |
71 | case VariableCharacterisation3EditPart.VISUAL_ID: |
72 | cmd.add(new DestroyElementCommand( |
73 | new DestroyElementRequest(getEditingDomain(), |
74 | cnode.getElement(), false))); // directlyOwned: true |
75 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
76 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
77 | break; |
78 | } |
79 | } |
80 | break; |
81 | } |
82 | } |
83 | } |
84 | |
85 | } |