1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
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.gmf.runtime.common.core.command.CommandResult; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
11 | import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
15 | import org.eclipse.jface.dialogs.Dialog; |
16 | import org.eclipse.ui.PlatformUI; |
17 | |
18 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
19 | import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog; |
20 | import de.uka.ipd.sdq.pcm.repository.InfrastructureRequiredRole; |
21 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
22 | import de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall; |
23 | import de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand; |
24 | import de.uka.ipd.sdq.pcm.seff.seff_performance.Seff_performancePackage; |
25 | import de.uka.ipd.sdq.stoex.StoexPackage; |
26 | import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum; |
27 | |
28 | /**Configures a given {@link InfrastructureCall} instance to use given a given signature and role. |
29 | * |
30 | * @author groenda |
31 | */ |
32 | public class InfrastructureCallConfigureCommand extends ConfigureElementCommand { |
33 | |
34 | /** Configuration request. */ |
35 | private ConfigureRequest request = null; |
36 | /** Infrastructure signature. */ |
37 | private InfrastructureSignature signature = null; |
38 | /** Infrastructure required role.*/ |
39 | private InfrastructureRequiredRole requiredRole = null; |
40 | /** The specification string for the number of calls. */ |
41 | private String numberOfCalls; |
42 | |
43 | /**Creates a new configuration command for an {@link InfrastructureCall}. |
44 | * @param request Configuration request. |
45 | * @param signature The target signature. |
46 | * @param requiredRole The target required role. |
47 | * @param numberOfCalls The number of calls to the target. |
48 | */ |
49 | public InfrastructureCallConfigureCommand(ConfigureRequest request, |
50 | InfrastructureSignature signature, InfrastructureRequiredRole requiredRole, String numberOfCalls) { |
51 | super(request); |
52 | this.request = request; |
53 | this.signature = signature; |
54 | this.requiredRole = requiredRole; |
55 | this.numberOfCalls = numberOfCalls; |
56 | } |
57 | |
58 | /* (non-Javadoc) |
59 | * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
60 | */ |
61 | @Override |
62 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
63 | IAdaptable info) throws ExecutionException { |
64 | CommandResult commandResult = setInfrastructureSignatureInfrastructureCall(monitor, |
65 | info); |
66 | if (!isOK(commandResult)) { |
67 | return CommandResult |
68 | .newErrorCommandResult("Set InfrastructureSignature for the InfrastructureCall failed!"); |
69 | } |
70 | commandResult = setInfrastructureRequiredRoleInfrastructureCall(monitor, info); |
71 | if (!isOK(commandResult)) { |
72 | return CommandResult |
73 | .newErrorCommandResult("Set InfrastructureRequiredRole for the InfrastructureCall failed!"); |
74 | } |
75 | commandResult = setNumberOfCallsInfrastructureCall(monitor, info); |
76 | if (!isOK(commandResult)) { |
77 | return CommandResult.newErrorCommandResult("Set NumberOfCalls for the InfrastructureCall failed."); |
78 | } |
79 | return CommandResult.newOKCommandResult(); |
80 | } |
81 | |
82 | |
83 | /**Create the command to modify the infrastructure signature for an infrastructure call. |
84 | * @param monitor Progress monitor. |
85 | * @param info Adaptation information. |
86 | * @return Command. |
87 | * @throws ExecutionException On error. |
88 | */ |
89 | private CommandResult setInfrastructureSignatureInfrastructureCall( |
90 | IProgressMonitor monitor, IAdaptable info) |
91 | throws ExecutionException { |
92 | |
93 | if (!(request.getElementToConfigure() instanceof InfrastructureCall)) { |
94 | throw new ExecutionException("The provided element which should be configured was not of type InfrastructureCall."); |
95 | } |
96 | |
97 | ICommand cmd = new SetValueCommand(new SetRequest(request |
98 | .getElementToConfigure(), |
99 | Seff_performancePackage.eINSTANCE.getInfrastructureCall_Signature__InfrastructureCall(), |
100 | signature)); |
101 | |
102 | cmd.execute(monitor, info); |
103 | |
104 | return cmd.getCommandResult(); |
105 | } |
106 | |
107 | /**Create the command to modify the required role for an infrastructure call. |
108 | * @param monitor Progress monitor. |
109 | * @param info Adaptation information. |
110 | * @return Command. |
111 | * @throws ExecutionException On error. |
112 | */ |
113 | private CommandResult setInfrastructureRequiredRoleInfrastructureCall( |
114 | IProgressMonitor monitor, IAdaptable info) |
115 | throws ExecutionException { |
116 | |
117 | if (!(request.getElementToConfigure() instanceof InfrastructureCall)) { |
118 | throw new ExecutionException("The provided element which should be configured was not of type InfrastructureCall."); |
119 | } |
120 | ICommand cmd = new SetValueCommand(new SetRequest(request |
121 | .getElementToConfigure(), Seff_performancePackage.eINSTANCE.getInfrastructureCall_RequiredRole__InfrastructureCall(), |
122 | requiredRole)); |
123 | |
124 | cmd.execute(monitor, info); |
125 | |
126 | return cmd.getCommandResult(); |
127 | } |
128 | |
129 | /**Create the command to modify the number of calls for an infrastructure call. |
130 | * @param monitor Progress monitor. |
131 | * @param info Adaptation information. |
132 | * @return Command. |
133 | * @throws ExecutionException On error. |
134 | */ |
135 | private CommandResult setNumberOfCallsInfrastructureCall( |
136 | IProgressMonitor monitor, IAdaptable info) |
137 | throws ExecutionException { |
138 | |
139 | if (!(request.getElementToConfigure() instanceof InfrastructureCall)) { |
140 | throw new ExecutionException("The provided element which should be configured was not of type InfrastructureCall."); |
141 | } |
142 | InfrastructureCall call = (InfrastructureCall) request.getElementToConfigure(); |
143 | ICommand cmd = new SetValueCommand( |
144 | new SetRequest( |
145 | call.getNumberOfCalls__InfrastructureCall(), |
146 | StoexPackage.eINSTANCE.getRandomVariable_Specification(), |
147 | numberOfCalls)); |
148 | cmd.execute(monitor, info); |
149 | return cmd.getCommandResult(); |
150 | } |
151 | |
152 | } |