Search in sources :

Example 81 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode 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 82 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class SelectDatabaseDialog method createInstanceSelector.

private void createInstanceSelector(Composite group, DBSObjectContainer instanceContainer) {
    ((GridLayout) group.getLayout()).numColumns++;
    instanceList = createObjectSelector(group, true, "DatabaseInstanceSelector", selectedInstances, new DBRRunnableWithResult<List<DBNDatabaseNode>>() {

        @Override
        public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
            try {
                if (!CommonUtils.isEmpty(currentInstanceName) && selectedInstances.isEmpty()) {
                    DBSObject activeInstance = instanceContainer.getChild(monitor, currentInstanceName);
                    if (activeInstance != null) {
                        DBNDatabaseNode activeInstanceNode = DBNUtils.getNodeByObject(monitor, activeInstance, false);
                        if (activeInstanceNode != null) {
                            selectedInstances.add(activeInstanceNode);
                        }
                    }
                }
                Collection<? extends DBSObject> instances = instanceContainer.getChildren(new VoidProgressMonitor());
                List<DBNDatabaseNode> instanceNodes = new ArrayList<>();
                if (!CommonUtils.isEmpty(instances)) {
                    for (DBSObject instance : instances) {
                        DBNDatabaseNode instanceNode = DBNUtils.getNodeByObject(monitor, instance, false);
                        if (instanceNode != null) {
                            instanceNodes.add(instanceNode);
                        }
                    }
                }
                result = instanceNodes;
                objectList.loadData();
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        }
    });
    instanceList.createProgressPanel();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.minimumWidth = 300;
    instanceList.setLayoutData(gd);
    instanceList.getSelectionProvider().addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        selectedInstances.clear();
        selectedInstances.addAll(selection.toList());
        DBNDatabaseNode instance = selectedInstances.isEmpty() ? null : selectedInstances.get(0);
        if (instance != null && !CommonUtils.equalObjects(instance.getNodeName(), currentInstanceName)) {
            currentInstanceName = instance.getNodeName();
            objectList.loadData();
        }
    });
    instanceList.loadData();
    closeOnFocusLost(instanceList);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithResult(org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult) ArrayList(java.util.ArrayList) GridData(org.eclipse.swt.layout.GridData) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 83 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class SelectDatabaseDialog method getObjects.

protected List<DBNDatabaseNode> getObjects(DBRProgressMonitor monitor) throws DBException {
    DBSObject rootObject;
    if (selectedInstances != null && currentInstanceName != null) {
        DBNDatabaseNode instanceNode = DBUtils.findObject(selectedInstances, currentInstanceName);
        rootObject = instanceNode == null ? null : instanceNode.getObject();
    } else {
        rootObject = dataSourceContainer.getDataSource();
    }
    if (rootObject instanceof DBSObjectContainer) {
        try {
            Collection<? extends DBSObject> objectList = ((DBSObjectContainer) rootObject).getChildren(monitor);
            if (objectList == null) {
                return Collections.emptyList();
            }
            List<DBNDatabaseNode> nodeList = new ArrayList<>(objectList.size());
            for (DBSObject object : objectList) {
                if (object instanceof DBSObjectContainer) {
                    DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, object, false);
                    if (databaseNode != null) {
                        nodeList.add(databaseNode);
                    }
                }
            }
            return nodeList;
        } catch (DBException e) {
            // Do not show error (it will close the dialog)
            log.error(e);
            return Collections.emptyList();
        }
    }
    return objects;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) ArrayList(java.util.ArrayList) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 84 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class ItemListControl method fillCustomActions.

@Override
public void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    addColumnConfigAction(contributionManager);
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (rootNode instanceof DBNDatabaseFolder) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
        {
            if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
                contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
            } else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
                contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {

                    {
                        setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
                    }

                    @Override
                    public void run() {
                        super.run();
                    }

                    @Override
                    public IMenuCreator getMenuCreator() {
                        return new MenuCreator(control -> {
                            List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
                            MenuManager menuManager = new MenuManager();
                            for (IContributionItem cc : items) {
                                menuManager.add(cc);
                            }
                            return menuManager;
                        });
                    }
                });
            }
        }
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (rootNode instanceof DBNDatabaseNode) {
        // Expand/collapse
        final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
        if (!inlineMetas.isEmpty()) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
        }
    }
    // Save/revert
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) ObjectPropertyTester(org.jkiss.dbeaver.ui.actions.ObjectPropertyTester) Arrays(java.util.Arrays) org.eclipse.jface.action(org.eclipse.jface.action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) NavigatorCommands(org.jkiss.dbeaver.ui.navigator.NavigatorCommands) PropertyEditorUtils(org.jkiss.dbeaver.ui.properties.PropertyEditorUtils) ArrayList(java.util.ArrayList) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Composite(org.eclipse.swt.widgets.Composite) NavigatorHandlerFilterConfig(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerFilterConfig) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ObjectPropertyDescriptor(org.jkiss.dbeaver.runtime.properties.ObjectPropertyDescriptor) Font(org.eclipse.swt.graphics.Font) DBPObjectStatisticsCollector(org.jkiss.dbeaver.model.DBPObjectStatisticsCollector) DBUtils(org.jkiss.dbeaver.model.DBUtils) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Collection(java.util.Collection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) ArrayUtils(org.jkiss.utils.ArrayUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UINavigatorMessages(org.jkiss.dbeaver.ui.internal.UINavigatorMessages) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) List(java.util.List) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) NavigatorHandlerObjectCreateNew(org.jkiss.dbeaver.ui.navigator.actions.NavigatorHandlerObjectCreateNew) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) ArrayList(java.util.ArrayList) List(java.util.List) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Example 85 with DBNDatabaseNode

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.

the class SearchDataPage method saveTreeState.

protected void saveTreeState() {
    // Object sources
    StringBuilder sourcesString = new StringBuilder();
    for (DBNNode node : selectorPanel.getCheckedNodes()) {
        if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
            if (sourcesString.length() > 0) {
                // $NON-NLS-1$
                sourcesString.append("|");
            }
            sourcesString.append(node.getNodeItemPath());
        }
    }
    searchStateCache.put(getClass(), sourcesString.toString());
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)222 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)85 DBException (org.jkiss.dbeaver.DBException)83 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)81 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 ArrayList (java.util.ArrayList)44 GridData (org.eclipse.swt.layout.GridData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)29 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)28 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)27 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)26 ISelection (org.eclipse.jface.viewers.ISelection)21 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)21 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)19 Collection (java.util.Collection)18 List (java.util.List)17 Composite (org.eclipse.swt.widgets.Composite)17 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)17 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)17 SWT (org.eclipse.swt.SWT)15