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;
}
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());
}
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;
}
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);
}
}
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()]);
}
Aggregations