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