1 | /* |
2 | *Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.commands; |
5 | |
6 | import org.eclipse.emf.ecore.EClass; |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.EReference; |
9 | |
10 | import org.eclipse.emf.ecore.resource.Resource; |
11 | |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
13 | |
14 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
15 | |
16 | import org.eclipse.gmf.runtime.notation.View; |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | public class ResourceContainerCreateCommand extends CreateElementCommand { |
22 | |
23 | /** |
24 | * @generated |
25 | */ |
26 | public ResourceContainerCreateCommand(CreateElementRequest req) { |
27 | super(req); |
28 | } |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | protected EObject getElementToEdit() { |
34 | EObject container = ((CreateElementRequest) getRequest()) |
35 | .getContainer(); |
36 | if (container instanceof View) { |
37 | container = ((View) container).getElement(); |
38 | } |
39 | return container; |
40 | } |
41 | |
42 | /** |
43 | * @generated |
44 | */ |
45 | public boolean canExecute() { |
46 | if (getEClass() != null) { |
47 | return getEClass().isSuperTypeOf(getEClassToEdit()); |
48 | } |
49 | return true; |
50 | } |
51 | |
52 | /** |
53 | * @generated |
54 | */ |
55 | protected EReference getContainmentFeature() { |
56 | return null; |
57 | } |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | protected EObject doDefaultElementCreation() { |
63 | // Uncomment to put "phantom" objects into the diagram file. |
64 | // org.eclipse.emf.ecore.resource.Resource resource = |
65 | // ((org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) getRequest()).getContainer().eResource(); |
66 | // if (resource == null) { |
67 | // return null; |
68 | // } |
69 | Resource resource = getElementToEdit().eResource(); |
70 | EClass eClass = getElementType().getEClass(); |
71 | EObject newElement = eClass.getEPackage().getEFactoryInstance().create( |
72 | eClass); |
73 | resource.getContents().add(newElement); |
74 | return newElement; |
75 | } |
76 | |
77 | } |