Search in sources :

Example 1 with CheckboxTreeManager

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

the class SearchDataPage method createControl.

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    initializeDialogUnits(parent);
    Composite searchGroup = new Composite(parent, SWT.NONE);
    searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    searchGroup.setLayout(new GridLayout(3, false));
    setControl(searchGroup);
    UIUtils.createControlLabel(searchGroup, "String");
    searchText = new Combo(searchGroup, SWT.DROP_DOWN);
    searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (params.searchString != null) {
        searchText.setText(params.searchString);
    }
    for (String history : searchHistory) {
        searchText.add(history);
    }
    searchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            params.searchString = searchText.getText();
            updateEnablement();
        }
    });
    Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    optionsGroup.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 3;
    optionsGroup.setLayoutData(gd);
    {
        final DBeaverCore core = DBeaverCore.getInstance();
        Group databasesGroup = UIUtils.createControlGroup(optionsGroup, "Databases", 1, GridData.FILL_BOTH, 0);
        gd = new GridData(GridData.FILL_BOTH);
        //gd.heightHint = 300;
        databasesGroup.setLayoutData(gd);
        final DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(core.getProjectRegistry().getActiveProject());
        DBNNode rootNode = projectNode == null ? core.getNavigatorModel().getRoot() : projectNode.getDatabases();
        dataSourceTree = new DatabaseNavigatorTree(databasesGroup, rootNode, SWT.SINGLE | SWT.CHECK);
        gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        dataSourceTree.setLayoutData(gd);
        final CheckboxTreeViewer viewer = (CheckboxTreeViewer) dataSourceTree.getViewer();
        viewer.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof TreeLoadNode) {
                    return true;
                }
                if (element instanceof DBNNode) {
                    if (element instanceof DBNDatabaseFolder) {
                        DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
                        Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
                        return folderItemsClass != null && (DBSObjectContainer.class.isAssignableFrom(folderItemsClass) || DBSEntity.class.isAssignableFrom(folderItemsClass));
                    }
                    if (element instanceof DBNLocalFolder || element instanceof DBNProjectDatabases || element instanceof DBNDataSource) {
                        return true;
                    }
                    if (element instanceof DBSWrapper) {
                        DBSObject obj = ((DBSWrapper) element).getObject();
                        if (obj instanceof DBSObjectContainer)
                            return true;
                        if (obj instanceof DBSDataContainer && obj instanceof DBSEntity) {
                            if ((((DBSDataContainer) obj).getSupportedFeatures() & DBSDataContainer.DATA_SEARCH) != 0) {
                                return true;
                            }
                        }
                    }
                }
                return false;
            }
        });
        checkboxTreeManager = new CheckboxTreeManager(viewer, new Class[] { DBSDataContainer.class });
        viewer.addCheckStateListener(new ICheckStateListener() {

            @Override
            public void checkStateChanged(CheckStateChangedEvent event) {
                updateEnablement();
            }
        });
    }
    {
        //new Label(searchGroup, SWT.NONE);
        Composite optionsGroup2 = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
        optionsGroup2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
        if (params.maxResults <= 0) {
            params.maxResults = 10;
        }
        final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(optionsGroup2, "Sample rows", params.maxResults, 1, Integer.MAX_VALUE);
        maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        maxResultsSpinner.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                params.maxResults = maxResultsSpinner.getSelection();
            }
        });
        final Button caseCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, CoreMessages.dialog_search_objects_case_sensitive, params.caseSensitive);
        caseCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        caseCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.caseSensitive = caseCheckbox.getSelection();
            }
        });
        final Button fastSearchCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Fast search (indexed)", params.fastSearch);
        fastSearchCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        fastSearchCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.fastSearch = fastSearchCheckbox.getSelection();
            }
        });
        final Button searchNumbersCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in numbers", params.searchNumbers);
        searchNumbersCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        searchNumbersCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchNumbers = searchNumbersCheckbox.getSelection();
            }
        });
        final Button searchLOBCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in LOBs", params.searchLOBs);
        searchLOBCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        searchLOBCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchLOBs = searchNumbersCheckbox.getSelection();
            }
        });
    }
    final List<DBNNode> checkedNodes = new ArrayList<>();
    dataSourceTree.setEnabled(false);
    try {
        DBeaverUI.runInProgressDialog(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Load database nodes", 1);
                try {
                    monitor.subTask("Load tree state");
                    checkedNodes.addAll(loadTreeState(monitor, store, PROP_SOURCES));
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(getShell(), "Data sources load", "Error loading settings", e.getTargetException());
    }
    if (!checkedNodes.isEmpty()) {
        boolean first = true;
        for (DBNNode node : checkedNodes) {
            ((CheckboxTreeViewer) dataSourceTree.getViewer()).setChecked(node, true);
            if (first) {
                dataSourceTree.getViewer().reveal(NavigatorUtils.getDataSourceNode(node));
                first = false;
            }
        }
        checkboxTreeManager.updateCheckStates();
    }
    updateEnablement();
    dataSourceTree.setEnabled(true);
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TreeLoadNode(org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode) DBeaverCore(org.jkiss.dbeaver.core.DBeaverCore) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckboxTreeManager(org.jkiss.dbeaver.ui.navigator.database.CheckboxTreeManager) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) InvocationTargetException(java.lang.reflect.InvocationTargetException) SashForm(org.eclipse.swt.custom.SashForm) GridData(org.eclipse.swt.layout.GridData) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 SashForm (org.eclipse.swt.custom.SashForm)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 DBeaverCore (org.jkiss.dbeaver.core.DBeaverCore)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1 CheckboxTreeManager (org.jkiss.dbeaver.ui.navigator.database.CheckboxTreeManager)1 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)1 TreeLoadNode (org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode)1