use of org.python.pydev.navigator.filters.PythonNodeFilter in project Pydev by fabioz.
the class PythonBaseModelProvider method hasChildren.
/**
* @return whether there are children for the given element. Note that there is
* an optimization in this method, so that it works correctly for elements that
* are not python files, and returns true if it is a python file with any content
* (even if that content does not actually map to a node.
*
* @see org.eclipse.ui.model.BaseWorkbenchContentProvider#hasChildren(java.lang.Object)
*/
@Override
public boolean hasChildren(Object element) {
if (element instanceof PythonFile) {
// If we're not showing nodes, return false.
INavigatorContentService contentService = viewer.getNavigatorContentService();
INavigatorFilterService filterService = contentService.getFilterService();
ViewerFilter[] visibleFilters = filterService.getVisibleFilters(true);
for (ViewerFilter viewerFilter : visibleFilters) {
if (viewerFilter instanceof PythonNodeFilter) {
return false;
}
}
PythonFile f = (PythonFile) element;
if (PythonPathHelper.isValidSourceFile(f.getActualObject())) {
try {
InputStream contents = f.getContents();
try {
if (contents.read() == -1) {
// if there is no content in the file, it has no children
return false;
} else {
// if it has any content, it has children (performance reasons)
return true;
}
} finally {
contents.close();
}
} catch (Exception e) {
Log.log("Handled error getting contents.", e);
return false;
}
}
return false;
}
if (element instanceof TreeNode<?>) {
TreeNode<?> treeNode = (TreeNode<?>) element;
return treeNode.hasChildren();
}
return getChildren(element).length > 0;
}
Aggregations