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