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.core.CoreFactory; |
19 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
20 | import de.uka.ipd.sdq.pcm.seff.AbstractInternalControlFlowAction; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class InfrastructureCallCreateCommand extends EditElementCommand { |
26 | |
27 | /**Default number of calls to use for a infrastructure call. |
28 | * @generated not |
29 | */ |
30 | private static final String DEFAULT_NUMBER_OF_CALLS = "1"; |
31 | |
32 | /** |
33 | * @generated |
34 | */ |
35 | public InfrastructureCallCreateCommand(CreateElementRequest req) { |
36 | super(req.getLabel(), null, req); |
37 | } |
38 | |
39 | /** |
40 | * FIXME: replace with setElementToEdit() |
41 | * @generated |
42 | */ |
43 | protected EObject getElementToEdit() { |
44 | EObject container = ((CreateElementRequest) getRequest()) |
45 | .getContainer(); |
46 | if (container instanceof View) { |
47 | container = ((View) container).getElement(); |
48 | } |
49 | return container; |
50 | } |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | public boolean canExecute() { |
56 | return true; |
57 | |
58 | } |
59 | |
60 | /** Additionally adds number of calls to the element. |
61 | * @generated not |
62 | */ |
63 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
64 | IAdaptable info) throws ExecutionException { |
65 | de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall newElement = de.uka.ipd.sdq.pcm.seff.seff_performance.Seff_performanceFactory.eINSTANCE |
66 | .createInfrastructureCall(); |
67 | // add empty random variable |
68 | PCMRandomVariable numberOfCalls = CoreFactory.eINSTANCE |
69 | .createPCMRandomVariable(); |
70 | numberOfCalls.setSpecification(DEFAULT_NUMBER_OF_CALLS); |
71 | newElement.setNumberOfCalls__InfrastructureCall(numberOfCalls); |
72 | |
73 | AbstractInternalControlFlowAction owner = (AbstractInternalControlFlowAction) getElementToEdit(); |
74 | owner.getInfrastructureCall__Action().add(newElement); |
75 | |
76 | doConfigure(newElement, monitor, info); |
77 | |
78 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
79 | return CommandResult.newOKCommandResult(newElement); |
80 | } |
81 | |
82 | /** |
83 | * @generated |
84 | */ |
85 | protected void doConfigure( |
86 | de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall newElement, |
87 | IProgressMonitor monitor, IAdaptable info) |
88 | throws ExecutionException { |
89 | IElementType elementType = ((CreateElementRequest) getRequest()) |
90 | .getElementType(); |
91 | ConfigureRequest configureRequest = new ConfigureRequest( |
92 | getEditingDomain(), newElement, elementType); |
93 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
94 | .getClientContext()); |
95 | configureRequest.addParameters(getRequest().getParameters()); |
96 | ICommand configureCommand = elementType |
97 | .getEditCommand(configureRequest); |
98 | if (configureCommand != null && configureCommand.canExecute()) { |
99 | configureCommand.execute(monitor, info); |
100 | } |
101 | } |
102 | |
103 | } |