1 | package de.uka.ipd.sdq.pcm.gmf.seff.helper; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import org.eclipse.emf.ecore.EObject; |
6 | import org.eclipse.emf.ecore.EReference; |
7 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
8 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
9 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
10 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
11 | import org.eclipse.gmf.runtime.common.core.command.ICommand; |
12 | import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; |
13 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
14 | import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice; |
15 | import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
16 | import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; |
17 | import org.eclipse.ui.PlatformUI; |
18 | |
19 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
20 | import de.uka.ipd.sdq.pcm.repository.DataType; |
21 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
22 | import de.uka.ipd.sdq.pcm.repository.Parameter; |
23 | import de.uka.ipd.sdq.pcm.repository.RepositoryPackage; |
24 | import de.uka.ipd.sdq.pcm.repository.Signature; |
25 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
26 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
27 | import de.uka.ipd.sdq.pcm.seff.SeffPackage; |
28 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
29 | |
30 | /** @author roman */ |
31 | public class ParameterCollectionIteratorActionEditHelperAdvice extends |
32 | AbstractEditHelperAdvice implements IEditHelperAdvice { |
33 | |
34 | @Override |
35 | protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
36 | EObject parameter = null; |
37 | OperationSignature signature = null; |
38 | ResourceDemandingSEFF seff = null; |
39 | |
40 | seff = getSEFF(request.getElementToConfigure()); |
41 | signature = (OperationSignature) seff.getDescribedService__SEFF(); |
42 | |
43 | ArrayList<Object> filterList = new ArrayList<Object>(); |
44 | filterList.add(ResourceDemandingSEFF.class); |
45 | filterList.add(OperationSignature.class); |
46 | filterList.add(Parameter.class); |
47 | filterList.add(DataType.class); |
48 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
49 | additionalReferences.add(RepositoryPackage.eINSTANCE |
50 | .getParameter_DataType__Parameter()); |
51 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog( |
52 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
53 | filterList, additionalReferences, signature |
54 | .getInterface__OperationSignature()); |
55 | dialog |
56 | .setViewerContentProvider(new CollectionIteratorContentProvider()); |
57 | ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(); |
58 | adapterFactory |
59 | .addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
60 | adapterFactory |
61 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
62 | adapterFactory |
63 | .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
64 | /** |
65 | * set a LabelProvider for dialog TreeViewer |
66 | */ |
67 | dialog |
68 | .setViewerLabelProvider(new AdapterFactoryLabelProvider( |
69 | new CollectionIteratorItemProviderAdapterFactory( |
70 | new PalladioItemProviderAdapterFactory( |
71 | adapterFactory)))); |
72 | dialog.setProvidedService(Parameter.class); |
73 | dialog.open(); |
74 | if (dialog.getResult() == null) |
75 | return new CanceledCommand(); |
76 | if (!(dialog.getResult() instanceof Parameter)) |
77 | return new CanceledCommand(); |
78 | parameter = (Parameter) dialog.getResult(); |
79 | |
80 | ICommand cmd = new SetValueCommand( |
81 | new SetRequest( |
82 | request.getElementToConfigure(), |
83 | SeffPackage.eINSTANCE |
84 | .getCollectionIteratorAction_Parameter_CollectionIteratorAction(), |
85 | parameter)); |
86 | return cmd; |
87 | } |
88 | |
89 | private ResourceDemandingSEFF getSEFF(EObject a) { |
90 | EObject container = a; |
91 | while (!(container instanceof ResourceDemandingSEFF)) |
92 | container = container.eContainer(); |
93 | if (!(container instanceof ResourceDemandingSEFF)) |
94 | return null; |
95 | ResourceDemandingSEFF seff = (ResourceDemandingSEFF) container; |
96 | return seff; |
97 | } |
98 | |
99 | } |