Search in sources :

Example 1 with INavigatorFilter

use of org.jkiss.dbeaver.ui.navigator.INavigatorFilter in project dbeaver by serge-rider.

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 2 with INavigatorFilter

use of org.jkiss.dbeaver.ui.navigator.INavigatorFilter 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 3 with INavigatorFilter

use of org.jkiss.dbeaver.ui.navigator.INavigatorFilter 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)

Example 4 with INavigatorFilter

use of org.jkiss.dbeaver.ui.navigator.INavigatorFilter in project dbeaver by serge-rider.

the class SelectDataSourceDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    showConnected = getDialogBoundsSettings().getBoolean(PARAM_SHOW_CONNECTED);
    showAllProjects = getDialogBoundsSettings().getBoolean(PARAM_SHOW_ALL_PROJECTS);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    rootNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot();
    projectNode = null;
    if (project != null) {
        DBNProject projectBaseNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(project);
        if (projectBaseNode != null) {
            projectNode = projectBaseNode.getDatabases();
        }
    }
    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;
        }
    };
    DatabaseNavigatorTree dataSourceTree = new DatabaseNavigatorTree(group, getTreeRootNode(), SWT.SINGLE | SWT.BORDER, false, dsFilter) {

        @Override
        protected void onTreeRefresh() {
            DBNNode treeRootNode = getTreeRootNode();
            if (dataSource != null && projectNode != null) {
                DBPDataSourceFolder dsFolder;
                for (dsFolder = dataSource.getFolder(); dsFolder != null; dsFolder = dsFolder.getParent()) {
                    if (dsFolder.getParent() == null) {
                        break;
                    }
                }
                if (dsFolder != null) {
                    // Expand only current DS folder
                    DBNLocalFolder folderNode = projectNode.getFolderNode(dsFolder);
                    if (folderNode != null) {
                        expandFolders(this, folderNode);
                    }
                } else {
                // Do not expand anything
                }
                return;
            }
            expandFolders(this, treeRootNode);
        }
    };
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 500;
    gd.minimumHeight = 100;
    gd.minimumWidth = 100;
    dataSourceTree.setLayoutData(gd);
    final TreeViewer treeViewer = dataSourceTree.getViewer();
    final Text descriptionText = new Text(group, SWT.READ_ONLY);
    descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Button showConnectedCheck = new Button(group, SWT.CHECK);
    showConnectedCheck.setText(UINavigatorMessages.label_show_connected);
    showConnectedCheck.setSelection(showConnected);
    showConnectedCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showConnected = showConnectedCheck.getSelection();
            treeViewer.getControl().setRedraw(false);
            try {
                treeViewer.refresh();
                if (showConnected) {
                    treeViewer.expandAll();
                }
            } finally {
                treeViewer.getControl().setRedraw(true);
            }
            getDialogBoundsSettings().put(PARAM_SHOW_CONNECTED, showConnected);
        }
    });
    final Button showAllProjectsCheck = new Button(group, SWT.CHECK);
    showAllProjectsCheck.setText(UINavigatorMessages.label_show_all_projects);
    showAllProjectsCheck.setSelection(showAllProjects);
    showAllProjectsCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showAllProjects = showAllProjectsCheck.getSelection();
            treeViewer.getControl().setRedraw(false);
            try {
                dataSourceTree.reloadTree(getTreeRootNode());
                if (showAllProjects) {
                    treeViewer.expandToLevel(3);
                }
            } finally {
                treeViewer.getControl().setRedraw(true);
            }
            getDialogBoundsSettings().put(PARAM_SHOW_ALL_PROJECTS, showAllProjects);
        }
    });
    if (this.dataSource != null) {
        DBNDatabaseNode dsNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(this.dataSource);
        if (dsNode != null) {
            treeViewer.setSelection(new StructuredSelection(dsNode), true);
        }
    }
    group.setTabList(new Control[] { dataSourceTree, showConnectedCheck, showAllProjectsCheck });
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (showConnected) {
                if (element instanceof DBNDataSource) {
                    return ((DBNDataSource) element).getDataSource() != null;
                }
                if (element instanceof DBNLocalFolder) {
                    return ((DBNLocalFolder) element).hasConnected();
                }
            }
            return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource;
        }
    });
    treeViewer.addSelectionChangedListener(event -> {
        IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
        Object selNode = structSel.isEmpty() ? null : structSel.getFirstElement();
        if (selNode instanceof DBNDataSource) {
            dataSource = ((DBNDataSource) selNode).getObject();
            getButton(IDialogConstants.OK_ID).setEnabled(true);
            String description = dataSource.getDescription();
            if (description == null) {
                description = dataSource.getName();
            }
            descriptionText.setText(description);
        } else {
            dataSource = null;
            getButton(IDialogConstants.OK_ID).setEnabled(false);
        }
    });
    treeViewer.addDoubleClickListener(event -> {
        if (getButton(IDialogConstants.OK_ID).isEnabled()) {
            okPressed();
        }
    });
    UIUtils.asyncExec(() -> {
        Point treeSize = dataSourceTree.getViewer().getTree().computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point shellSize = getShell().getSize();
        if (treeSize.x >= shellSize.x) {
            Point shellCompSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            getShell().setSize(shellCompSize.x, shellSize.y);
            getShell().layout(true);
        }
        dataSourceTree.getFilterControl().setFocus();
        if (showConnected) {
            treeViewer.expandAll();
        }
    });
    closeOnFocusLost(treeViewer.getControl(), dataSourceTree.getFilterControl(), descriptionText, showConnectedCheck, showAllProjectsCheck);
    return group;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) INavigatorFilter(org.jkiss.dbeaver.ui.navigator.INavigatorFilter) Point(org.eclipse.swt.graphics.Point) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

GridData (org.eclipse.swt.layout.GridData)4 INavigatorFilter (org.jkiss.dbeaver.ui.navigator.INavigatorFilter)4 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)4 Composite (org.eclipse.swt.widgets.Composite)3 TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 IFile (org.eclipse.core.resources.IFile)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)1 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)1 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)1 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)1