Search in sources :

Example 26 with DBSObjectFilter

use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.

the class NavigatorHandlerFilterClear method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
        DBXTreeItem itemsMeta = folder.getItemsMeta();
        if (itemsMeta != null) {
            folder.setNodeFilter(itemsMeta, new DBSObjectFilter());
            NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
        }
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 27 with DBSObjectFilter

use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.

the class NavigatorHandlerFilterToggle method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
        DBXTreeItem itemsMeta = folder.getItemsMeta();
        if (itemsMeta != null) {
            final DBSObjectFilter nodeFilter = folder.getNodeFilter(itemsMeta, true);
            if (nodeFilter != null) {
                nodeFilter.setEnabled(!nodeFilter.isEnabled());
                NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
            }
        }
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 28 with DBSObjectFilter

use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.

the class MSSQLDatabase method loadSchemas.

private List<MSSQLSchema> loadSchemas(JDBCSession session) throws DBException {
    boolean showAllSchemas = dataSource.isShowAllSchemas();
    final DBSObjectFilter schemaFilters = dataSource.getContainer().getObjectFilter(GenericSchema.class, this, false);
    String sysSchema = DBUtils.getQuotedIdentifier(this) + ".sys";
    String sql;
    if (showAllSchemas) {
        if (dataSource.isServerVersionAtLeast(SQLServerConstants.SQL_SERVER_2005_VERSION_MAJOR, 0)) {
            sql = "SELECT name FROM " + DBUtils.getQuotedIdentifier(this) + ".sys.schemas";
        } else {
            sql = "SELECT name FROM " + DBUtils.getQuotedIdentifier(this) + ".dbo.sysusers";
        }
    } else {
        sql = "SELECT DISTINCT s.name\n" + "FROM " + sysSchema + ".schemas s, " + sysSchema + ".sysobjects o\n" + "WHERE s.schema_id=o.uid\n" + "ORDER BY 1";
    }
    List<MSSQLSchema> result = new ArrayList<>();
    try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            while (dbResult.next()) {
                String name = JDBCUtils.safeGetString(dbResult, 1);
                if (name == null) {
                    continue;
                }
                name = name.trim();
                if (schemaFilters != null && !schemaFilters.matches(name)) {
                    // Doesn't match filter
                    continue;
                }
                MSSQLSchema schema = new MSSQLSchema(this, name);
                result.add(schema);
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, dataSource);
    }
    if (result.isEmpty()) {
        if (!showAllSchemas) {
            // Perhaps all schemas were filtered out
            result.add(new MSSQLSchema(this, SQLServerConstants.DEFAULT_SCHEMA_NAME));
        } else {
            // Maybe something went wrong. LEt's try to use native function
            log.warn("Schema read failed: empty list returned. Try generic method.");
            try (JDBCResultSet dbResult = session.getMetaData().getSchemas()) {
                while (dbResult.next()) {
                    result.add(new MSSQLSchema(this, dbResult.getString("TABLE_SCHEM")));
                }
            } catch (SQLException e) {
                log.error("Error reading schemas from database metadata", e);
            }
        }
    }
    return result;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList)

Example 29 with DBSObjectFilter

use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.

the class NavigatorHandlerFilterToggle method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
        DBXTreeItem itemsMeta = folder.getItemsMeta();
        if (itemsMeta != null) {
            final DBSObjectFilter nodeFilter = folder.getNodeFilter(itemsMeta, true);
            if (nodeFilter != null) {
                nodeFilter.setEnabled(!nodeFilter.isEnabled());
                NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
            }
        }
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 30 with DBSObjectFilter

use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.

the class EditObjectFilterDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(NLS.bind(CoreMessages.dialog_filter_title, objectTitle));
    // getShell().setImage(DBIcon.EVENT.getImage());
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite topPanel = UIUtils.createPlaceholder(composite, globalFilter ? 1 : 2);
    topPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    enableButton = UIUtils.createCheckbox(topPanel, CoreMessages.dialog_filter_button_enable, false);
    enableButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filter.setEnabled(enableButton.getSelection());
            enableFiltersContent();
        }
    });
    enableButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    enableButton.setSelection(filter.isEnabled());
    if (!globalFilter) {
        Link globalLink = UIUtils.createLink(topPanel, CoreMessages.dialog_filter_global_link, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                setReturnCode(SHOW_GLOBAL_FILTERS_ID);
                close();
            }
        });
        globalLink.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    }
    blockControl = UIUtils.createPlaceholder(composite, 1);
    blockControl.setLayoutData(new GridData(GridData.FILL_BOTH));
    includeTable = createEditableList(CoreMessages.dialog_filter_list_include, filter.getInclude());
    excludeTable = createEditableList(CoreMessages.dialog_filter_list_exclude, filter.getExclude());
    UIUtils.createInfoLabel(blockControl, CoreMessages.dialog_connection_edit_wizard_general_filter_hint_text);
    {
        Group sfGroup = UIUtils.createControlGroup(composite, CoreMessages.dialog_connection_edit_wizard_general_filter_save_label, 4, GridData.FILL_HORIZONTAL, 0);
        namesCombo = UIUtils.createLabelCombo(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_name_label, SWT.DROP_DOWN);
        namesCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        namesCombo.add(NULL_FILTER_NAME);
        List<String> sfNames = new ArrayList<>();
        for (DBSObjectFilter sf : dsRegistry.getSavedFilters()) {
            sfNames.add(sf.getName());
        }
        Collections.sort(sfNames);
        for (String sfName : sfNames) {
            namesCombo.add(sfName);
        }
        namesCombo.setText(CommonUtils.notEmpty(filter.getName()));
        namesCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                changeSavedFilter();
            }
        });
        Button saveButton = UIUtils.createPushButton(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_save_button, null);
        saveButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                saveConfigurations();
            }
        });
        Button removeButton = UIUtils.createPushButton(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_remove_button, null);
        removeButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dsRegistry.removeSavedFilter(namesCombo.getText());
                namesCombo.setText(NULL_FILTER_NAME);
            }
        });
    }
    enableFiltersContent();
    return composite;
}
Also used : DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)44 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)12 DBXTreeItem (org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)12 DBException (org.jkiss.dbeaver.DBException)10 ArrayList (java.util.ArrayList)9 ISelection (org.eclipse.jface.viewers.ISelection)8 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)8 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)8 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)7 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)6 List (java.util.List)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 TypeToken (com.google.gson.reflect.TypeToken)4 SQLException (java.sql.SQLException)4 NotNull (org.jkiss.code.NotNull)4 Nullable (org.jkiss.code.Nullable)4 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4