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