Search in sources :

Example 6 with DatabaseNavigatorTree

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

the class TreeNodeLazyExpander method handleDefaultAction.

@Override
public boolean handleDefaultAction(DatabaseNavigatorTree tree) {
    int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
    boolean lastSegment = visibleChildren + longListFetchSize > allChildren.length;
    int nextSegmentSize = lastSegment ? allChildren.length - visibleChildren : longListFetchSize;
    Object[] nodes = new Object[lastSegment ? nextSegmentSize : nextSegmentSize + 1];
    System.arraycopy(allChildren, visibleChildren, nodes, 0, nextSegmentSize);
    if (!lastSegment) {
        nodes[nextSegmentSize] = new TreeNodeLazyExpander(getParent(), allChildren, visibleChildren + nextSegmentSize);
    }
    Tree treeControl = tree.getViewer().getTree();
    treeControl.setRedraw(false);
    try {
        tree.getViewer().remove(this);
        tree.getViewer().add(getParent(), nodes);
    } finally {
        treeControl.setRedraw(true);
    }
    return true;
}
Also used : DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) Tree(org.eclipse.swt.widgets.Tree)

Example 7 with DatabaseNavigatorTree

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

the class ScriptsExportWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    String outDir = DBWorkbench.getPlatform().getPreferenceStore().getString(PREF_SCRIPTS_EXPORT_OUT_DIR);
    if (CommonUtils.isEmpty(outDir)) {
        outDir = RuntimeUtils.getUserHomeDir().getAbsolutePath();
    }
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    placeholder.setLayout(new GridLayout(1, false));
    // Project list
    scriptsNavigator = new DatabaseNavigatorTree(placeholder, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.BORDER | SWT.CHECK);
    GridData gd = new GridData(GridData.FILL_BOTH);
    scriptsNavigator.setLayoutData(gd);
    CheckboxTreeViewer viewer = (CheckboxTreeViewer) scriptsNavigator.getViewer();
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateState();
        }
    });
    scriptsNavigator.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof DBNResource && ((DBNResource) element).getResource() instanceof IContainer;
        }
    });
    // Output folder
    Composite generalSettings = UIUtils.createPlaceholder(placeholder, 3);
    generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    {
        overwriteCheck = UIUtils.createCheckbox(generalSettings, CoreMessages.dialog_project_export_wizard_page_checkbox_overwrite_files, false);
        gd = new GridData(GridData.BEGINNING);
        gd.horizontalSpan = 3;
        overwriteCheck.setLayoutData(gd);
        UIUtils.createControlLabel(generalSettings, CoreMessages.dialog_project_export_wizard_page_label_directory);
        directoryText = new Text(generalSettings, SWT.BORDER);
        directoryText.setText(outDir);
        directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        directoryText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateState();
            }
        });
        Button openFolder = new Button(generalSettings, SWT.PUSH);
        openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
        openFolder.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);
                dialog.setMessage(CoreMessages.dialog_project_export_wizard_page_dialog_choose_export_dir_message);
                dialog.setText(CoreMessages.dialog_project_export_wizard_page_dialog_choose_export_dir_text);
                String directory = directoryText.getText();
                if (!CommonUtils.isEmpty(directory)) {
                    dialog.setFilterPath(directory);
                }
                directory = dialog.open();
                if (directory != null) {
                    directoryText.setText(directory);
                }
            }
        });
    }
    setControl(placeholder);
    updateState();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IContainer(org.eclipse.core.resources.IContainer) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 8 with DatabaseNavigatorTree

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

the class TreeNodeLazyExpander method handleDefaultAction.

@Override
public boolean handleDefaultAction(DatabaseNavigatorTree tree) {
    int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
    boolean lastSegment = visibleChildren + longListFetchSize > allChildren.length;
    int nextSegmentSize = lastSegment ? allChildren.length - visibleChildren : longListFetchSize;
    Object[] nodes = new Object[lastSegment ? nextSegmentSize : nextSegmentSize + 1];
    System.arraycopy(allChildren, visibleChildren, nodes, 0, nextSegmentSize);
    if (!lastSegment) {
        nodes[nextSegmentSize] = new TreeNodeLazyExpander(getParent(), allChildren, visibleChildren + nextSegmentSize);
    }
    Tree treeControl = tree.getViewer().getTree();
    treeControl.setRedraw(false);
    try {
        tree.getViewer().remove(this);
        tree.getViewer().add(getParent(), nodes);
    } finally {
        treeControl.setRedraw(true);
    }
    return true;
}
Also used : DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) Tree(org.eclipse.swt.widgets.Tree)

Example 9 with DatabaseNavigatorTree

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

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)

Example 10 with DatabaseNavigatorTree

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

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)

Aggregations

DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)36 GridData (org.eclipse.swt.layout.GridData)28 Composite (org.eclipse.swt.widgets.Composite)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)14 Text (org.eclipse.swt.widgets.Text)13 GridLayout (org.eclipse.swt.layout.GridLayout)11 TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)8 ModifyListener (org.eclipse.swt.events.ModifyListener)8 Button (org.eclipse.swt.widgets.Button)8 INavigatorFilter (org.jkiss.dbeaver.ui.navigator.INavigatorFilter)8 Viewer (org.eclipse.jface.viewers.Viewer)6 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)6 SashForm (org.eclipse.swt.custom.SashForm)6 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)6 IContainer (org.eclipse.core.resources.IContainer)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)4