Search in sources :

Example 1 with SelectionFilter

use of eu.esdihumboldt.hale.ui.util.selection.SelectionFilter in project hale by halestudio.

the class TypeHierarchyView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite parent) {
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new TypeHierarchyContentProvider());
    viewer.setLabelProvider(new TypeHierarchyLabelProvider(viewer));
    viewer.setComparator(new DefinitionComparator());
    contributeToActionBars();
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            update(event.getSelection());
        }
    });
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(part instanceof PropertiesViewPart)) {
                // selections
                return;
            }
            if (part != TypeHierarchyView.this) {
                update(selection);
            }
        }
    });
    getSite().setSelectionProvider(selectionProvider = new SelectionFilter(viewer) {

        @Override
        protected ISelection filter(ISelection selection) {
            if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
                List<Object> elements = new ArrayList<Object>();
                for (Object element : ((IStructuredSelection) selection).toList()) {
                    if (element instanceof ParentPath) {
                        // add parent path head instead of parent path
                        elements.add(((ParentPath) element).getHead());
                    } else {
                        elements.add(element);
                    }
                }
                return new StructuredSelection(elements);
            } else {
                return selection;
            }
        }
    });
    new ViewerMenu(getSite(), viewer);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionFilter(eu.esdihumboldt.hale.ui.util.selection.SelectionFilter) ISelectionListener(org.eclipse.ui.ISelectionListener) ViewerMenu(eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ParentPath(eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) PropertiesViewPart(eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)

Aggregations

DefinitionComparator (eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator)1 SelectionFilter (eu.esdihumboldt.hale.ui.util.selection.SelectionFilter)1 ViewerMenu (eu.esdihumboldt.hale.ui.util.viewer.ViewerMenu)1 PropertiesViewPart (eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)1 ParentPath (eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath)1 ArrayList (java.util.ArrayList)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ISelectionListener (org.eclipse.ui.ISelectionListener)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1