Search in sources :

Example 11 with DBNDatabaseNode

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

the class NavigatorHandlerAddBookmark method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        final DBNNode node = NavigatorUtils.getSelectedNode(selection);
        if (node instanceof DBNDatabaseNode) {
            try {
                AddBookmarkDialog dialog = new AddBookmarkDialog(activeShell, (DBNDatabaseNode) node);
                final String title = dialog.chooseName();
                if (title != null) {
                    BookmarksHandlerImpl.createBookmark((DBNDatabaseNode) node, title, dialog.getTargetFolder());
                }
            } catch (DBException e) {
                UIUtils.showErrorDialog(activeShell, CoreMessages.actions_navigator_bookmark_error_title, CoreMessages.actions_navigator_bookmark_error_message, e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Shell(org.eclipse.swt.widgets.Shell) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 12 with DBNDatabaseNode

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

the class NavigatorHandlerCopyAbstract method copySelection.

private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
    ClipboardData clipboardData = new ClipboardData();
    {
        IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
        if (clipboardSource != null) {
            clipboardSource.addClipboardData(getCopyMode(), clipboardData);
        }
    }
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        List<DBNNode> selectedNodes = new ArrayList<>();
        List<DBPNamedObject> selectedObjects = new ArrayList<>();
        List<String> selectedFiles = new ArrayList<>();
        StringBuilder buf = new StringBuilder();
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object object = iter.next();
            String objectValue = getObjectDisplayString(object);
            if (objectValue == null) {
                continue;
            }
            DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
            DBPNamedObject dbObject = null;
            if (node instanceof DBNDatabaseNode) {
                dbObject = ((DBNDatabaseNode) node).getObject();
            }
            if (dbObject == null) {
                dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
            }
            if (node != null) {
                selectedNodes.add(node);
            }
            if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
                final IFile file = (IFile) ((DBNResource) node).getResource();
                if (file != null) {
                    selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
                }
            }
            if (dbObject != null) {
                selectedObjects.add(dbObject);
            }
            if (buf.length() > 0) {
                buf.append(GeneralUtils.getDefaultLineSeparator());
            }
            buf.append(objectValue);
        }
        {
            if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
                clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
            }
            if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
                clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
            }
            if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
                clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
            }
            if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
                clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
            }
        }
    }
    if (clipboardData.hasData()) {
        clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
        ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
    }
}
Also used : IClipboardSource(org.jkiss.dbeaver.ui.IClipboardSource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ClipboardData(org.jkiss.dbeaver.ui.ClipboardData) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 13 with DBNDatabaseNode

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

the class ResultSetViewer method openResultsInNewWindow.

private void openResultsInNewWindow(DBRProgressMonitor monitor, DBSEntity targetEntity, final DBDDataFilter newFilter) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext == null) {
        return;
    }
    final DBNDatabaseNode targetNode = executionContext.getDataSource().getContainer().getPlatform().getNavigatorModel().getNodeByObject(monitor, targetEntity, false);
    if (targetNode == null) {
        UIUtils.showMessageBox(null, "Open link", "Can't navigate to '" + DBUtils.getObjectFullName(targetEntity, DBPEvaluationContext.UI) + "' - navigator node not found", SWT.ICON_ERROR);
        return;
    }
    DBeaverUI.asyncExec(new Runnable() {

        @Override
        public void run() {
            openNewDataEditor(targetNode, newFilter);
        }
    });
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 14 with DBNDatabaseNode

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

the class NodeListControl method getListBaseTypes.

@Nullable
@Override
protected Class<?>[] getListBaseTypes(Collection<DBNNode> items) {
    // Collect base types for root node
    if (getRootNode() instanceof DBNDatabaseNode) {
        DBNDatabaseNode dbNode = (DBNDatabaseNode) getRootNode();
        List<Class<?>> baseTypes = dbNode.getChildrenTypes(nodeMeta);
        // Collect base types for inline children
        return CommonUtils.isEmpty(baseTypes) ? null : baseTypes.toArray(new Class<?>[baseTypes.size()]);
    } else {
        return null;
    }
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) Nullable(org.jkiss.code.Nullable)

Example 15 with DBNDatabaseNode

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

the class NodeListControl method createContentProvider.

private static IContentProvider createContentProvider(DBNNode node, DBXTreeNode metaNode) {
    if (node instanceof DBNDatabaseNode) {
        final DBNDatabaseNode dbNode = (DBNDatabaseNode) node;
        if (metaNode == null) {
            metaNode = dbNode.getMeta();
        }
        final List<DBXTreeNode> inlineMetas = collectInlineMetas(dbNode, metaNode);
        if (!inlineMetas.isEmpty()) {
            return new TreeContentProvider() {

                @Override
                public boolean hasChildren(Object parentElement) {
                    return parentElement instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentElement).hasChildren(false);
                }

                @Override
                public Object[] getChildren(Object parentElement) {
                    if (parentElement instanceof DBNDatabaseNode) {
                        try {
                            // Read children with void progress monitor because inline children SHOULD be already cached
                            DBNNode[] children = NavigatorUtils.getNodeChildrenFiltered(VoidProgressMonitor.INSTANCE, (DBNDatabaseNode) parentElement, false);
                            if (ArrayUtils.isEmpty(children)) {
                                return null;
                            } else {
                                return children;
                            }
                        } catch (DBException e) {
                            log.error(e);
                        }
                    }
                    return null;
                }
            };
        }
    }
    return new ListContentProvider();
}
Also used : TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) DBXTreeNode(org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode) DBException(org.jkiss.dbeaver.DBException) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)165 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)64 DBException (org.jkiss.dbeaver.DBException)60 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)60 InvocationTargetException (java.lang.reflect.InvocationTargetException)38 ArrayList (java.util.ArrayList)29 GridData (org.eclipse.swt.layout.GridData)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)21 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)20 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)20 ISelection (org.eclipse.jface.viewers.ISelection)16 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)13 Collection (java.util.Collection)12 Composite (org.eclipse.swt.widgets.Composite)12 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)12 IEditorPart (org.eclipse.ui.IEditorPart)11