| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcmbench.tabs; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.Collection; |
| 8 | import java.util.Iterator; |
| 9 | |
| 10 | import org.eclipse.core.runtime.Assert; |
| 11 | import org.eclipse.emf.ecore.EClass; |
| 12 | import org.eclipse.emf.ecore.EObject; |
| 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 | /** |
| 23 | * @author Snowball |
| 24 | * A tabbed property sheet section which can be configured to display |
| 25 | * a set of generic EMFPropertTextEditField (and maybe other later on). |
| 26 | * It uses a template method pattern to get a list of characterising objects |
| 27 | * describing the fields to be displayed in this sheet section |
| 28 | */ |
| 29 | |
| 30 | public abstract class GenericEMFPropertySection extends AbstractPropertySection { |
| 31 | |
| 32 | private ArrayList<EMFPropertyTextEdit> editFields = new ArrayList<EMFPropertyTextEdit>(); |
| 33 | |
| 34 | /** |
| 35 | * This method sets up the property sheet section using a template method |
| 36 | * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) |
| 37 | */ |
| 38 | @Override |
| 39 | public void createControls( |
| 40 | Composite parent, |
| 41 | TabbedPropertySheetPage tabbedPropertySheetPage) { |
| 42 | super.createControls(parent, tabbedPropertySheetPage); |
| 43 | |
| 44 | // Call the template method |
| 45 | Collection<EMFPropertySectionFieldInfo> editFieldsInfo = getEditableTextFields(); |
| 46 | |
| 47 | EMFPropertyTextEdit predecessor = null; |
| 48 | Composite composite = |
| 49 | getWidgetFactory().createFlatFormComposite(parent); |
| 50 | for(Iterator<EMFPropertySectionFieldInfo> it = editFieldsInfo.iterator(); it.hasNext(); ) |
| 51 | { |
| 52 | EMFPropertySectionFieldInfo info = it.next(); |
| 53 | EMFPropertyTextEdit newField = |
| 54 | new EMFPropertyTextEdit(composite, info.getLabel(), |
| 55 | getEClassToEdit(). |
| 56 | getEStructuralFeature(info.getFeatureID()), |
| 57 | getWidgetFactory(), |
| 58 | predecessor); |
| 59 | predecessor = newField; |
| 60 | editFields.add(newField); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns a list of edit fields which are used to display features of EMF meta-model |
| 66 | * classes |
| 67 | * @return A list of EMF features which should be editable in this property sheet section |
| 68 | */ |
| 69 | protected abstract Collection<EMFPropertySectionFieldInfo> getEditableTextFields(); |
| 70 | |
| 71 | /** |
| 72 | * The EClass of the objects which can be displayed in this property sheet. |
| 73 | * A single model object is edited in the property sheet. The features which are |
| 74 | * diplayed on the sheet are set using the getEditableTextFields method |
| 75 | * @return |
| 76 | */ |
| 77 | protected abstract EClass getEClassToEdit(); |
| 78 | |
| 79 | /** |
| 80 | * The model object which should be edited in the tab sheet is passed in here |
| 81 | * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySection#setInput(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| 82 | */ |
| 83 | @Override |
| 84 | public void setInput(IWorkbenchPart part, ISelection selection) { |
| 85 | super.setInput(part, selection); |
| 86 | Assert.isTrue(selection instanceof IStructuredSelection); |
| 87 | Object input = ((IStructuredSelection)selection).getFirstElement(); |
| 88 | if (input instanceof GraphicalEditPart) |
| 89 | { |
| 90 | GraphicalEditPart ep = (GraphicalEditPart)input; |
| 91 | input = ep.getModel(); |
| 92 | } |
| 93 | if (input instanceof View){ |
| 94 | input = ((View)input).getElement(); |
| 95 | } |
| 96 | Assert.isTrue(input instanceof EObject); |
| 97 | EObject inputEObject = (EObject)input; |
| 98 | for(Iterator<EMFPropertyTextEdit> it = editFields.iterator(); it.hasNext(); ) |
| 99 | { |
| 100 | EMFPropertyTextEdit editField = it.next(); |
| 101 | editField.setEObject(inputEObject); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | } |