Search in sources :

Example 1 with DBNDatabaseFolder

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

the class NavigatorHandlerFilterConfig method configureFilters.

public static void configureFilters(Shell shell, DBNNode node) {
    final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
    DBXTreeItem itemsMeta = folder.getItemsMeta();
    if (itemsMeta != null) {
        DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
        if (objectFilter == null) {
            objectFilter = new DBSObjectFilter();
        }
        boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
        String parentName = "?";
        if (folder.getValueObject() instanceof DBSObject) {
            parentName = ((DBSObject) folder.getValueObject()).getName();
        }
        EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
        switch(dialog.open()) {
            case IDialogConstants.OK_ID:
                folder.setNodeFilter(itemsMeta, dialog.getFilter());
                NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
                break;
            case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
                objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, false);
                dialog = new EditObjectFilterDialog(shell, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    // Set global filter
                    folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
                    folder.getDataSource().getContainer().persistConfiguration();
                    NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
                }
                break;
        }
    }
}
Also used : DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) EditObjectFilterDialog(org.jkiss.dbeaver.ui.dialogs.connection.EditObjectFilterDialog) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 2 with DBNDatabaseFolder

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

the class NavigatorHandlerFilterConfig 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) {
        configureFilters(HandlerUtil.getActiveShell(event), node);
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 3 with DBNDatabaseFolder

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

the class ItemListControl method fillCustomActions.

@Override
protected void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action("Filter", DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (workbenchSite != null) {
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
    }
    if (rootNode instanceof DBNDatabaseNode) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_OPEN));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_CREATE));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (EntityEditorsRegistry.getInstance().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_SAVE, null, UIIcon.SAVE, null, true));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REVERT, null, UIIcon.RESET, null, true));
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Action(org.eclipse.jface.action.Action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) Separator(org.eclipse.jface.action.Separator)

Example 4 with DBNDatabaseFolder

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

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

Aggregations

DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)8 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 ISelection (org.eclipse.jface.viewers.ISelection)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)3 DBXTreeItem (org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)3 DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)3 ArrayList (java.util.ArrayList)1 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 IWorkbenchSite (org.eclipse.ui.IWorkbenchSite)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)1 MultiPageEditorSite (org.eclipse.ui.part.MultiPageEditorSite)1 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1