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.emf.type.core.commands.EditElementCommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
13 | |
14 | import de.uka.ipd.sdq.pcm.gmf.resource.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
15 | import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource; |
16 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | public class LinkingResourceConnectedResourceContainers_LinkingResourceCreateCommand |
22 | extends EditElementCommand { |
23 | |
24 | /** |
25 | * @generated |
26 | */ |
27 | private final EObject source; |
28 | |
29 | /** |
30 | * @generated |
31 | */ |
32 | private final EObject target; |
33 | |
34 | /** |
35 | * @generated |
36 | */ |
37 | public LinkingResourceConnectedResourceContainers_LinkingResourceCreateCommand( |
38 | CreateRelationshipRequest request, EObject source, EObject target) { |
39 | super(request.getLabel(), null, request); |
40 | this.source = source; |
41 | this.target = target; |
42 | } |
43 | |
44 | /** |
45 | * @generated |
46 | */ |
47 | public boolean canExecute() { |
48 | if (source == null && target == null) { |
49 | return false; |
50 | } |
51 | if (source != null && false == source instanceof LinkingResource) { |
52 | return false; |
53 | } |
54 | if (target != null && false == target instanceof ResourceContainer) { |
55 | return false; |
56 | } |
57 | if (getSource() == null) { |
58 | return true; // link creation is in progress; source is not defined yet |
59 | } |
60 | // target may be null here but it's possible to check constraint |
61 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
62 | .canCreateLinkingResourceConnectedResourceContainers_LinkingResource_4002( |
63 | getSource(), getTarget()); |
64 | } |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
70 | IAdaptable info) throws ExecutionException { |
71 | if (!canExecute()) { |
72 | throw new ExecutionException( |
73 | "Invalid arguments in create link command"); //$NON-NLS-1$ |
74 | } |
75 | |
76 | if (getSource() != null && getTarget() != null) { |
77 | getSource().getConnectedResourceContainers_LinkingResource().add( |
78 | getTarget()); |
79 | } |
80 | return CommandResult.newOKCommandResult(); |
81 | |
82 | } |
83 | |
84 | /** |
85 | * @generated |
86 | */ |
87 | protected void setElementToEdit(EObject element) { |
88 | throw new UnsupportedOperationException(); |
89 | } |
90 | |
91 | /** |
92 | * @generated |
93 | */ |
94 | protected LinkingResource getSource() { |
95 | return (LinkingResource) source; |
96 | } |
97 | |
98 | /** |
99 | * @generated |
100 | */ |
101 | protected ResourceContainer getTarget() { |
102 | return (ResourceContainer) target; |
103 | } |
104 | } |