Search in sources :

Example 31 with DatabaseNavigatorTree

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

the class ScriptsImportWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    String externalDir = DBWorkbench.getPlatform().getPreferenceStore().getString(ScriptsExportWizardPage.PREF_SCRIPTS_EXPORT_OUT_DIR);
    if (CommonUtils.isEmpty(externalDir)) {
        externalDir = RuntimeUtils.getUserHomeDir().getAbsolutePath();
    }
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    placeholder.setLayout(new GridLayout(1, false));
    // Input settings
    Composite generalSettings = UIUtils.createPlaceholder(placeholder, 3);
    generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    {
        UIUtils.createControlLabel(generalSettings, CoreMessages.dialog_scripts_import_wizard_label_input_directory);
        directoryText = new Text(generalSettings, SWT.BORDER);
        directoryText.setText(externalDir);
        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_scripts_import_wizard_dialog_choose_dir_message);
                dialog.setText(CoreMessages.dialog_scripts_import_wizard_dialog_choose_dir_text);
                String directory = directoryText.getText();
                if (!CommonUtils.isEmpty(directory)) {
                    dialog.setFilterPath(directory);
                }
                directory = dialog.open();
                if (directory != null) {
                    directoryText.setText(directory);
                }
            }
        });
        // $NON-NLS-2$
        extensionsText = UIUtils.createLabelText(generalSettings, CoreMessages.dialog_scripts_import_wizard_label_file_mask, "*.sql,*.txt");
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        extensionsText.setLayoutData(gd);
        UIUtils.createControlLabel(generalSettings, CoreMessages.dialog_scripts_import_wizard_label_default_connection);
        scriptsDataSources = new CSmartCombo<>(generalSettings, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new ConnectionLabelProvider());
        for (DBPDataSourceContainer dataSourceDescriptor : DataSourceRegistry.getAllDataSources()) {
            scriptsDataSources.addItem(dataSourceDescriptor);
        }
        if (scriptsDataSources.getItemCount() > 0) {
            scriptsDataSources.select(0);
        }
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        gd.verticalIndent = 2;
        scriptsDataSources.setLayoutData(gd);
    }
    UIUtils.createControlLabel(placeholder, CoreMessages.dialog_scripts_import_wizard_label_root_folder);
    importRoot = DBWorkbench.getPlatform().getNavigatorModel().getRoot();
    final DatabaseNavigatorTree scriptsNavigator = new DatabaseNavigatorTree(placeholder, importRoot, SWT.BORDER | SWT.SINGLE, false);
    scriptsNavigator.setLayoutData(new GridData(GridData.FILL_BOTH));
    scriptsNavigator.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel == null || sel.isEmpty()) {
                importRoot = null;
            } else {
                importRoot = (DBNNode) sel.getFirstElement();
            }
            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;
        }
    });
    scriptsNavigator.getViewer().expandToLevel(2);
    overwriteCheck = UIUtils.createCheckbox(placeholder, CoreMessages.dialog_project_export_wizard_page_checkbox_overwrite_files, false);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.horizontalSpan = 3;
    overwriteCheck.setLayoutData(gd);
    setControl(placeholder);
    updateState();
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IContainer(org.eclipse.core.resources.IContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Composite(org.eclipse.swt.widgets.Composite) 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) GridData(org.eclipse.swt.layout.GridData)

Example 32 with DatabaseNavigatorTree

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree 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 33 with DatabaseNavigatorTree

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

the class PostgresRolePrivilegesEditor method createPartControl.

