Search in sources :

Example 1 with ParentPath

use of eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath in project hale by halestudio.

the class TypeHierarchyView method update.

/**
 * Update the hierarchy view with the given selection
 *
 * @param selection the selection
 */
protected void update(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof ParentPath) {
            element = ((ParentPath) element).getHead();
        }
        if (element instanceof Entity) {
            element = ((Entity) element).getDefinition();
        }
        if (element instanceof EntityDefinition) {
            element = ((EntityDefinition) element).getDefinition();
        }
        viewer.setInput(element);
        ParentPath path = TypeHierarchyContentProvider.createPath(element);
        viewer.expandAll();
        if (path != null) {
            viewer.setSelection(new StructuredSelection(path.getMainPath()));
        }
    } else {
        viewer.setInput(null);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ParentPath(eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with ParentPath

use of eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath 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

ParentPath (eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 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 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 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ISelectionListener (org.eclipse.ui.ISelectionListener)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1