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