1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.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.emf.ecore.resource.Resource; |
11 | import org.eclipse.gmf.runtime.common.core.command.CommandResult; |
12 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
14 | import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
17 | import org.eclipse.gmf.runtime.notation.View; |
18 | |
19 | import de.uka.ipd.sdq.pcm.core.entity.ComposedProvidingRequiringEntity; |
20 | import de.uka.ipd.sdq.pcm.core.entity.EntityFactory; |
21 | import de.uka.ipd.sdq.pcm.system.SystemFactory; |
22 | |
23 | /** |
24 | * @generated |
25 | */ |
26 | public class ComposedProvidingRequiringEntityCreateCommand extends |
27 | EditElementCommand { |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | public ComposedProvidingRequiringEntityCreateCommand( |
33 | CreateElementRequest req) { |
34 | super(req.getLabel(), null, req); |
35 | } |
36 | |
37 | /** |
38 | * FIXME: replace with setElementToEdit() |
39 | * @generated |
40 | */ |
41 | protected EObject getElementToEdit() { |
42 | EObject container = ((CreateElementRequest) getRequest()) |
43 | .getContainer(); |
44 | if (container instanceof View) { |
45 | container = ((View) container).getElement(); |
46 | } |
47 | return container; |
48 | } |
49 | |
50 | /** |
51 | * @generated |
52 | */ |
53 | public boolean canExecute() { |
54 | return true; |
55 | } |
56 | |
57 | /** |
58 | * @generated NOT |
59 | */ |
60 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
61 | IAdaptable info) throws ExecutionException { |
62 | // Uncomment to put "phantom" objects into the diagram file. |
63 | // org.eclipse.emf.ecore.resource.Resource resource = |
64 | // ((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).getContainer().eResource(); |
65 | // if (resource == null) { |
66 | // return null; |
67 | // } |
68 | Resource resource = getElementToEdit().eResource(); |
69 | ComposedProvidingRequiringEntity newElement = SystemFactory.eINSTANCE |
70 | .createSystem(); |
71 | |
72 | resource.getContents().add(newElement); |
73 | |
74 | doConfigure(newElement, monitor, info); |
75 | |
76 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
77 | return CommandResult.newOKCommandResult(newElement); |
78 | } |
79 | |
80 | /** |
81 | * @generated |
82 | */ |
83 | protected void doConfigure(ComposedProvidingRequiringEntity newElement, |
84 | IProgressMonitor monitor, IAdaptable info) |
85 | throws ExecutionException { |
86 | IElementType elementType = ((CreateElementRequest) getRequest()) |
87 | .getElementType(); |
88 | ConfigureRequest configureRequest = new ConfigureRequest( |
89 | getEditingDomain(), newElement, elementType); |
90 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
91 | .getClientContext()); |
92 | configureRequest.addParameters(getRequest().getParameters()); |
93 | ICommand configureCommand = elementType |
94 | .getEditCommand(configureRequest); |
95 | if (configureCommand != null && configureCommand.canExecute()) { |
96 | configureCommand.execute(monitor, info); |
97 | } |
98 | } |
99 | |
100 | } |