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.OperationInterface; |
20 | import de.uka.ipd.sdq.pcm.repository.OperationSignature; |
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.OperationsEditorSection; |
24 | import de.uka.ipd.sdq.pcmbench.tabs.operations.OperationsTabItemProviderAdapterFactory; |
25 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
26 | |
27 | /** |
28 | * "Operations" Property Section - signature editor |
29 | */ |
30 | public class OperationsPropertySection extends AbstractPropertySection { |
31 | |
32 | /** |
33 | * The Property Sheet Page used to display the standard properties |
34 | */ |
35 | private ComposedAdapterFactory adapterFactory; |
36 | private OperationsEditorSection propertySection; |
37 | |
38 | /** |
39 | * @see org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite, |
40 | * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) |
41 | */ |
42 | @Override |
43 | public void createControls(Composite parent, |
44 | TabbedPropertySheetPage tabbedPropertySheetPage) { |
45 | |
46 | super.createControls(parent, tabbedPropertySheetPage); |
47 | Composite composite = getWidgetFactory() |
48 | .createFlatFormComposite(parent); |
49 | |
50 | adapterFactory = new ComposedAdapterFactory(); |
51 | adapterFactory |
52 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
53 | adapterFactory.addAdapterFactory(new SeffItemProviderAdapterFactory()); |
54 | adapterFactory |
55 | .addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
56 | adapterFactory |
57 | .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
58 | |
59 | propertySection = new OperationsEditorSection(composite); |
60 | propertySection |
61 | .setViewerContentProvider(new AdapterFactoryContentProvider( |
62 | adapterFactory)); |
63 | propertySection |
64 | .setViewerLabelProvider(new AdapterFactoryLabelProvider( |
65 | new OperationsTabItemProviderAdapterFactory( |
66 | new PalladioItemProviderAdapterFactory( |
67 | adapterFactory)))); |
68 | } |
69 | |
70 | /** |
71 | * @see org.eclipse.ui.views.properties.tabbed.ISection#setInput(org.eclipse.ui.IWorkbenchPart, |
72 | * org.eclipse.jface.viewers.ISelection) |
73 | */ |
74 | @Override |
75 | public void setInput(IWorkbenchPart part, ISelection selection) { |
76 | super.setInput(part, selection); |
77 | Assert.isTrue(selection instanceof IStructuredSelection); |
78 | Object input = ((IStructuredSelection) selection).getFirstElement(); |
79 | if (input instanceof GraphicalEditPart){ |
80 | GraphicalEditPart ep = (GraphicalEditPart)input; |
81 | input = ep.getModel(); |
82 | } |
83 | if (input instanceof View){ |
84 | input = ((View)input).getElement(); |
85 | } |
86 | if (input instanceof OperationSignature) { |
87 | OperationSignature signature = (OperationSignature) input; |
88 | input = signature.getInterface__OperationSignature(); |
89 | } |
90 | |
91 | Assert.isTrue(input instanceof EObject); |
92 | // set input for 'TableViewer' |
93 | propertySection.setViewerInput(input); |
94 | // set in the diagram selected object to the add button action listener. |
95 | propertySection.getAddButtonListener().setSelectedInterface((OperationInterface) input); |
96 | } |
97 | |
98 | /** |
99 | * @see org.eclipse.ui.views.properties.tabbed.ISection#refresh() |
100 | */ |
101 | @Override |
102 | public void refresh() { |
103 | propertySection.refresh(); |
104 | } |
105 | |
106 | /** |
107 | * @see org.eclipse.ui.views.properties.tabbed.ISection#shouldUseExtraSpace() |
108 | */ |
109 | @Override |
110 | public boolean shouldUseExtraSpace() { |
111 | return true; |
112 | } |
113 | } |