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