1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.edit.commands; |
5 | |
6 | import org.eclipse.core.commands.ExecutionException; |
7 | import org.eclipse.core.runtime.IAdaptable; |
8 | import org.eclipse.core.runtime.IProgressMonitor; |
9 | import org.eclipse.emf.ecore.EObject; |
10 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest; |
14 | |
15 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
16 | import de.uka.ipd.sdq.pcm.repository.CompleteComponentType; |
17 | import de.uka.ipd.sdq.pcm.repository.ImplementationComponentType; |
18 | |
19 | /** |
20 | * @generated |
21 | */ |
22 | public class ImplementationComponentTypeParentCompleteComponentTypesReorientCommand |
23 | extends EditElementCommand { |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | private final int reorientDirection; |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | private final EObject referenceOwner; |
34 | |
35 | /** |
36 | * @generated |
37 | */ |
38 | private final EObject oldEnd; |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | private final EObject newEnd; |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | public ImplementationComponentTypeParentCompleteComponentTypesReorientCommand( |
49 | ReorientReferenceRelationshipRequest request) { |
50 | super(request.getLabel(), null, request); |
51 | reorientDirection = request.getDirection(); |
52 | referenceOwner = request.getReferenceOwner(); |
53 | oldEnd = request.getOldRelationshipEnd(); |
54 | newEnd = request.getNewRelationshipEnd(); |
55 | } |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | public boolean canExecute() { |
61 | if (false == referenceOwner instanceof ImplementationComponentType) { |
62 | return false; |
63 | } |
64 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
65 | return canReorientSource(); |
66 | } |
67 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
68 | return canReorientTarget(); |
69 | } |
70 | return false; |
71 | } |
72 | |
73 | /** |
74 | * @generated |
75 | */ |
76 | protected boolean canReorientSource() { |
77 | if (!(oldEnd instanceof CompleteComponentType && newEnd instanceof ImplementationComponentType)) { |
78 | return false; |
79 | } |
80 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
81 | .canExistImplementationComponentTypeParentCompleteComponentTypes_4103( |
82 | getNewSource(), getOldTarget()); |
83 | } |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | protected boolean canReorientTarget() { |
89 | if (!(oldEnd instanceof CompleteComponentType && newEnd instanceof CompleteComponentType)) { |
90 | return false; |
91 | } |
92 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
93 | .canExistImplementationComponentTypeParentCompleteComponentTypes_4103( |
94 | getOldSource(), getNewTarget()); |
95 | } |
96 | |
97 | /** |
98 | * @generated |
99 | */ |
100 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
101 | IAdaptable info) throws ExecutionException { |
102 | if (!canExecute()) { |
103 | throw new ExecutionException( |
104 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
105 | } |
106 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
107 | return reorientSource(); |
108 | } |
109 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
110 | return reorientTarget(); |
111 | } |
112 | throw new IllegalStateException(); |
113 | } |
114 | |
115 | /** |
116 | * @generated |
117 | */ |
118 | protected CommandResult reorientSource() throws ExecutionException { |
119 | getOldSource().getParentCompleteComponentTypes().remove(getOldTarget()); |
120 | getNewSource().getParentCompleteComponentTypes().add(getOldTarget()); |
121 | return CommandResult.newOKCommandResult(referenceOwner); |
122 | } |
123 | |
124 | /** |
125 | * @generated |
126 | */ |
127 | protected CommandResult reorientTarget() throws ExecutionException { |
128 | getOldSource().getParentCompleteComponentTypes().remove(getOldTarget()); |
129 | getOldSource().getParentCompleteComponentTypes().add(getNewTarget()); |
130 | return CommandResult.newOKCommandResult(referenceOwner); |
131 | } |
132 | |
133 | /** |
134 | * @generated |
135 | */ |
136 | protected ImplementationComponentType getOldSource() { |
137 | return (ImplementationComponentType) referenceOwner; |
138 | } |
139 | |
140 | /** |
141 | * @generated |
142 | */ |
143 | protected ImplementationComponentType getNewSource() { |
144 | return (ImplementationComponentType) newEnd; |
145 | } |
146 | |
147 | /** |
148 | * @generated |
149 | */ |
150 | protected CompleteComponentType getOldTarget() { |
151 | return (CompleteComponentType) oldEnd; |
152 | } |
153 | |
154 | /** |
155 | * @generated |
156 | */ |
157 | protected CompleteComponentType getNewTarget() { |
158 | return (CompleteComponentType) newEnd; |
159 | } |
160 | } |