Search in sources :

Example 1 with DatabaseNavigatorTreeFilter

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

the class BrowseObjectDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, new DatabaseNavigatorTreeFilter());
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 500;
    gd.heightHint = 500;
    navigatorTree.setLayoutData(gd);
    final TreeViewer treeViewer = navigatorTree.getViewer();
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof TreeLoadNode || element instanceof DBNLocalFolder) {
                return true;
            }
            if (element instanceof DBNNode) {
                if (element instanceof DBNDatabaseFolder) {
                    DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
                    Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
                    return folderItemsClass != null && matchesType(folderItemsClass, false);
                }
                if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
                    return true;
                }
            }
            return false;
        }
    });
    if (selectedNode != null) {
        treeViewer.setSelection(new StructuredSelection(selectedNode));
        selectedObjects.add(selectedNode);
    }
    treeViewer.addSelectionChangedListener(event -> {
        selectedObjects.clear();
        IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
        for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
            DBNNode node = (DBNNode) iter.next();
            if (node instanceof DBSWrapper) {
                DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
                if (object != null) {
                    if (!matchesType(object.getClass(), true)) {
                        selectedObjects.clear();
                        break;
                    }
                    selectedObjects.add(node);
                }
            }
        }
        getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
    });
    treeViewer.addDoubleClickListener(event -> okPressed());
    treeViewer.getTree().setFocus();
    return group;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DatabaseNavigatorTreeFilter(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) TreeLoadNode(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 2 with DatabaseNavigatorTreeFilter

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

the class ObjectBrowserDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    DatabaseNavigatorTreeFilter filter = new DatabaseNavigatorTreeFilter() {

        @Override
        public boolean isLeafObject(Object object) {
            if (leafTypes != null && leafTypes.length > 0) {
                if (object instanceof DBNDatabaseNode) {
                    DBSObject dbObject = ((DBNDatabaseNode) object).getObject();
                    if (dbObject != null) {
                        for (Class<?> leafType : leafTypes) {
                            if (leafType.isAssignableFrom(dbObject.getClass())) {
                                return true;
                            }
                        }
                    }
                }
            }
            return super.isLeafObject(object);
        }
    };
    navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, filter);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 500;
    gd.heightHint = 500;
    navigatorTree.setLayoutData(gd);
    final TreeViewer treeViewer = navigatorTree.getViewer();
    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();
                }
            }
            if (element instanceof TreeNodeSpecial || element instanceof DBNLocalFolder) {
                return true;
            }
            if (element instanceof DBNNode) {
                if (element instanceof DBNDatabaseFolder) {
                    DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
                    Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
                    return folderItemsClass != null && matchesType(folderItemsClass, false);
                }
                if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
                    return true;
                }
            }
            return false;
        }
    });
    if (selectedNode != null) {
        treeViewer.setSelection(new StructuredSelection(selectedNode));
        if (!(selectedNode instanceof DBNDataSource) || ((DBNDataSource) selectedNode).getDataSourceContainer().isConnected()) {
            treeViewer.expandToLevel(selectedNode, 1);
        }
        selectedObjects.add(selectedNode);
    }
    treeViewer.addSelectionChangedListener(event -> {
        selectedObjects.clear();
        specialNode = null;
        IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
        for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
            Object node = iter.next();
            if (node instanceof DBNNode && node instanceof DBSWrapper) {
                DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
                if (object != null) {
                    if (!matchesType(object.getClass(), true)) {
                        selectedObjects.clear();
                        break;
                    }
                    selectedObjects.add((DBNNode) node);
                }
            } else if (node instanceof TreeNodeSpecial) {
                specialNode = (TreeNodeSpecial) node;
            }
        }
        getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
    });
    treeViewer.addDoubleClickListener(event -> {
        if (!selectedObjects.isEmpty()) {
            okPressed();
        } else if (specialNode != null) {
            specialNode.handleDefaultAction(navigatorTree);
        }
    });
    treeViewer.getTree().setFocus();
    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);
            }
        }
    });
    return group;
}
Also used : DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DatabaseNavigatorTreeFilter(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter) Button(org.eclipse.swt.widgets.Button) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 3 with DatabaseNavigatorTreeFilter

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

the class ObjectBrowserDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    DatabaseNavigatorTreeFilter filter = new DatabaseNavigatorTreeFilter() {

        @Override
        public boolean isLeafObject(Object object) {
            if (leafTypes != null && leafTypes.length > 0) {
                if (object instanceof DBNDatabaseNode) {
                    DBSObject dbObject = ((DBNDatabaseNode) object).getObject();
                    if (dbObject != null) {
                        for (Class<?> leafType : leafTypes) {
                            if (leafType.isAssignableFrom(dbObject.getClass())) {
                                return true;
                            }
                        }
                    }
                }
            }
            return super.isLeafObject(object);
        }
    };
    navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER, false, filter);
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 500;
    gd.heightHint = 500;
    navigatorTree.setLayoutData(gd);
    final TreeViewer treeViewer = navigatorTree.getViewer();
    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();
                }
            }
            if (element instanceof TreeNodeSpecial || element instanceof DBNLocalFolder) {
                return true;
            }
            if (element instanceof DBNNode) {
                if (element instanceof DBNDatabaseFolder) {
                    DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
                    Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
                    return folderItemsClass != null && matchesType(folderItemsClass, false);
                }
                if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
                    return true;
                }
            }
            return false;
        }
    });
    if (selectedNode != null) {
        treeViewer.setSelection(new StructuredSelection(selectedNode));
        if (!(selectedNode instanceof DBNDataSource) || ((DBNDataSource) selectedNode).getDataSourceContainer().isConnected()) {
            treeViewer.expandToLevel(selectedNode, 1);
        }
        selectedObjects.add(selectedNode);
    }
    treeViewer.addSelectionChangedListener(event -> {
        selectedObjects.clear();
        specialNode = null;
        IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
        for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
            Object node = iter.next();
            if (node instanceof DBNNode && node instanceof DBSWrapper) {
                DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
                if (object != null) {
                    if (!matchesType(object.getClass(), true)) {
                        selectedObjects.clear();
                        break;
                    }
                    selectedObjects.add((DBNNode) node);
                }
            } else if (node instanceof TreeNodeSpecial) {
                specialNode = (TreeNodeSpecial) node;
            }
        }
        getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
    });
    treeViewer.addDoubleClickListener(event -> {
        if (!selectedObjects.isEmpty()) {
            okPressed();
        } else if (specialNode != null) {
            specialNode.handleDefaultAction(navigatorTree);
        }
    });
    treeViewer.getTree().setFocus();
    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);
            }
        }
    });
    return group;
}
Also used : DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DatabaseNavigatorTreeFilter(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter) Button(org.eclipse.swt.widgets.Button) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

Iterator (java.util.Iterator)3 GridData (org.eclipse.swt.layout.GridData)3 Composite (org.eclipse.swt.widgets.Composite)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)3 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)3 DatabaseNavigatorTreeFilter (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilter)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 TreeNodeSpecial (org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial)2 TreeLoadNode (org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode)1