| 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.commands.DestroyReferenceCommand; |
| 15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| 16 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; |
| 17 | import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest; |
| 18 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
| 19 | import org.eclipse.gmf.runtime.notation.Edge; |
| 20 | import org.eclipse.gmf.runtime.notation.Node; |
| 21 | import org.eclipse.gmf.runtime.notation.View; |
| 22 | |
| 23 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionCreateCommand; |
| 24 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.commands.AbstractActionSuccessor_AbstractActionReorientCommand; |
| 25 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.AbstractActionSuccessor_AbstractActionEditPart; |
| 26 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.BranchActionBranchTransitionCompartment2EditPart; |
| 27 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.GuardedBranchTransitionEditPart; |
| 28 | import de.uka.ipd.sdq.pcm.gmf.seff.edit.parts.ProbabilisticBranchTransitionEditPart; |
| 29 | import de.uka.ipd.sdq.pcm.gmf.seff.part.PalladioComponentModelVisualIDRegistry; |
| 30 | import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes; |
| 31 | |
| 32 | /** |
| 33 | * @generated |
| 34 | */ |
| 35 | public class BranchActionItemSemanticEditPolicy extends |
| 36 | PalladioComponentModelBaseItemSemanticEditPolicy { |
| 37 | |
| 38 | /** |
| 39 | * @generated |
| 40 | */ |
| 41 | public BranchActionItemSemanticEditPolicy() { |
| 42 | super(PalladioComponentModelElementTypes.BranchAction_2005); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @generated |
| 47 | */ |
| 48 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
| 49 | View view = (View) getHost().getModel(); |
| 50 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
| 51 | getEditingDomain(), null); |
| 52 | cmd.setTransactionNestingEnabled(false); |
| 53 | for (Iterator it = view.getTargetEdges().iterator(); it.hasNext();) { |
| 54 | Edge incomingLink = (Edge) it.next(); |
| 55 | if (PalladioComponentModelVisualIDRegistry |
| 56 | .getVisualID(incomingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
| 57 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 58 | incomingLink.getSource().getElement(), null, |
| 59 | incomingLink.getTarget().getElement(), false); |
| 60 | cmd.add(new DestroyReferenceCommand(r)); |
| 61 | cmd.add(new DeleteCommand(getEditingDomain(), incomingLink)); |
| 62 | continue; |
| 63 | } |
| 64 | } |
| 65 | for (Iterator it = view.getSourceEdges().iterator(); it.hasNext();) { |
| 66 | Edge outgoingLink = (Edge) it.next(); |
| 67 | if (PalladioComponentModelVisualIDRegistry |
| 68 | .getVisualID(outgoingLink) == AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID) { |
| 69 | DestroyReferenceRequest r = new DestroyReferenceRequest( |
| 70 | outgoingLink.getSource().getElement(), null, |
| 71 | outgoingLink.getTarget().getElement(), false); |
| 72 | cmd.add(new DestroyReferenceCommand(r)); |
| 73 | cmd.add(new DeleteCommand(getEditingDomain(), outgoingLink)); |
| 74 | continue; |
| 75 | } |
| 76 | } |
| 77 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
| 78 | if (annotation == null) { |
| 79 | // there are indirectly referenced children, need extra commands: false |
| 80 | addDestroyChildNodesCommand(cmd); |
| 81 | addDestroyShortcutsCommand(cmd, view); |
| 82 | // delete host element |
| 83 | cmd.add(new DestroyElementCommand(req)); |
| 84 | } else { |
| 85 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
| 86 | } |
| 87 | return getGEFWrapper(cmd.reduce()); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @generated |
| 92 | */ |
| 93 | private void addDestroyChildNodesCommand(ICompositeCommand cmd) { |
| 94 | View view = (View) getHost().getModel(); |
| 95 | for (Iterator nit = view.getChildren().iterator(); nit.hasNext();) { |
| 96 | Node node = (Node) nit.next(); |
| 97 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(node)) { |
| 98 | case BranchActionBranchTransitionCompartment2EditPart.VISUAL_ID: |
| 99 | for (Iterator cit = node.getChildren().iterator(); cit |
| 100 | .hasNext();) { |
| 101 | Node cnode = (Node) cit.next(); |
| 102 | switch (PalladioComponentModelVisualIDRegistry |
| 103 | .getVisualID(cnode)) { |
| 104 | case ProbabilisticBranchTransitionEditPart.VISUAL_ID: |
| 105 | cmd.add(new DestroyElementCommand( |
| 106 | new DestroyElementRequest(getEditingDomain(), |
| 107 | cnode.getElement(), false))); // directlyOwned: true |
| 108 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
| 109 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
| 110 | break; |
| 111 | case GuardedBranchTransitionEditPart.VISUAL_ID: |
| 112 | cmd.add(new DestroyElementCommand( |
| 113 | new DestroyElementRequest(getEditingDomain(), |
| 114 | cnode.getElement(), false))); // directlyOwned: true |
| 115 | // don't need explicit deletion of cnode as parent's view deletion would clean child views as well |
| 116 | // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode)); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @generated |
| 127 | */ |
| 128 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
| 129 | Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) |
| 130 | : getCompleteCreateRelationshipCommand(req); |
| 131 | return command != null ? command : super |
| 132 | .getCreateRelationshipCommand(req); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @generated |
| 137 | */ |
| 138 | protected Command getStartCreateRelationshipCommand( |
| 139 | CreateRelationshipRequest req) { |
| 140 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
| 141 | .getElementType()) { |
| 142 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
| 143 | req, req.getSource(), req.getTarget())); |
| 144 | } |
| 145 | return null; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @generated |
| 150 | */ |
| 151 | protected Command getCompleteCreateRelationshipCommand( |
| 152 | CreateRelationshipRequest req) { |
| 153 | if (PalladioComponentModelElementTypes.AbstractActionSuccessor_AbstractAction_4001 == req |
| 154 | .getElementType()) { |
| 155 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionCreateCommand( |
| 156 | req, req.getSource(), req.getTarget())); |
| 157 | } |
| 158 | return null; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Returns command to reorient EReference based link. New link target or source |
| 163 | * should be the domain model element associated with this node. |
| 164 | * |
| 165 | * @generated |
| 166 | */ |
| 167 | protected Command getReorientReferenceRelationshipCommand( |
| 168 | ReorientReferenceRelationshipRequest req) { |
| 169 | switch (getVisualID(req)) { |
| 170 | case AbstractActionSuccessor_AbstractActionEditPart.VISUAL_ID: |
| 171 | return getGEFWrapper(new AbstractActionSuccessor_AbstractActionReorientCommand( |
| 172 | req)); |
| 173 | } |
| 174 | return super.getReorientReferenceRelationshipCommand(req); |
| 175 | } |
| 176 | |
| 177 | } |