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.providers.PalladioComponentModelElementTypes; |
20 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class RequiredRoleItemSemanticEditPolicy extends |
26 | PalladioComponentModelBaseItemSemanticEditPolicy { |
27 | |
28 | /** |
29 | * @generated |
30 | */ |
31 | public RequiredRoleItemSemanticEditPolicy() { |
32 | // TODO: Model changed |
33 | // super(PalladioComponentModelElementTypes.RequiredRole_3010); |
34 | super(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
35 | |
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 | 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 | // TODO: write javadoc and annotations |
59 | /** |
60 | * @generated not |
61 | */ |
62 | protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) { |
63 | if (PalladioComponentModelElementTypes.AssemblyConnector_4004 == req |
64 | .getElementType()) { |
65 | return req.getTarget() == null ? getCreateStartOutgoingAssemblyConnector_4001Command(req) |
66 | : null; |
67 | } |
68 | if (PalladioComponentModelElementTypes.RequiredDelegationConnector_4005 == req |
69 | .getElementType()) { |
70 | return req.getTarget() == null ? getCreateStartOutgoingRequiredDelegationConnector_4002Command(req) |
71 | : null; |
72 | } |
73 | return super.getCreateRelationshipCommand(req); |
74 | } |
75 | |
76 | // TODO: write javadoc and annotations |
77 | /** |
78 | * @generated not |
79 | */ |
80 | protected Command getCreateStartOutgoingAssemblyConnector_4001Command( |
81 | CreateRelationshipRequest req) { |
82 | EObject sourceEObject = req.getSource(); |
83 | if (false == sourceEObject instanceof OperationRequiredRole) { |
84 | return UnexecutableCommand.INSTANCE; |
85 | } |
86 | OperationRequiredRole source = (OperationRequiredRole) sourceEObject; |
87 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
88 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
89 | req.getElementType()); |
90 | if (container == null) { |
91 | return UnexecutableCommand.INSTANCE; |
92 | } |
93 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
94 | .canCreateAssemblyConnector_4004(container, source, null)) { |
95 | return UnexecutableCommand.INSTANCE; |
96 | } |
97 | req.setParameter("REQ_CHILD_CONTEXT", ((View) getHost().getParent() |
98 | .getModel()).getElement()); |
99 | return new Command() { |
100 | }; |
101 | } |
102 | |
103 | // TODO: write javadoc and annotations |
104 | /** |
105 | * @generated not |
106 | */ |
107 | protected Command getCreateStartOutgoingRequiredDelegationConnector_4002Command( |
108 | CreateRelationshipRequest req) { |
109 | EObject sourceEObject = req.getSource(); |
110 | if (false == sourceEObject instanceof OperationRequiredRole) { |
111 | return UnexecutableCommand.INSTANCE; |
112 | } |
113 | OperationRequiredRole source = (OperationRequiredRole) sourceEObject; |
114 | ComposedStructure container = (ComposedStructure) getRelationshipContainer( |
115 | source, CompositionPackage.eINSTANCE.getComposedStructure(), |
116 | req.getElementType()); |
117 | if (container == null) { |
118 | return UnexecutableCommand.INSTANCE; |
119 | } |
120 | req.setParameter("CHILD_CONTEXT", ((View) getHost().getParent() |
121 | .getModel()).getElement()); |
122 | if (!PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
123 | .canCreateRequiredDelegationConnector_4005(container, source, |
124 | null)) { |
125 | return UnexecutableCommand.INSTANCE; |
126 | } |
127 | return new Command() { |
128 | }; |
129 | } |
130 | |
131 | } |