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 | |
16 | import de.uka.ipd.sdq.pcm.repository.EventType; |
17 | import de.uka.ipd.sdq.pcm.repository.SourceRole; |
18 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
19 | |
20 | /** |
21 | * Command to Configure an emit event action with the appropriate event type and |
22 | * source role. |
23 | * |
24 | * This configuration command takes use of the basic commands provided by the |
25 | * EMF environment like setValueCommand() etc. |
26 | * |
27 | * @author Benjamin Klatt |
28 | */ |
29 | public class EmitEventActionConfigureCommand extends ConfigureElementCommand { |
30 | |
31 | /** The request send for the configuration */ |
32 | private ConfigureRequest request = null; |
33 | |
34 | /** The event type to be emitted by the EmitEventAction */ |
35 | private EventType eventType = null; |
36 | |
37 | /** The source role to be triggered by the emit event action */ |
38 | private SourceRole sourceRole = null; |
39 | |
40 | /** |
41 | * Constructor to set the required configuration. |
42 | * |
43 | * @param request |
44 | * The request calling this command. |
45 | * @param eventType |
46 | * The EventType the action should be able to emit. |
47 | * @param sourceRole |
48 | * The source role to be triggered by the action. |
49 | */ |
50 | public EmitEventActionConfigureCommand(ConfigureRequest request, |
51 | EventType eventType, SourceRole sourceRole) { |
52 | super(request); |
53 | this.request = request; |
54 | this.eventType = eventType; |
55 | this.sourceRole = sourceRole; |
56 | } |
57 | |
58 | /** |
59 | * Execute the command and return the result of the configuration process. |
60 | * |
61 | * @param monitor |
62 | * The monitor to report the progress to. |
63 | * @param info |
64 | * The adaptable information object of the environment. |
65 | * @return The result of the configuration process. |
66 | * |
67 | * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, |
68 | * org.eclipse.core.runtime.IAdaptable) |
69 | */ |
70 | @Override |
71 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
72 | IAdaptable info) throws ExecutionException { |
73 | CommandResult commandResult = setEventTypeEmitEventAction(monitor, info); |
74 | if (!isOK(commandResult)) { |
75 | return CommandResult |
76 | .newErrorCommandResult("Set EventType for the EmitEventAction failed!"); |
77 | } |
78 | commandResult = setSourceRoleEmitEventAction(monitor, info); |
79 | if (!isOK(commandResult)) { |
80 | return CommandResult |
81 | .newErrorCommandResult("Set SourceRole for the EmitEventAction failed!"); |
82 | } |
83 | return CommandResult.newOKCommandResult(); |
84 | } |
85 | |
86 | /** |
87 | * Set the EventType in the EmitEventAction. |
88 | * |
89 | * @param monitor |
90 | * The monitor to report the progress to. |
91 | * @param info |
92 | * The adaptable information object of the environment. |
93 | * @return The result of this processing step. |
94 | * |
95 | * @throws ExecutionException |
96 | * indicating any problems during the EmitEventAction |
97 | * configuration. |
98 | */ |
99 | private CommandResult setEventTypeEmitEventAction(IProgressMonitor monitor, |
100 | IAdaptable info) throws ExecutionException { |
101 | |
102 | ICommand cmd = new SetValueCommand(new SetRequest(request |
103 | .getElementToConfigure(), SeffPackage.eINSTANCE |
104 | .getEmitEventAction_EventType__EmitEventAction(), eventType)); |
105 | |
106 | cmd.execute(monitor, info); |
107 | |
108 | return cmd.getCommandResult(); |
109 | } |
110 | |
111 | /** |
112 | * Set the SourceRole of the EmitEventAction. |
113 | * |
114 | * @param monitor |
115 | * The monitor to report the progress to. |
116 | * @param info |
117 | * The adaptable information object of the environment. |
118 | * @return The result of this processing step. |
119 | * |
120 | * @throws ExecutionException |
121 | * indicating any problems during the EmitEventAction |
122 | * configuration. |
123 | */ |
124 | private CommandResult setSourceRoleEmitEventAction( |
125 | IProgressMonitor monitor, IAdaptable info) |
126 | throws ExecutionException { |
127 | |
128 | ICommand cmd = new SetValueCommand(new SetRequest(request |
129 | .getElementToConfigure(), SeffPackage.eINSTANCE |
130 | .getEmitEventAction_SourceRole__EmitEventAction(), sourceRole)); |
131 | |
132 | cmd.execute(monitor, info); |
133 | |
134 | return cmd.getCommandResult(); |
135 | } |
136 | } |