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.jface.dialogs.Dialog; |
15 | import org.eclipse.ui.PlatformUI; |
16 | |
17 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
18 | import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog; |
19 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
20 | import de.uka.ipd.sdq.pcm.repository.InfrastructureInterface; |
21 | import de.uka.ipd.sdq.pcm.repository.InfrastructureRequiredRole; |
22 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
23 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
24 | import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum; |
25 | |
26 | /**Advice for the EditHelper of InfrastructureCall. Displays the dialogs for selection of infrastructure required role and signature. |
27 | * @author groenda |
28 | */ |
29 | public class InfrastructureCallEditHelperAdvice extends |
30 | AbstractEditHelperAdvice implements IEditHelperAdvice { |
31 | |
32 | /* (non-Javadoc) |
33 | * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
34 | */ |
35 | @Override |
36 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
37 | EObject eObject = searchBasicComponent(request.getElementToConfigure()); |
38 | InfrastructureRequiredRole requiredRole = null; |
39 | |
40 | // define the filter list |
41 | ArrayList<Object> filterList = new ArrayList<Object>(); |
42 | filterList.add(InfrastructureRequiredRole.class); |
43 | filterList.add(InfrastructureInterface.class); |
44 | filterList.add(InfrastructureSignature.class); |
45 | |
46 | // define the additional references |
47 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
48 | additionalReferences |
49 | .add(RepositoryPackage.eINSTANCE |
50 | .getInfrastructureRequiredRole_RequiredInterface__InfrastructureRequiredRole()); |
51 | |
52 | // create the call target dialog |
53 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
54 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
55 | filterList, additionalReferences, eObject); |
56 | dialog.setProvidedService(InfrastructureSignature.class); |
57 | dialog.open(); |
58 | if (dialog.getResult() == null) |
59 | return new CanceledCommand(); |
60 | if (!(dialog.getResult() instanceof InfrastructureSignature)) |
61 | return new CanceledCommand(); |
62 | // set the signature for InfrastructureCall |
63 | InfrastructureSignature signature = (InfrastructureSignature) dialog.getResult(); |
64 | // set the required role for InfrastructureCall |
65 | if (dialog.getViewerRootElement() instanceof InfrastructureRequiredRole) { |
66 | requiredRole = (InfrastructureRequiredRole) dialog.getRootOfResult(); |
67 | } |
68 | |
69 | //create the number of calls dialog |
70 | StochasticExpressionEditDialog dialogNoC = new StochasticExpressionEditDialog( |
71 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
72 | TypeEnum.INT, request.getElementToConfigure()); |
73 | dialogNoC.open(); |
74 | if (dialogNoC.getReturnCode() == Dialog.CANCEL) |
75 | return new CanceledCommand(); |
76 | String numberOfCalls = dialogNoC.getResultText(); |
77 | |
78 | // create and execute the ExternalCallActionConfigureCommand command |
79 | return new InfrastructureCallConfigureCommand(request, signature, |
80 | requiredRole, numberOfCalls); |
81 | } |
82 | |
83 | private EObject searchBasicComponent(EObject elementToConfigure) { |
84 | EObject o = elementToConfigure; |
85 | while (!(o instanceof BasicComponent)) |
86 | o = o.eContainer(); |
87 | return o; |
88 | } |
89 | } |