| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcmbench.tabs; |
| 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.AdapterFactoryLabelProvider; |
| 12 | import org.eclipse.gef.GraphicalEditPart; |
| 13 | import org.eclipse.gmf.runtime.notation.View; |
| 14 | import org.eclipse.jface.viewers.ISelection; |
| 15 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 16 | import org.eclipse.swt.SWT; |
| 17 | import org.eclipse.swt.graphics.Color; |
| 18 | import org.eclipse.swt.widgets.Composite; |
| 19 | import org.eclipse.swt.widgets.Display; |
| 20 | import org.eclipse.swt.widgets.Table; |
| 21 | import org.eclipse.swt.widgets.TableItem; |
| 22 | import org.eclipse.ui.IWorkbenchPart; |
| 23 | import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; |
| 24 | import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; |
| 25 | |
| 26 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
| 27 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
| 28 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
| 29 | import de.uka.ipd.sdq.pcmbench.tabs.parameters.ComponentParametersEditorSection; |
| 30 | import de.uka.ipd.sdq.pcmbench.tabs.parameters.ParameterContentProvider; |
| 31 | import de.uka.ipd.sdq.pcmbench.tabs.parameters.ParametersTabItemProviderAdapterFactory; |
| 32 | import de.uka.ipd.sdq.pcmbench.tabs.parameters.VariableUsageWrapper; |
| 33 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
| 34 | |
| 35 | /** |
| 36 | * @author Roman Andrej |
| 37 | * |
| 38 | */ |
| 39 | public class ComponentParametersPropertySection extends AbstractPropertySection { |
| 40 | |
| 41 | /** |
| 42 | * The Property Sheet Page used to display the standard properties |
| 43 | */ |
| 44 | private ComposedAdapterFactory adapterFactory; |
| 45 | private ComponentParametersEditorSection propertySection; |
| 46 | |
| 47 | /* (non-Javadoc) |
| 48 | * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) |
| 49 | */ |
| 50 | @Override |
| 51 | public void createControls(Composite parent, |
| 52 | TabbedPropertySheetPage tabbedPropertySheetPage) { |
| 53 | super.createControls(parent, tabbedPropertySheetPage); |
| 54 | |
| 55 | Composite composite = getWidgetFactory() |
| 56 | .createFlatFormComposite(parent); |
| 57 | |
| 58 | adapterFactory = new ComposedAdapterFactory(); |
| 59 | adapterFactory |
| 60 | .addAdapterFactory(new RepositoryItemProviderAdapterFactory()); |
| 61 | adapterFactory |
| 62 | .addAdapterFactory(new SeffItemProviderAdapterFactory()); |
| 63 | adapterFactory |
| 64 | .addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
| 65 | adapterFactory |
| 66 | .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
| 67 | |
| 68 | propertySection = new ComponentParametersEditorSection(composite); |
| 69 | // propertySection.setViewerContentProvider(new AdapterFactoryContentProvider( |
| 70 | // adapterFactory)); |
| 71 | propertySection.setViewerContentProvider(new ParameterContentProvider()); |
| 72 | // propertySection.setViewerLabelProvider(new ParameterLabelProvider()); |
| 73 | propertySection.setViewerLabelProvider(new AdapterFactoryLabelProvider( |
| 74 | new ParametersTabItemProviderAdapterFactory( |
| 75 | new PalladioItemProviderAdapterFactory(adapterFactory)))); |
| 76 | |
| 77 | |
| 78 | |
| 79 | } |
| 80 | |
| 81 | /* (non-Javadoc) |
| 82 | * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#setInput(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| 83 | */ |
| 84 | @Override |
| 85 | public void setInput(IWorkbenchPart part, ISelection selection) { |
| 86 | super.setInput(part, selection); |
| 87 | Assert.isTrue(selection instanceof IStructuredSelection); |
| 88 | Object input = ((IStructuredSelection) selection).getFirstElement(); |
| 89 | |
| 90 | if (input instanceof GraphicalEditPart){ |
| 91 | GraphicalEditPart ep = (GraphicalEditPart)input; |
| 92 | input = ep.getModel(); |
| 93 | } |
| 94 | if (input instanceof View){ |
| 95 | input = ((View)input).getElement(); |
| 96 | } |
| 97 | |
| 98 | Assert.isTrue(input instanceof EObject); |
| 99 | // set input for 'TableViewer' |
| 100 | propertySection.setViewerInput(input); |
| 101 | propertySection.getViewer().getTable(); |
| 102 | // set in the diagram selected object to the TableViever cell modifier. |
| 103 | propertySection.getCellModifier().setContext((AssemblyContext) input); |
| 104 | |
| 105 | setColorOfTableItems(propertySection.getViewer().getTable()); |
| 106 | } |
| 107 | |
| 108 | private void setColorOfTableItems(Table table) { |
| 109 | |
| 110 | // set color for items |
| 111 | Display display = table.getDisplay(); |
| 112 | Color gray = display.getSystemColor(SWT.COLOR_GRAY); |
| 113 | |
| 114 | TableItem[] items = table.getItems(); |
| 115 | |
| 116 | for (int i = 0; i < items.length; i++) { |
| 117 | TableItem item = items[i]; |
| 118 | |
| 119 | VariableUsageWrapper wrapper = (VariableUsageWrapper) item |
| 120 | .getData(); |
| 121 | |
| 122 | if (!wrapper.isEdited()) { |
| 123 | item.setForeground(gray); |
| 124 | } |
| 125 | |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | } |