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.AbstractInternalControlFlowAction; |
19 | |
20 | /** |
21 | * @generated |
22 | */ |
23 | public class ParametricResourceDemandCreateCommand extends EditElementCommand { |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | public ParametricResourceDemandCreateCommand(CreateElementRequest req) { |
29 | super(req.getLabel(), null, req); |
30 | } |
31 | |
32 | /** |
33 | * @generated |
34 | */ |
35 | protected EObject getElementToEdit() { |
36 | EObject container = ((CreateElementRequest) getRequest()) |
37 | .getContainer(); |
38 | if (container instanceof View) { |
39 | container = ((View) container).getElement(); |
40 | } |
41 | return container; |
42 | } |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | public boolean canExecute() { |
48 | return true; |
49 | |
50 | } |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
56 | IAdaptable info) throws ExecutionException { |
57 | de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand newElement = de.uka.ipd.sdq.pcm.seff.seff_performance.Seff_performanceFactory.eINSTANCE |
58 | .createParametricResourceDemand(); |
59 | |
60 | AbstractInternalControlFlowAction owner = (AbstractInternalControlFlowAction) getElementToEdit(); |
61 | owner.getResourceDemand_Action().add(newElement); |
62 | |
63 | doConfigure(newElement, monitor, info); |
64 | |
65 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
66 | return CommandResult.newOKCommandResult(newElement); |
67 | } |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | protected void doConfigure( |
73 | de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand newElement, |
74 | IProgressMonitor monitor, IAdaptable info) |
75 | throws ExecutionException { |
76 | IElementType elementType = ((CreateElementRequest) getRequest()) |
77 | .getElementType(); |
78 | ConfigureRequest configureRequest = new ConfigureRequest( |
79 | getEditingDomain(), newElement, elementType); |
80 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
81 | .getClientContext()); |
82 | configureRequest.addParameters(getRequest().getParameters()); |
83 | ICommand configureCommand = elementType |
84 | .getEditCommand(configureRequest); |
85 | if (configureCommand != null && configureCommand.canExecute()) { |
86 | configureCommand.execute(monitor, info); |
87 | } |
88 | } |
89 | |
90 | } |