public void createPartControl(Composite parent) {
    this.pageControl = new PageControl(parent);
    SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
    roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    final TreeViewer treeViewer = roleOrObjectTable.getViewer();
    treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {

        @Override
        public Font getFont(Object element) {
            if (element instanceof DBNDatabaseNode) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof PostgreSchema) {
                    String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
                    for (String tableName : permissionMap.keySet()) {
                        if (tableName.startsWith(schemaPrefix)) {
                            return boldFont;
                        }
                    }
                } else if (getObjectPermissions(object) != null) {
                    return boldFont;
                }
            }
            return null;
        }
    });
    treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
                return false;
            }
            if (element instanceof DBNDatabaseFolder) {
                try {
                    String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
                    if (elementTypeName == null) {
                        return false;
                    }
                    Class<?> childType = Class.forName(elementTypeName);
                    return PostgreTableReal.class.isAssignableFrom(childType) || PostgreSequence.class.isAssignableFrom(childType) || PostgreProcedure.class.isAssignableFrom(childType);
                } catch (ClassNotFoundException e) {
                    return false;
                }
            }
            return true;
        }
    });
    {
        permEditPanel = new Composite(composite, SWT.NONE);
        permEditPanel.setLayout(new GridLayout(1, true));
        permissionTable = new Table(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK);
        permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        permissionTable.setHeaderVisible(true);
        permissionTable.setLinesVisible(true);
        UIUtils.createTableColumn(permissionTable, SWT.LEFT, PostgreMessages.dialog_create_table_column_name_permission);
        UIUtils.createTableColumn(permissionTable, SWT.CENTER, PostgreMessages.dialog_create_table_column_name_with_garant);
        UIUtils.createTableColumn(permissionTable, SWT.CENTER, PostgreMessages.dialog_create_table_column_name_with_hierarchy);
        permissionTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (e.detail == SWT.CHECK) {
                    updateCurrentPrivileges(((TableItem) e.item).getChecked(), (PostgrePrivilegeType) e.item.getData());
                }
            }
        });
        permissionTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                super.mouseDown(e);
            }
        });
        if (!isRoleEditor()) {
            for (PostgrePrivilegeType pt : PostgrePrivilegeType.values()) {
                if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
                    continue;
                }
                TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
                privItem.setText(0, pt.name());
                privItem.setData(pt);
            }
        }
        Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
        buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        buttonPanel.setLayout(new RowLayout());
        UIUtils.createPushButton(buttonPanel, PostgreMessages.dialog_create_push_button_grant_all, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean hadNonChecked = false;
                for (TableItem item : permissionTable.getItems()) {
                    if (!item.getChecked())
                        hadNonChecked = true;
                    item.setChecked(true);
                }
                if (hadNonChecked)
                    updateCurrentPrivileges(true, null);
            }
        });
        UIUtils.createPushButton(buttonPanel, PostgreMessages.dialog_create_push_button_revoke_all, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean hadChecked = false;
                for (TableItem item : permissionTable.getItems()) {
                    if (item.getChecked())
                        hadChecked = true;
                    item.setChecked(false);
                }
                if (hadChecked) {
                    updateCurrentPrivileges(false, null);
                }
            }
        });
        objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
        objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    pageControl.createOrSubstituteProgressPanel(getSite());
    updateObjectPermissions(null);
}
Also used : DatabaseNavigatorLabelProvider(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TableItem(org.eclipse.swt.widgets.TableItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 34 with DatabaseNavigatorTree

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

Example 35 with DatabaseNavigatorTree

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

the class NavigatorHandlerFilterObjectType method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DatabaseNavigatorView) {
        DatabaseNavigatorTree navigatorTree = ((DatabaseNavigatorView) activePart).getNavigatorTree();
        DatabaseNavigatorTreeFilterObjectType objectType = CommonUtils.valueOf(DatabaseNavigatorTreeFilterObjectType.class, event.getParameter("type"), DatabaseNavigatorTreeFilterObjectType.table);
        if (objectType == navigatorTree.getFilterObjectType()) {
            return null;
        }
        navigatorTree.setFilterObjectType(objectType);
        navigatorTree.getViewer().getControl().setRedraw(false);
        try {
            navigatorTree.getViewer().refresh();
        } finally {
            navigatorTree.getViewer().getControl().setRedraw(true);
        }
    }
    ActionUtils.fireCommandRefresh(NavigatorCommands.CMD_FILTER_CONNECTIONS);
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DatabaseNavigatorView(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorView) DatabaseNavigatorTreeFilterObjectType(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTreeFilterObjectType) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)

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