1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
5 | |
6 | import java.util.ArrayList; |
7 | |
8 | import org.eclipse.emf.ecore.EObject; |
9 | import org.eclipse.emf.ecore.EReference; |
10 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
11 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
12 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
13 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
14 | import org.eclipse.ui.PlatformUI; |
15 | |
16 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
17 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
18 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
19 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
20 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
21 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
22 | |
23 | /** |
24 | * @author Roman Andrej |
25 | * |
26 | */ |
27 | public class ExternalCallActionEditHelperAdvice extends |
28 | AbstractEditHelperAdvice implements IEditHelperAdvice { |
29 | |
30 | /* (non-Javadoc) |
31 | * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
32 | */ |
33 | @Override |
34 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
35 | EObject eObject = searchBasicComponent(request.getElementToConfigure()); |
36 | OperationRequiredRole requiredRole = null; |
37 | |
38 | // define the filter list |
39 | ArrayList<Object> filterList = new ArrayList<Object>(); |
40 | filterList.add(OperationRequiredRole.class); |
41 | filterList.add(OperationInterface.class); |
42 | filterList.add(OperationSignature.class); |
43 | |
44 | // define the additional references |
45 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
46 | additionalReferences.add(RepositoryPackage.eINSTANCE |
47 | .getOperationRequiredRole_RequiredInterface__OperationRequiredRole()); |
48 | |
49 | // create the dialog |
50 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
51 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
52 | filterList, additionalReferences, eObject); |
53 | dialog.setProvidedService(OperationSignature.class); |
54 | dialog.open(); |
55 | if (dialog.getResult() == null) |
56 | return new CanceledCommand(); |
57 | if (!(dialog.getResult() instanceof OperationSignature)) |
58 | return new CanceledCommand(); |
59 | |
60 | // set the signature for ExternalCallAction |
61 | OperationSignature signature = (OperationSignature) dialog.getResult(); |
62 | |
63 | // set the required role for ExternalCallAction |
64 | if (dialog.getViewerRootElement() instanceof OperationRequiredRole) { |
65 | requiredRole = (OperationRequiredRole) dialog.getRootOfResult(); |
66 | } |
67 | |
68 | // create and execute the ExternalCallActionConfigureCommand command |
69 | return new ExternalCallActionConfigureCommand(request, signature, |
70 | requiredRole); |
71 | } |
72 | |
73 | private EObject searchBasicComponent(EObject elementToConfigure) { |
74 | EObject o = elementToConfigure; |
75 | while (!(o instanceof BasicComponent)) |
76 | o = o.eContainer(); |
77 | return o; |
78 | } |
79 | } |