Search in sources :

Example 1 with DBXTreeItem

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

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

the class DBNDatabaseNode method addChildItem.

void addChildItem(DBSObject object) {
    DBXTreeItem metaChildren = getItemsMeta();
    if (metaChildren != null) {
        final DBNDatabaseItem newChild = new DBNDatabaseItem(this, metaChildren, object, false);
        synchronized (this) {
            childNodes = ArrayUtils.add(DBNDatabaseNode.class, childNodes, newChild);
        }
        getModel().fireNodeEvent(new DBNEvent(this, DBNEvent.Action.ADD, DBNEvent.NodeChange.LOAD, newChild));
    } else {
        //$NON-NLS-1$ //$NON-NLS-2$
        log.error("Cannot add child item to " + getNodeName() + ". Conditions doesn't met");
    }
}
Also used : DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)

Example 3 with DBXTreeItem

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

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

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

the class DBNDatabaseNode method loadChildren.

private void loadChildren(DBRProgressMonitor monitor, final DBXTreeNode meta, final DBNDatabaseNode[] oldList, final List<DBNDatabaseNode> toList, boolean reflect) throws DBException {
    if (monitor.isCanceled()) {
        return;
    }
    this.filtered = false;
    List<DBXTreeNode> childMetas = meta.getChildren(this);
    if (CommonUtils.isEmpty(childMetas)) {
        return;
    }
    monitor.beginTask(ModelMessages.model_navigator_load_items_, childMetas.size());
    for (DBXTreeNode child : childMetas) {
        if (monitor.isCanceled()) {
            break;
        }
        monitor.subTask(ModelMessages.model_navigator_load_ + " " + child.getChildrenType(getObject().getDataSource()));
        if (child instanceof DBXTreeItem) {
            final DBXTreeItem item = (DBXTreeItem) child;
            boolean isLoaded = loadTreeItems(monitor, item, oldList, toList, reflect);
            if (!isLoaded && item.isOptional() && item.getRecursiveLink() == null) {
                // This may occur only if no child nodes was read
                // Then we try to go on next DBX level
                loadChildren(monitor, item, oldList, toList, reflect);
            }
        } else if (child instanceof DBXTreeFolder) {
            if (oldList == null) {
                // Load new folders only if there are no old ones
                toList.add(new DBNDatabaseFolder(this, (DBXTreeFolder) child));
            } else {
                for (DBNDatabaseNode oldFolder : oldList) {
                    if (oldFolder.getMeta() == child) {
                        oldFolder.reloadChildren(monitor, reflect);
                        toList.add(oldFolder);
                        break;
                    }
                }
            }
        } else if (child instanceof DBXTreeObject) {
            if (oldList == null) {
                // Load new objects only if there are no old ones
                toList.add(new DBNDatabaseObject(this, (DBXTreeObject) child));
            } else {
                for (DBNDatabaseNode oldObject : oldList) {
                    if (oldObject.getMeta() == child) {
                        oldObject.reloadChildren(monitor, reflect);
                        toList.add(oldObject);
                        break;
                    }
                }
            }
        } else {
            //$NON-NLS-1$
            log.warn("Unsupported meta node type: " + child);
        }
        monitor.worked(1);
    }
    monitor.done();
    if (reflect && filtered) {
        getModel().fireNodeUpdate(this, this, DBNEvent.NodeChange.REFRESH);
    }
}
Also used : DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBXTreeObject(org.jkiss.dbeaver.model.navigator.meta.DBXTreeObject) DBXTreeFolder(org.jkiss.dbeaver.model.navigator.meta.DBXTreeFolder)

Aggregations

DBXTreeItem (org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem)5 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)3 DBSObjectFilter (org.jkiss.dbeaver.model.struct.DBSObjectFilter)3 ISelection (org.eclipse.jface.viewers.ISelection)2 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1 DBXTreeFolder (org.jkiss.dbeaver.model.navigator.meta.DBXTreeFolder)1 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)1 DBXTreeObject (org.jkiss.dbeaver.model.navigator.meta.DBXTreeObject)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 EditObjectFilterDialog (org.jkiss.dbeaver.ui.dialogs.connection.EditObjectFilterDialog)1