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