Search in sources :

Example 16 with DBNNode

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

the class NavigatorHandlerObjectCreateNew method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node != null) {
        createNewObject(HandlerUtil.getActiveWorkbenchWindow(event), node, null);
    }
    return null;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection)

Example 17 with DBNNode

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

the class NavigatorActionSetActiveObject method run.

@Override
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(selection);
        if (selectedNode instanceof DBNDatabaseNode) {
            final DBNDatabaseNode databaseNode = (DBNDatabaseNode) selectedNode;
            final DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, databaseNode.getObject());
            if (activeContainer != null) {
                TasksJob.runTask("Select active object", new DBRRunnableWithProgress() {

                    @Override
                    public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            activeContainer.setDefaultObject(monitor, databaseNode.getObject());
                        } catch (DBException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with DBNNode

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

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

the class NavigatorHandlerAssociateScript method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell activeShell = HandlerUtil.getActiveShell(event);
    List<IFile> scripts = new ArrayList<>();
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
        for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
            final DBNNode node = RuntimeUtils.getObjectAdapter(iter.next(), DBNNode.class);
            if (node instanceof DBNResource) {
                IResource resource = ((DBNResource) node).getResource();
                if (resource instanceof IFile) {
                    scripts.add((IFile) resource);
                }
            }
        }
    }
    if (!scripts.isEmpty()) {
        DBPDataSourceContainer dataSourceDescriptor = SelectDataSourceDialog.selectDataSource(activeShell, scripts.get(0).getProject());
        if (dataSourceDescriptor != null) {
            for (IFile script : scripts) {
                EditorUtils.setFileDataSource(script, dataSourceDescriptor, true);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 20 with DBNNode

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

Aggregations

DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)40 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 DBException (org.jkiss.dbeaver.DBException)13 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)12 ISelection (org.eclipse.jface.viewers.ISelection)9 ArrayList (java.util.ArrayList)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 GridData (org.eclipse.swt.layout.GridData)5 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)5 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IFile (org.eclipse.core.resources.IFile)4 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)4 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)3 CSmartCombo (org.jkiss.dbeaver.ui.controls.CSmartCombo)3 IProject (org.eclipse.core.resources.IProject)2