1 | /* |
2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.resource.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.resource.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
16 | import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource; |
17 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
18 | |
19 | /** |
20 | * @generated |
21 | */ |
22 | public class LinkingResourceConnectedResourceContainers_LinkingResourceReorientCommand |
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 LinkingResourceConnectedResourceContainers_LinkingResourceReorientCommand( |
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 LinkingResource) { |
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 ResourceContainer && newEnd instanceof LinkingResource)) { |
78 | return false; |
79 | } |
80 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
81 | .canExistLinkingResourceConnectedResourceContainers_LinkingResource_4002( |
82 | getNewSource(), getOldTarget()); |
83 | } |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | protected boolean canReorientTarget() { |
89 | if (!(oldEnd instanceof ResourceContainer && newEnd instanceof ResourceContainer)) { |
90 | return false; |
91 | } |
92 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
93 | .canExistLinkingResourceConnectedResourceContainers_LinkingResource_4002( |
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().getConnectedResourceContainers_LinkingResource().remove( |
120 | getOldTarget()); |
121 | getNewSource().getConnectedResourceContainers_LinkingResource().add( |
122 | getOldTarget()); |
123 | return CommandResult.newOKCommandResult(referenceOwner); |
124 | } |
125 | |
126 | /** |
127 | * @generated |
128 | */ |
129 | protected CommandResult reorientTarget() throws ExecutionException { |
130 | getOldSource().getConnectedResourceContainers_LinkingResource().remove( |
131 | getOldTarget()); |
132 | getOldSource().getConnectedResourceContainers_LinkingResource().add( |
133 | getNewTarget()); |
134 | return CommandResult.newOKCommandResult(referenceOwner); |
135 | } |
136 | |
137 | /** |
138 | * @generated |
139 | */ |
140 | protected LinkingResource getOldSource() { |
141 | return (LinkingResource) referenceOwner; |
142 | } |
143 | |
144 | /** |
145 | * @generated |
146 | */ |
147 | protected LinkingResource getNewSource() { |
148 | return (LinkingResource) newEnd; |
149 | } |
150 | |
151 | /** |
152 | * @generated |
153 | */ |
154 | protected ResourceContainer getOldTarget() { |
155 | return (ResourceContainer) oldEnd; |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected ResourceContainer getNewTarget() { |
162 | return (ResourceContainer) newEnd; |
163 | } |
164 | } |