Search in sources :

Example 6 with TreeNodeSpecial

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

the class NavigatorViewBase method createNavigatorTree.

private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
    // Create tree
    final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
    createTreeColumns(navigatorTree);
    navigatorTree.getViewer().addSelectionChangedListener(event -> onSelectionChange((IStructuredSelection) event.getSelection()));
    navigatorTree.getViewer().getTree().addListener(SWT.MouseDoubleClick, event -> {
        event.doit = false;
    });
    navigatorTree.getViewer().getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            super.mouseDoubleClick(e);
        }

        @Override
        public void mouseDown(MouseEvent e) {
            super.mouseDown(e);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            super.mouseUp(e);
        }
    });
    navigatorTree.getViewer().addDoubleClickListener(event -> {
        TreeViewer viewer = tree.getViewer();
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        for (Object node : selection.toArray()) {
            // Object node = selection.getFirstElement();
            if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
                toggleNode(viewer, node);
            } else if (node instanceof DBNDataSource) {
                NavigatorPreferences.DoubleClickBehavior dsBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK), NavigatorPreferences.DoubleClickBehavior.EDIT);
                if (dsBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
                    switch(dsBehaviorDefault) {
                        case EDIT:
                            NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, UIUtils.getActiveWorkbenchWindow());
                            break;
                        case CONNECT:
                            {
                                UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
                                if (serviceConnections != null) {
                                    if (dataSource.isConnected()) {
                                        serviceConnections.disconnectDataSource(dataSource);
                                    } else {
                                        serviceConnections.connectDataSource(dataSource, null);
                                    }
                                }
                                break;
                            }
                        case SQL_EDITOR:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openRecentScript(dataSource);
                                }
                                break;
                            }
                        case SQL_EDITOR_NEW:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openNewScript(dataSource);
                                }
                                break;
                            }
                    }
                }
            } else if (node instanceof TreeNodeSpecial) {
                ((TreeNodeSpecial) node).handleDefaultAction(navigatorTree);
            } else {
                String defaultEditorPageId = null;
                NavigatorPreferences.DoubleClickBehavior dcBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
                if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
                    defaultEditorPageId = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE);
                }
                boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
                if (hasChildren && dcBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    Map<String, Object> parameters = null;
                    if (!CommonUtils.isEmpty(defaultEditorPageId)) {
                        parameters = Collections.singletonMap(MultiPageDatabaseEditor.PARAMETER_ACTIVE_PAGE, defaultEditorPageId);
                    }
                    NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, parameters, getSite());
                }
            }
        }
    });
    // Hook context menu
    NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
    // Add drag and drop support
    NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
    DBWorkbench.getPlatform().getPreferenceStore().addPropertyChangeListener(this);
    return navigatorTree;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with TreeNodeSpecial

use of org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial 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 8 with TreeNodeSpecial

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

the class SQLScriptTaskDataSourceSelectorDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    INavigatorFilter dsFilter = new INavigatorFilter() {

        @Override
        public boolean filterFolders() {
            return true;
        }

        @Override
        public boolean isLeafObject(Object object) {
            return object instanceof DBNDataSource;
        }

        @Override
        public boolean select(Object element) {
            return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource || element instanceof TreeNodeSpecial;
        }
    };
    dataSourceTree = new DatabaseNavigatorTree(dialogArea, projectNode.getDatabases(), SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, dsFilter);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.widthHint = 400;
    dataSourceTree.setLayoutData(gd);
    dataSourceTree.getViewer().addSelectionChangedListener(event -> {
        updateSelectedDataSources();
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) INavigatorFilter(org.jkiss.dbeaver.ui.navigator.INavigatorFilter) GridData(org.eclipse.swt.layout.GridData) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)

Example 9 with TreeNodeSpecial

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

the class SQLScriptTaskScriptSelectorDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    INavigatorFilter scriptFilter = new INavigatorFilter() {

        @Override
        public boolean filterFolders() {
            return true;
        }

        @Override
        public boolean isLeafObject(Object object) {
            return object instanceof DBNResource && ((DBNResource) object).getResource() instanceof IFile;
        }

        @Override
        public boolean select(Object element) {
            return element instanceof DBNLocalFolder || element instanceof DBNResource || element instanceof TreeNodeSpecial;
        }
    };
    scriptsTree = new DatabaseNavigatorTree(dialogArea, projectNode, SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, scriptFilter);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.widthHint = 400;
    scriptsTree.setLayoutData(gd);
    scriptsTree.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof TreeNodeSpecial) {
                return true;
            }
            if (element instanceof DBNResource) {
                return isResourceApplicable((DBNResource) element);
            }
            return false;
        }
    });
    scriptsTree.getViewer().addSelectionChangedListener(event -> {
        updateSelectedScripts();
    });
    scriptsTree.getViewer().expandToLevel(2);
    scriptsTree.getViewer().getTree().setHeaderVisible(true);
    createScriptColumns(scriptsTree.getViewer());
    return dialogArea;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IFile(org.eclipse.core.resources.IFile) DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) Composite(org.eclipse.swt.widgets.Composite) INavigatorFilter(org.jkiss.dbeaver.ui.navigator.INavigatorFilter) GridData(org.eclipse.swt.layout.GridData) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)

Example 10 with TreeNodeSpecial

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

the class SQLToolTaskObjectSelectorDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    INavigatorFilter dsFilter = new INavigatorFilter() {

        @Override
        public boolean filterFolders() {
            return true;
        }

        @Override
        public boolean isLeafObject(Object object) {
            return object instanceof DBNDatabaseItem && taskType.appliesTo(((DBNDatabaseItem) object).getObject());
        }

        @Override
        public boolean select(Object element) {
            if (element instanceof DBNProject || element instanceof DBNProjectDatabases) {
                return true;
            }
            if (element instanceof DBNLocalFolder) {
                for (DBNDataSource ds : ((DBNLocalFolder) element).getNestedDataSources()) {
                    if (taskType.isDriverApplicable(ds.getDataSourceContainer().getDriver()) && (!showConnected || ds.getDataSourceContainer().isConnected())) {
                        return true;
                    }
                }
                return false;
            }
            if (element instanceof DBNDataSource) {
                if (showConnected && !((DBNDataSource) element).getDataSourceContainer().isConnected()) {
                    return false;
                }
                return taskType.isDriverApplicable(((DBNDataSource) element).getDataSourceContainer().getDriver());
            }
            if (element instanceof DBNDatabaseItem) {
                DBSObject object = ((DBNDatabaseItem) element).getObject();
                return (DBSObjectContainer.class.isAssignableFrom(object.getClass()) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(object.getClass())) || taskType.appliesTo(object));
            } else if (element instanceof DBNDatabaseFolder) {
                Class<? extends DBSObject> childrenClass = ((DBNDatabaseFolder) element).getChildrenClass();
                return childrenClass != null && (DBSObjectContainer.class.isAssignableFrom(childrenClass) || (taskType.matchesEntityElements() && DBSEntity.class.isAssignableFrom(childrenClass)) || taskType.matchesType(childrenClass));
            }
            return element instanceof TreeNodeSpecial;
        }
    };
    dataSourceTree = new DatabaseNavigatorTree(dialogArea, projectNode.getDatabases(), SWT.SINGLE | SWT.BORDER | SWT.CHECK, false, dsFilter);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.widthHint = 400;
    dataSourceTree.setLayoutData(gd);
    dataSourceTree.getViewer().addSelectionChangedListener(event -> {
        updateSelectedObjects();
    });
    final Button showConnectedCheck = new Button(dialogArea, SWT.CHECK);
    showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
    showConnectedCheck.setSelection(showConnected);
    showConnectedCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showConnected = showConnectedCheck.getSelection();
            dataSourceTree.getViewer().refresh();
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) INavigatorFilter(org.jkiss.dbeaver.ui.navigator.INavigatorFilter) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Button(org.eclipse.swt.widgets.Button) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)

Aggregations

TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)14 GridData (org.eclipse.swt.layout.GridData)10 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)10 Composite (org.eclipse.swt.widgets.Composite)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 INavigatorFilter (org.jkiss.dbeaver.ui.navigator.INavigatorFilter)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Button (org.eclipse.swt.widgets.Button)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2