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