Search in sources :

Example 1 with PropertySheetEntry

use of org.eclipse.ui.views.properties.PropertySheetEntry in project jbosstools-hibernate by jbosstools.

the class ExporterSettingsTab method createPropertySheet.

private Control createPropertySheet(Composite exportersComposite) {
    propertySheet = new PropertySheetPage() {

        public void handleEntrySelection(ISelection selection) {
            super.handleEntrySelection(selection);
            IStructuredSelection iss = (IStructuredSelection) selection;
            IPropertyDescriptor propertyDescriptor = null;
            if (!iss.isEmpty()) {
                MyPropertySheetEntry mse = (MyPropertySheetEntry) iss.getFirstElement();
                propertyDescriptor = mse.getMyDescriptor();
            }
            updateCurrentDescriptor(propertyDescriptor);
        }
    };
    propertySheet.createControl(exportersComposite);
    final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
    propertySheetEntry.setPropertySourceProvider(new IPropertySourceProvider() {

        public IPropertySource getPropertySource(Object object) {
            if (object instanceof ExporterFactory) {
                return new ExporterFactoryPropertySource((ExporterFactory) object) {

                    public void setPropertyValue(Object id, Object value) {
                        super.setPropertyValue(id, value);
                        dialogChanged();
                    }
                };
            } else {
                return null;
            }
        }
    });
    propertySheet.setRootEntry(propertySheetEntry);
    // propertySheetEntry.setValues( new Object[] { this });
    getExporterTable().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            if (s.isEmpty()) {
                if (add != null)
                    add.setEnabled(false);
                if (remove != null)
                    remove.setEnabled(false);
                if (edit != null)
                    edit.setEnabled(false);
                propertySheetEntry.setValues(new Object[0]);
            } else {
                if (add != null)
                    add.setEnabled(true);
                boolean hasSelection = false;
                if (currentDescriptor != null) {
                    hasSelection = true;
                }
                if (remove != null)
                    remove.setEnabled(hasSelection);
                if (edit != null)
                    edit.setEnabled(hasSelection);
                ExporterFactory ep = (ExporterFactory) s.getFirstElement();
                propertySheetEntry.setValues(new Object[] { ep });
            // if(ep.isEnabled( configuration ))
            }
        }
    });
    Control control = propertySheet.getControl();
    if (control instanceof Tree && !control.isDisposed()) {
        Tree tree = (Tree) control;
        tree.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                IPropertyDescriptor propertyDescriptor = null;
                if (e.item != null && e.item.getData() != null) {
                    MyPropertySheetEntry mse = (MyPropertySheetEntry) e.item.getData();
                    propertyDescriptor = mse.getMyDescriptor();
                }
                updateCurrentDescriptor(propertyDescriptor);
            }
        });
    }
    return control;
}
Also used : PropertySheetPage(org.eclipse.ui.views.properties.PropertySheetPage) IPropertySourceProvider(org.eclipse.ui.views.properties.IPropertySourceProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertySheetEntry(org.eclipse.ui.views.properties.PropertySheetEntry) Control(org.eclipse.swt.widgets.Control) ExporterFactory(org.hibernate.eclipse.console.model.impl.ExporterFactory) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Control (org.eclipse.swt.widgets.Control)1 Tree (org.eclipse.swt.widgets.Tree)1 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)1 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)1 IPropertySourceProvider (org.eclipse.ui.views.properties.IPropertySourceProvider)1 PropertySheetEntry (org.eclipse.ui.views.properties.PropertySheetEntry)1 PropertySheetPage (org.eclipse.ui.views.properties.PropertySheetPage)1 ExporterFactory (org.hibernate.eclipse.console.model.impl.ExporterFactory)1