1 | /* |
2 | * Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.repository.edit.policies.PalladioComponentModelBaseItemSemanticEditPolicy; |
15 | import de.uka.ipd.sdq.pcm.repository.CompleteComponentType; |
16 | import de.uka.ipd.sdq.pcm.repository.ImplementationComponentType; |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | public class ImplementationComponentTypeParentCompleteComponentTypesCreateCommand |
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 ImplementationComponentTypeParentCompleteComponentTypesCreateCommand( |
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 |
52 | && false == source instanceof ImplementationComponentType) { |
53 | return false; |
54 | } |
55 | if (target != null && false == target instanceof CompleteComponentType) { |
56 | return false; |
57 | } |
58 | if (getSource() == null) { |
59 | return true; // link creation is in progress; source is not defined yet |
60 | } |
61 | // target may be null here but it's possible to check constraint |
62 | return PalladioComponentModelBaseItemSemanticEditPolicy.LinkConstraints |
63 | .canCreateImplementationComponentTypeParentCompleteComponentTypes_4103( |
64 | getSource(), getTarget()); |
65 | } |
66 | |
67 | /** |
68 | * @generated |
69 | */ |
70 | protected CommandResult doExecuteWithResult(IProgressMonitor monitor, |
71 | IAdaptable info) throws ExecutionException { |
72 | if (!canExecute()) { |
73 | throw new ExecutionException( |
74 | "Invalid arguments in create link command"); //$NON-NLS-1$ |
75 | } |
76 | |
77 | if (getSource() != null && getTarget() != null) { |
78 | getSource().getParentCompleteComponentTypes().add(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 ImplementationComponentType getSource() { |
95 | return (ImplementationComponentType) source; |
96 | } |
97 | |
98 | /** |
99 | * @generated |
100 | */ |
101 | protected CompleteComponentType getTarget() { |
102 | return (CompleteComponentType) target; |
103 | } |
104 | } |