Search in sources :

Example 6 with DBNDatabaseItem

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseItem 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 7 with DBNDatabaseItem

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseItem 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 8 with DBNDatabaseItem

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseItem 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 9 with DBNDatabaseItem

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseItem 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 10 with DBNDatabaseItem

use of org.jkiss.dbeaver.model.navigator.DBNDatabaseItem in project dbeaver by serge-rider.

the class NavigatorHandlerSetDefaultObject method markObjectAsActive.

@SuppressWarnings("unchecked")
private void markObjectAsActive(final DBNDatabaseNode databaseNode, IEditorPart activeEditor) {
    DBNNode parentNode = databaseNode.getParentNode();
    if (parentNode instanceof DBNDatabaseItem) {
        markObjectAsActive((DBNDatabaseItem) parentNode, activeEditor);
        return;
    }
    DBSObject object = databaseNode.getObject();
    DBPDataSource dataSource = object.getDataSource();
    final DBCExecutionContext editorContext;
    if (activeEditor instanceof DBPContextProvider) {
        editorContext = ((DBPContextProvider) activeEditor).getExecutionContext();
    } else {
        editorContext = null;
    }
    TasksJob.runTask("Change default object", monitor -> {
        try {
            DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
                try {
                    DBCExecutionContext defaultContext = dataSource.getDefaultInstance().getDefaultContext(monitor, false);
                    DBCExecutionContext[] contextsToChange;
                    if (editorContext != null && editorContext != defaultContext && editorContext.getDataSource() == defaultContext.getDataSource()) {
                        contextsToChange = new DBCExecutionContext[] { defaultContext, editorContext };
                    } else {
                        contextsToChange = new DBCExecutionContext[] { defaultContext };
                    }
                    for (DBCExecutionContext executionContext : contextsToChange) {
                        DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
                        if (contextDefaults != null) {
                            if (object instanceof DBSCatalog && contextDefaults.supportsCatalogChange()) {
                                contextDefaults.setDefaultCatalog(monitor, (DBSCatalog) object, null);
                            } else if (object instanceof DBSSchema && contextDefaults.supportsSchemaChange()) {
                                contextDefaults.setDefaultSchema(monitor, (DBSSchema) object);
                            } else {
                                throw new DBCException("Internal error: active object change not supported");
                            }
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            });
        } catch (Exception e) {
            throw new InvocationTargetException(e);
        }
    });
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSCatalog(org.jkiss.dbeaver.model.struct.rdb.DBSCatalog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(org.eclipse.core.commands.ExecutionException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSSchema(org.jkiss.dbeaver.model.struct.rdb.DBSSchema) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)10 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)10 ISelection (org.eclipse.jface.viewers.ISelection)9 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)9 DBXTreeItem (org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)6 DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 DBException (org.jkiss.dbeaver.DBException)1 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)1 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSCatalog (org.jkiss.dbeaver.model.struct.rdb.DBSCatalog)1 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)1