Search in sources :

Example 1 with TreeNodeLazyExpander

use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeLazyExpander in project dbeaver by dbeaver.

the class DatabaseNavigatorContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parent) {
    if (parent instanceof TreeNodeSpecial) {
        return EMPTY_CHILDREN;
    }
    if (!(parent instanceof DBNNode)) {
        return EMPTY_CHILDREN;
    }
    // view.getNavigatorModel().findNode(parent);
    final DBNNode parentNode = (DBNNode) parent;
    /*
        if (parentNode == null) {
            log.error("Can't find parent node '" + ((DBSObject) parent).getName() + "' in model");
            return EMPTY_CHILDREN;
        }
*/
    if (!parentNode.hasChildren(true)) {
        return EMPTY_CHILDREN;
    }
    if (parentNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentNode).needsInitialization()) {
        return TreeLoadVisualizer.expandChildren(navigatorTree.getViewer(), new TreeLoadService("Loading", ((DBNDatabaseNode) parentNode)));
    } else {
        try {
            // Read children with null monitor cos' it's not a lazy node
            // and no blocking process will occur
            DBNNode[] children = DBNUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), parentNode, true);
            if (ArrayUtils.isEmpty(children)) {
                return EMPTY_CHILDREN;
            } else {
                int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
                if (children.length > longListFetchSize) {
                    Object[] curChildren = new Object[longListFetchSize + 1];
                    System.arraycopy(children, 0, curChildren, 0, longListFetchSize);
                    curChildren[longListFetchSize] = new TreeNodeLazyExpander(parentNode, children, longListFetchSize);
                    return curChildren;
                }
                return children;
            }
        } catch (Throwable ex) {
            DBWorkbench.getPlatformUI().showError("Navigator error", ex.getMessage(), ex);
            // Collapse this item
            UIUtils.asyncExec(() -> {
                navigatorTree.getViewer().collapseToLevel(parent, 1);
                navigatorTree.getViewer().refresh(parent);
            });
            return EMPTY_CHILDREN;
        }
    }
}
Also used : TreeNodeLazyExpander(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeLazyExpander) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) TreeLoadService(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with TreeNodeLazyExpander

use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeLazyExpander in project dbeaver by serge-rider.

the class DatabaseNavigatorContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parent) {
    if (parent instanceof TreeNodeSpecial) {
        return EMPTY_CHILDREN;
    }
    if (!(parent instanceof DBNNode)) {
        return EMPTY_CHILDREN;
    }
    // view.getNavigatorModel().findNode(parent);
    final DBNNode parentNode = (DBNNode) parent;
    /*
        if (parentNode == null) {
            log.error("Can't find parent node '" + ((DBSObject) parent).getName() + "' in model");
            return EMPTY_CHILDREN;
        }
*/
    if (!parentNode.hasChildren(true)) {
        return EMPTY_CHILDREN;
    }
    if (parentNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentNode).needsInitialization()) {
        return TreeLoadVisualizer.expandChildren(navigatorTree.getViewer(), new TreeLoadService("Loading", ((DBNDatabaseNode) parentNode)));
    } else {
        try {
            // Read children with null monitor cos' it's not a lazy node
            // and no blocking process will occur
            DBNNode[] children = DBNUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), parentNode, true);
            if (ArrayUtils.isEmpty(children)) {
                return EMPTY_CHILDREN;
            } else {
                int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
                if (children.length > longListFetchSize) {
                    Object[] curChildren = new Object[longListFetchSize + 1];
                    System.arraycopy(children, 0, curChildren, 0, longListFetchSize);
                    curChildren[longListFetchSize] = new TreeNodeLazyExpander(parentNode, children, longListFetchSize);
                    return curChildren;
                }
                return children;
            }
        } catch (Throwable ex) {
            DBWorkbench.getPlatformUI().showError("Navigator error", ex.getMessage(), ex);
            // Collapse this item
            UIUtils.asyncExec(() -> {
                navigatorTree.getViewer().collapseToLevel(parent, 1);
                navigatorTree.getViewer().refresh(parent);
            });
            return EMPTY_CHILDREN;
        }
    }
}
Also used : TreeNodeLazyExpander(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeLazyExpander) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) TreeLoadService(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 TreeLoadService (org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadService)2 TreeNodeLazyExpander (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeLazyExpander)2 TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)2