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.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.core.entity.InterfaceRequiringEntity; |
19 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
20 | import de.uka.ipd.sdq.pcm.repository.RequiredRole; |
21 | |
22 | // TODO: decide whether this file is obsolete |
23 | |
24 | /** |
25 | * @generated |
26 | */ |
27 | public class RequiredRoleCreateCommand extends EditElementCommand { |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | public RequiredRoleCreateCommand(CreateElementRequest req) { |
33 | super(req.getLabel(), null, req); |
34 | } |
35 | |
36 | /** |
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 NOT |
58 | */ |
59 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
60 | IAdaptable info) throws ExecutionException { |
61 | RequiredRole newElement = RepositoryFactory.eINSTANCE |
62 | .createOperationRequiredRole(); // changed createRequiredRole to |
63 | |
64 | InterfaceRequiringEntity owner = (InterfaceRequiringEntity) getElementToEdit(); |
65 | owner.getRequiredRoles_InterfaceRequiringEntity().add(newElement); |
66 | |
67 | doConfigure(newElement, monitor, info); |
68 | |
69 | ((CreateElementRequest) getRequest()).setNewElement(newElement); |
70 | return CommandResult.newOKCommandResult(newElement); |
71 | } |
72 | |
73 | /** |
74 | * @generated |
75 | */ |
76 | protected void doConfigure(RequiredRole newElement, |
77 | IProgressMonitor monitor, IAdaptable info) |
78 | throws ExecutionException { |
79 | IElementType elementType = ((CreateElementRequest) getRequest()) |
80 | .getElementType(); |
81 | ConfigureRequest configureRequest = new ConfigureRequest( |
82 | getEditingDomain(), newElement, elementType); |
83 | configureRequest.setClientContext(((CreateElementRequest) getRequest()) |
84 | .getClientContext()); |
85 | configureRequest.addParameters(getRequest().getParameters()); |
86 | ICommand configureCommand = elementType |
87 | .getEditCommand(configureRequest); |
88 | if (configureCommand != null && configureCommand.canExecute()) { |
89 | configureCommand.execute(monitor, info); |
90 | } |
91 | } |
92 | |
93 | } |