Search in sources :

Example 1 with ITreePathContentProvider

use of org.eclipse.jface.viewers.ITreePathContentProvider in project hale by halestudio.

the class TreePathPatternFilter method isParentMatch.

/**
 * @see PatternFilter#isParentMatch(Viewer, Object)
 */
@Override
protected boolean isParentMatch(Viewer viewer, Object element) {
    TreePath elementPath = (TreePath) element;
    boolean proceed = allowDescend(elementPath);
    if (!proceed) {
        return false;
    }
    Object[] children;
    ITreePathContentProvider cp = ((ITreePathContentProvider) ((AbstractTreeViewer) viewer).getContentProvider());
    children = cp.getChildren(elementPath);
    if ((children != null) && (children.length > 0)) {
        // convert children to tree paths
        List<TreePath> pathChildren = TreePathFilteredTree.getPathsForElements(elementPath, children);
        return isAnyVisible(viewer, element, pathChildren.toArray());
    }
    return false;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer)

Example 2 with ITreePathContentProvider

use of org.eclipse.jface.viewers.ITreePathContentProvider in project polymap4-core by Polymap4.

the class SafeDelegateTreeContentProvider method getChildren.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreePathContentProvider#getChildren(org.eclipse.jface.viewers.TreePath)
	 */
public Object[] getChildren(TreePath parentPath) {
    if (contentProvider instanceof ITreePathContentProvider) {
        ITreePathContentProvider tpcp = (ITreePathContentProvider) contentProvider;
        Object[] children = tpcp.getChildren(parentPath);
        return children;
    }
    return getChildren(parentPath.getLastSegment());
}
Also used : ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider)

Example 3 with ITreePathContentProvider

use of org.eclipse.jface.viewers.ITreePathContentProvider in project polymap4-core by Polymap4.

the class SafeDelegateTreeContentProvider method getParents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreePathContentProvider#getParents(java.lang.Object)
	 */
public TreePath[] getParents(Object element) {
    if (contentProvider instanceof ITreePathContentProvider) {
        ITreePathContentProvider tpcp = (ITreePathContentProvider) contentProvider;
        return tpcp.getParents(element);
    }
    ArrayList segments = new ArrayList();
    Object parent = element;
    do {
        parent = contentProvider.getParent(parent);
        if (parent != null && parent != viewer.getInput())
            segments.add(0, parent);
    } while (parent != null && parent != viewer.getInput());
    if (!segments.isEmpty()) {
        // Loop backwards over the array to create the path.
        return new TreePath[] { new TreePath(segments.toArray()) };
    }
    return NO_PATHS;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider)

Example 4 with ITreePathContentProvider

use of org.eclipse.jface.viewers.ITreePathContentProvider in project polymap4-core by Polymap4.

the class NavigatorSaveablesService method getActiveSaveables.

public synchronized Saveable[] getActiveSaveables() {
    ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection instanceof ITreeSelection) {
        return getActiveSaveablesFromTreeSelection((ITreeSelection) selection);
    } else if (contentProvider instanceof ITreePathContentProvider) {
        return getActiveSaveablesFromTreePathProvider(selection, (ITreePathContentProvider) contentProvider);
    } else {
        return getActiveSaveablesFromTreeProvider(selection, contentProvider);
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with ITreePathContentProvider

use of org.eclipse.jface.viewers.ITreePathContentProvider in project polymap4-core by Polymap4.

the class NavigatorSaveablesService method computeSaveables.

/**
 * helper to compute the saveables for which elements are part of the tree.
 * Must be called from a synchronized method.
 *
 * @return the saveables
 */
private Saveable[] computeSaveables() {
    ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
    Object viewerInput = viewer.getInput();
    List result = new ArrayList();
    Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
    SaveablesProvider[] saveablesProviders = getSaveablesProviders();
    for (int i = 0; i < saveablesProviders.length; i++) {
        SaveablesProvider saveablesProvider = saveablesProviders[i];
        Saveable[] saveables = saveablesProvider.getSaveables();
        for (int j = 0; j < saveables.length; j++) {
            Saveable saveable = saveables[j];
            Object[] elements = saveablesProvider.getElements(saveable);
            // the saveable is added to the result if at least one of the
            // elements representing the saveable appears in the tree, i.e.
            // if its parent chain leads to a root node.
            boolean foundRoot = false;
            for (int k = 0; !foundRoot && k < elements.length; k++) {
                Object element = elements[k];
                if (roots.contains(element)) {
                    result.add(saveable);
                    foundRoot = true;
                } else if (isTreepathContentProvider) {
                    ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
                    TreePath[] parentPaths = treePathContentProvider.getParents(element);
                    for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
                        TreePath parentPath = parentPaths[l];
                        for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
                            if (roots.contains(parentPath.getSegment(m))) {
                                result.add(saveable);
                                foundRoot = true;
                            }
                        }
                    }
                } else {
                    while (!foundRoot && element != null) {
                        if (roots.contains(element)) {
                            // found a parent chain leading to a root. The
                            // saveable is part of the tree.
                            result.add(saveable);
                            foundRoot = true;
                        } else {
                            element = contentProvider.getParent(element);
                        }
                    }
                }
            }
        }
    }
    return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Saveable(org.eclipse.ui.Saveable) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) TreePath(org.eclipse.jface.viewers.TreePath) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider) HashSet(java.util.HashSet)

Aggregations

ITreePathContentProvider (org.eclipse.jface.viewers.ITreePathContentProvider)5 TreePath (org.eclipse.jface.viewers.TreePath)3 ArrayList (java.util.ArrayList)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 Saveable (org.eclipse.ui.Saveable)1 SaveablesProvider (org.eclipse.ui.navigator.SaveablesProvider)1