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 | /** |
19 | * @generated |
20 | */ |
21 | public class RecoveryActionBehaviourCreateCommand extends EditElementCommand { |
22 | |
23 | /** |
24 | * @generated |
25 | */ |
26 | public RecoveryActionBehaviourCreateCommand(CreateElementRequest req) { |
27 | super(req.getLabel(), null, req); |
28 | } |
29 | |
30 | /** |
31 | * FIXME: replace with setElementToEdit() |
32 | * @generated |
33 | */ |
34 | protected EObject getElementToEdit() { |
35 | EObject container = ((CreateElementRequest) getRequest()) |
36 | .getContainer(); |
37 | if (container instanceof View) { |
38 | container = ((View) container).getElement(); |
39 | } |
40 | return container; |
41 | } |
42 | |
43 | /** |
44 | * @generated |
45 | */ |
46 | public boolean canExecute() { |
47 | return true; |
48 | |
49 | } |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
55 | IAdaptable info) throws ExecutionException { |
56 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour newElement = de.uka.ipd.sdq.pcm.seff.seff_reliability.Seff_reliabilityFactory.eINSTANCE |
57 | .createRecoveryActionBehaviour(); |
58 | |
59 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryAction owner = (de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryAction) getElementToEdit(); |
60 | owner.getRecoveryActionBehaviours__RecoveryAction().add(newElement); |
61 | |
62 | doConfigure(newElement, monitor, info); |
63 | |
64 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
65 | return CommandResult.newOKCommandResult(newElement); |
66 | } |
67 | |
68 | /** |
69 | * @generated |
70 | */ |
71 | protected void doConfigure( |
72 | de.uka.ipd.sdq.pcm.seff.seff_reliability.RecoveryActionBehaviour newElement, |
73 | IProgressMonitor monitor, IAdaptable info) |
74 | 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 | } |