1 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
2 | |
3 | import org.eclipse.emf.ecore.EObject; |
4 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
5 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
6 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
7 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
8 | import org.eclipse.swt.SWT; |
9 | import org.eclipse.swt.widgets.MessageBox; |
10 | import org.eclipse.swt.widgets.Shell; |
11 | import org.eclipse.ui.PlatformUI; |
12 | |
13 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
14 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
15 | import de.uka.ipd.sdq.pcm.repository.ParameterModifier; |
16 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
17 | |
18 | /** |
19 | * This class defines an EditHelper to handle the creation of an SetVariableAction. |
20 | * |
21 | * @author Christian Busch |
22 | */ |
23 | public class SetVariableActionEditHelperAdvice extends |
24 | AbstractEditHelperAdvice implements IEditHelperAdvice { |
25 | |
26 | /* (non-Javadoc) |
27 | * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
28 | */ |
29 | @Override |
30 | protected ICommand getBeforeConfigureCommand(ConfigureRequest request) { |
31 | |
32 | if (hasReturn(request)) { |
33 | return new OKCommand(); |
34 | } else { |
35 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
36 | |
37 | MessageBox messageBox = |
38 | new MessageBox(shell , |
39 | SWT.OK |
40 | | SWT.ICON_WARNING); |
41 | messageBox.setText("Notice"); |
42 | messageBox.setMessage("In order to create a SetVariableAction there must be a return type specified for the signature of the interface."); |
43 | messageBox.open(); |
44 | |
45 | return new CanceledCommand(); |
46 | } |
47 | } |
48 | |
49 | /** |
50 | * Checks whether the SEFF corresponding to the request |
51 | * has a signature with at least one return type specified. |
52 | * |
53 | * @param request to be checked |
54 | * @return true if return parameter(s) of signature specified |
55 | */ |
56 | protected boolean hasReturn(ConfigureRequest request) { |
57 | |
58 | boolean hasReturn = false; |
59 | EObject node = request.getElementToConfigure(); |
60 | |
61 | /* walk through the tree */ |
62 | while (!(node instanceof ResourceDemandingSEFF)) { |
63 | node = node.eContainer(); |
64 | if (node == null) { |
65 | return false; |
66 | } |
67 | } |
68 | node = ((ResourceDemandingSEFF) node).getDescribedService__SEFF(); |
69 | if (node instanceof OperationSignature) { |
70 | OperationSignature signature = (OperationSignature) node; |
71 | /* check signature */ |
72 | for (Parameter p : signature.getParameters__OperationSignature()) { |
73 | if (p.getModifier__Parameter() == ParameterModifier.OUT |
74 | || p.getModifier__Parameter() == ParameterModifier.INOUT) { |
75 | hasReturn = true; |
76 | break; |
77 | } |
78 | } |
79 | if (signature.getReturnType__OperationSignature() != null) { |
80 | hasReturn = true; |
81 | } |
82 | } |
83 | return hasReturn; |
84 | } |
85 | } |
86 | |