1 | /* |
2 | *Copyright 2006 SDQ Research Group, University of Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.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.common.core.command.ICommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
13 | import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
16 | import org.eclipse.gmf.runtime.notation.View; |
17 | |
18 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingBehaviour; |
19 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
20 | import de.uka.ipd.sdq.pcm.seff.StopAction; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class StopActionCreateCommand extends EditElementCommand { |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | public StopActionCreateCommand(CreateElementRequest req) { |
31 | super(req.getLabel(), null, req); |
32 | } |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | protected EObject getElementToEdit() { |
38 | EObject container = ((CreateElementRequest) getRequest()) |
39 | .getContainer(); |
40 | if (container instanceof View) { |
41 | container = ((View) container).getElement(); |
42 | } |
43 | return container; |
44 | } |
45 | |
46 | /** |
47 | * @generated |
48 | */ |
49 | public boolean canExecute() { |
50 | return true; |
51 | |
52 | } |
53 | |
54 | /** |
55 | * @generated |
56 | */ |
57 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
58 | IAdaptable info) throws ExecutionException { |
59 | StopAction newElement = SeffFactory.eINSTANCE.createStopAction(); |
60 | |
61 | ResourceDemandingBehaviour owner = (ResourceDemandingBehaviour) getElementToEdit(); |
62 | owner.getSteps_Behaviour().add(newElement); |
63 | |
64 | doConfigure(newElement, monitor, info); |
65 | |
66 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
67 | return CommandResult.newOKCommandResult(newElement); |
68 | } |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | protected void doConfigure(StopAction newElement, IProgressMonitor monitor, |
74 | IAdaptable info) throws ExecutionException { |
75 | IElementType elementType = ((CreateElementRequest) getRequest()) |
76 | .getElementType(); |
77 | ConfigureRequest configureRequest = new ConfigureRequest( |
78 | getEditingDomain(), newElement, elementType); |
79 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
80 | .getClientContext()); |
81 | configureRequest.addParameters(getRequest().getParameters()); |
82 | ICommand configureCommand = elementType |
83 | .getEditCommand(configureRequest); |
84 | if (configureCommand != null && configureCommand.canExecute()) { |
85 | configureCommand.execute(monitor, info); |
86 | } |
87 | } |
88 | |
89 | } |