1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.policies; |
5 | |
6 | import org.eclipse.emf.ecore.EAnnotation; |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.gef.commands.Command; |
9 | import org.eclipse.gef.commands.UnexecutableCommand; |
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.notation.View; |
16 | |
17 | import de.uka.ipd.sdq.pcm.core.composition.ComposedStructure; |
18 | import de.uka.ipd.sdq.pcm.core.composition.CompositionPackage; |
19 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.AssemblyConnectorTypeLinkCreateCommand; |
20 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.commands.ProvidedDelegationConnectorTypeLinkCreateCommand; |
21 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
22 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
23 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | public class ProvidedRoleItemSemanticEditPolicy extends |
29 | PalladioComponentModelBaseItemSemanticEditPolicy { |
30 | |
31 | /** |
32 | * @generated |
33 | */ |
34 | public ProvidedRoleItemSemanticEditPolicy() { |
35 | // TODO: model changed |
36 | // super(PalladioComponentModelElementTypes.ProvidedRole_3009); |
37 | super(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
38 | } |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | protected Command getDestroyElementCommand(DestroyElementRequest req) { |
44 | View view = (View) getHost().getModel(); |
45 | CompositeTransactionalCommand cmd = new CompositeTransactionalCommand( |
46 | getEditingDomain(), null); |
47 | cmd.setTransactionNestingEnabled(false); |
48 | EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$ |
49 | if (annotation == null) { |
50 | // there are indirectly referenced children, need extra commands: false |
51 | addDestroyShortcutsCommand(cmd, view); |
52 | // delete host element |
53 | cmd.add(new DestroyElementCommand(req)); |
54 | } else { |
55 | cmd.add(new DeleteCommand(getEditingDomain(), view)); |
56 | } |
57 | return getGEFWrapper(cmd.reduce()); |
58 | } |
59 | |
60 | // TODO: write javadoc and annotations |
61 | /** |
62 | * @generated not |
63 | */ |
64 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
65 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
66 | .getElementType()) { |
67 | return req.getTarget() == null ? null |
68 | : getCreateCompleteIncomingAssemblyConnector_4001Command(req); |
69 | } |
70 | if (PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006 == req |
71 | .getElementType()) { |
72 | return req.getTarget() == null ? null |
73 | : getCreateCompleteIncomingProvidedDelegationConnector_4003Command(req); |
74 | } |
75 | return super.getCreateRelationshipCommand(req); |
76 | } |
77 | |
78 | // TODO: write javadoc and annotations |
79 | /** |
80 | * @generated not |
81 | */ |
82 | protected Command getCreateCompleteIncomingAssemblyConnector_4001Command( |
83 | CreateRelationshipRequest req) { |
84 | EObject sourceEObject = req.getSource(); |
85 | EObject targetEObject = req.getTarget(); |
86 | if (false == sourceEObject instanceof OperationRequiredRole |
87 | || false == targetEObject instanceof OperationProvidedRole) { |
88 | return UnexecutableCommand.INSTANCE; |
89 | } |
90 | OperationRequiredRole source = (OperationRequiredRole) sourceEObject; |
91 | OperationProvidedRole target = (OperationProvidedRole) targetEObject; |
92 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
93 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
94 | req.getElementType()); |
95 | if (container == null) { |
96 | return UnexecutableCommand.INSTANCE; |
97 | } |
98 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
99 | .canCreateAssemblyConnector_4004(container, source, target)) { |
100 | return UnexecutableCommand.INSTANCE; |
101 | } |
102 | if (req.getContainmentFeature() == null) { |
103 | req |
104 | .setContainmentFeature(CompositionPackage.eINSTANCE |
105 | .getComposedStructure_Connectors__ComposedStructure()); |
106 | } |
107 | req.setParameter("PROV_CHILD_CONTEXT", ((View) getHost().getParent() |
108 | .getModel()).getElement()); |
109 | return getGEFWrapper(new AssemblyConnectorTypeLinkCreateCommand(req, |
110 | container, source, target)); |
111 | } |
112 | |
113 | // TODO: write javadoc and annotations |
114 | /** |
115 | * @generated not |
116 | */ |
117 | protected Command getCreateCompleteIncomingProvidedDelegationConnector_4003Command( |
118 | CreateRelationshipRequest req) { |
119 | EObject sourceEObject = req.getSource(); |
120 | EObject targetEObject = req.getTarget(); |
121 | if (false == sourceEObject instanceof OperationProvidedRole |
122 | || false == targetEObject instanceof OperationProvidedRole) { |
123 | return UnexecutableCommand.INSTANCE; |
124 | } |
125 | OperationProvidedRole source = (OperationProvidedRole) sourceEObject; |
126 | OperationProvidedRole target = (OperationProvidedRole) targetEObject; |
127 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
128 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
129 | req.getElementType()); |
130 | if (container == null) { |
131 | return UnexecutableCommand.INSTANCE; |
132 | } |
133 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
134 | .canCreateProvidedDelegationConnector_4006(container, source, |
135 | target)) { |
136 | return UnexecutableCommand.INSTANCE; |
137 | } |
138 | if (req.getContainmentFeature() == null) { |
139 | req |
140 | .setContainmentFeature(CompositionPackage.eINSTANCE |
141 | .getComposedStructure_Connectors__ComposedStructure()); |
142 | } |
143 | req.setParameter("CHILD_CONTEXT", ((View) getHost().getParent() |
144 | .getModel()).getElement()); |
145 | return getGEFWrapper(new ProvidedDelegationConnectorTypeLinkCreateCommand( |
146 | req, container, source, target)); |
147 | } |
148 | |
149 | } |