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.ReorientRelationshipRequest; |
13 | |
14 | import de.uka.ipd.sdq.pcm.core.entity.InterfaceProvidingEntity; |
15 | import de.uka.ipd.sdq.pcm.gmf.repository.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
16 | import de.uka.ipd.sdq.pcm.repository.InfrastructureInterface; |
17 | import de.uka.ipd.sdq.pcm.repository.InfrastructureProvidedRole; |
18 | |
19 | /** |
20 | * @generated |
21 | */ |
22 | public class InfrastructureProvidedRoleReorientCommand extends |
23 | EditElementCommand { |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | private final int reorientDirection; |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | private final EObject oldEnd; |
34 | |
35 | /** |
36 | * @generated |
37 | */ |
38 | private final EObject newEnd; |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | public InfrastructureProvidedRoleReorientCommand( |
44 | ReorientRelationshipRequest request) { |
45 | super(request.getLabel(), request.getRelationship(), request); |
46 | reorientDirection = request.getDirection(); |
47 | oldEnd = request.getOldRelationshipEnd(); |
48 | newEnd = request.getNewRelationshipEnd(); |
49 | } |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | public boolean canExecute() { |
55 | if (false == getElementToEdit() instanceof InfrastructureProvidedRole) { |
56 | return false; |
57 | } |
58 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
59 | return canReorientSource(); |
60 | } |
61 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
62 | return canReorientTarget(); |
63 | } |
64 | return false; |
65 | } |
66 | |
67 | /** |
68 | * @generated |
69 | */ |
70 | protected boolean canReorientSource() { |
71 | if (!(oldEnd instanceof InterfaceProvidingEntity && newEnd instanceof InterfaceProvidingEntity)) { |
72 | return false; |
73 | } |
74 | InfrastructureInterface target = getLink() |
75 | .getProvidedInterface__InfrastructureProvidedRole(); |
76 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
77 | .canExistInfrastructureProvidedRole_4111(getNewSource(), target); |
78 | } |
79 | |
80 | /** |
81 | * @generated |
82 | */ |
83 | protected boolean canReorientTarget() { |
84 | if (!(oldEnd instanceof InfrastructureInterface && newEnd instanceof InfrastructureInterface)) { |
85 | return false; |
86 | } |
87 | if (!(getLink().eContainer() instanceof InterfaceProvidingEntity)) { |
88 | return false; |
89 | } |
90 | InterfaceProvidingEntity source = (InterfaceProvidingEntity) getLink() |
91 | .eContainer(); |
92 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
93 | .canExistInfrastructureProvidedRole_4111(source, getNewTarget()); |
94 | } |
95 | |
96 | /** |
97 | * @generated |
98 | */ |
99 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
100 | IAdaptable info) throws ExecutionException { |
101 | if (!canExecute()) { |
102 | throw new ExecutionException( |
103 | "Invalid arguments in reorient link command"); //$NON-NLS-1$ |
104 | } |
105 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) { |
106 | return reorientSource(); |
107 | } |
108 | if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) { |
109 | return reorientTarget(); |
110 | } |
111 | throw new IllegalStateException(); |
112 | } |
113 | |
114 | /** |
115 | * @generated |
116 | */ |
117 | protected CommandResult reorientSource() throws ExecutionException { |
118 | getOldSource().getProvidedRoles_InterfaceProvidingEntity().remove( |
119 | getLink()); |
120 | getNewSource().getProvidedRoles_InterfaceProvidingEntity().add( |
121 | getLink()); |
122 | return CommandResult.newOKCommandResult(getLink()); |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected CommandResult reorientTarget() throws ExecutionException { |
129 | getLink().setProvidedInterface__InfrastructureProvidedRole( |
130 | getNewTarget()); |
131 | return CommandResult.newOKCommandResult(getLink()); |
132 | } |
133 | |
134 | /** |
135 | * @generated |
136 | */ |
137 | protected InfrastructureProvidedRole getLink() { |
138 | return (InfrastructureProvidedRole) getElementToEdit(); |
139 | } |
140 | |
141 | /** |
142 | * @generated |
143 | */ |
144 | protected InterfaceProvidingEntity getOldSource() { |
145 | return (InterfaceProvidingEntity) oldEnd; |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected InterfaceProvidingEntity getNewSource() { |
152 | return (InterfaceProvidingEntity) newEnd; |
153 | } |
154 | |
155 | /** |
156 | * @generated |
157 | */ |
158 | protected InfrastructureInterface getOldTarget() { |
159 | return (InfrastructureInterface) oldEnd; |
160 | } |
161 | |
162 | /** |
163 | * @generated |
164 | */ |
165 | protected InfrastructureInterface getNewTarget() { |
166 | return (InfrastructureInterface) newEnd; |
167 | } |
168 | } |