1 | package de.uka.ipd.sdq.pcmbench.tabs; |
2 | |
3 | import org.eclipse.core.runtime.Assert; |
4 | import org.eclipse.emf.ecore.EObject; |
5 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
6 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
7 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
8 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
9 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
10 | import org.eclipse.gef.GraphicalEditPart; |
11 | import org.eclipse.gmf.runtime.notation.View; |
12 | import org.eclipse.jface.viewers.ISelection; |
13 | import org.eclipse.jface.viewers.IStructuredSelection; |
14 | import org.eclipse.swt.widgets.Composite; |
15 | import org.eclipse.ui.IWorkbenchPart; |
16 | import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; |
17 | import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; |
18 | |
19 | import de.uka.ipd.sdq.pcm.repository.InfrastructureInterface; |
20 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
21 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
22 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
23 | import de.uka.ipd.sdq.pcmbench.tabs.operations.InfrastructureSignaturesEditorSection; |
24 | import de.uka.ipd.sdq.pcmbench.tabs.operations.InfrastructureSignaturesTabItemProviderAdapterFactory; |
25 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
26 | |
27 | /** |
28 | * "Operations" Tab section for infrastructure signatures. |
29 | * |
30 | * @author groenda |
31 | */ |
32 | public class InfrastructureSignaturesPropertySection extends AbstractPropertySection { |
33 | |
34 | /** Content provider. */ |
35 | private ComposedAdapterFactory adapterFactory; |
36 | /** Property editor section for infrastructure signatures. */ |
37 | private InfrastructureSignaturesEditorSection editorSection; |
38 | |
39 | /** |
40 | * @see org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite, |
41 | * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) |
42 | */ |
43 | @Override |
44 | public void createControls(Composite parent, |
45 | TabbedPropertySheetPage tabbedPropertySheetPage) { |
46 | |
47 | super.createControls(parent, tabbedPropertySheetPage); |
48 | Composite composite = getWidgetFactory() |
49 | .createFlatFormComposite(parent); |
50 | |
51 | adapterFactory = new ComposedAdapterFactory(); |
52 | adapterFactory |
53 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
54 | adapterFactory.addAdapterFactory(new SeffItemProviderAdapterFactory()); |
55 | adapterFactory |
56 | .addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
57 | adapterFactory |
58 | .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
59 | |
60 | editorSection = new InfrastructureSignaturesEditorSection(composite); |
61 | editorSection |
62 | .setViewerContentProvider(new AdapterFactoryContentProvider( |
63 | adapterFactory)); |
64 | editorSection |
65 | .setViewerLabelProvider(new AdapterFactoryLabelProvider( |
66 | new InfrastructureSignaturesTabItemProviderAdapterFactory( |
67 | new PalladioItemProviderAdapterFactory( |
68 | adapterFactory)))); |
69 | } |
70 | |
71 | /** |
72 | * @see org.eclipse.ui.views.properties.tabbed.ISection#setInput(org.eclipse.ui.IWorkbenchPart, |
73 | * org.eclipse.jface.viewers.ISelection) |
74 | */ |
75 | @Override |
76 | public void setInput(IWorkbenchPart part, ISelection selection) { |
77 | super.setInput(part, selection); |
78 | Assert.isTrue(selection instanceof IStructuredSelection); |
79 | Object input = ((IStructuredSelection) selection).getFirstElement(); |
80 | if (input instanceof GraphicalEditPart){ |
81 | GraphicalEditPart ep = (GraphicalEditPart)input; |
82 | input = ep.getModel(); |
83 | } |
84 | if (input instanceof View){ |
85 | input = ((View)input).getElement(); |
86 | } |
87 | if (input instanceof InfrastructureSignature) { |
88 | InfrastructureSignature signature = (InfrastructureSignature) input; |
89 | input = signature.getInfrastructureInterface__InfrastructureSignature(); |
90 | } |
91 | |
92 | Assert.isTrue(input instanceof EObject); |
93 | // set input for 'TableViewer' |
94 | editorSection.setViewerInput(input); |
95 | // set in the diagram selected object to the add button action listener. |
96 | editorSection.getAddButtonListener().setSelectedInterface((InfrastructureInterface) input); |
97 | } |
98 | |
99 | /** |
100 | * @see org.eclipse.ui.views.properties.tabbed.ISection#refresh() |
101 | */ |
102 | @Override |
103 | public void refresh() { |
104 | editorSection.refresh(); |
105 | } |
106 | |
107 | /** |
108 | * @see org.eclipse.ui.views.properties.tabbed.ISection#shouldUseExtraSpace() |
109 | */ |
110 | @Override |
111 | public boolean shouldUseExtraSpace() { |
112 | return true; |
113 | } |
114 | } |