Search in sources :

Example 1 with NavigatorViewBase

use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase in project dbeaver by serge-rider.

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView) {
        if (activeEditor instanceof SQLEditor) {
            IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
            if (file != null) {
                showResourceInNavigator(navigatorView, file);
            }
        } else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
            IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
            showResourceInNavigator(navigatorView, editorFile);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull final DBSObject activeObject;
        if (dsContainer != null) {
            DBPDataSource dataSource = dsContainer.getDataSource();
            if (dataSource != null) {
                activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
            } else {
                activeObject = dsContainer;
            }
            final NavigatorViewBase view = navigatorView;
            DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    DBSObject showObject = activeObject;
                    if (showObject instanceof DBPDataSource) {
                        showObject = ((DBPDataSource) showObject).getContainer();
                    }
                    DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                    if (objectNode != null) {
                        view.showNode(objectNode);
                    }
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with NavigatorViewBase

use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase in project dbeaver by serge-rider.

the class NavigatorHandlerLocalFolderCreate method createFolder.

public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
    if (newName == null) {
        newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
    }
    if (CommonUtils.isEmpty(newName)) {
        return false;
    }
    // Create folder and refresh databases root
    // DS container will reload folders on refresh
    final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
    DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
    for (DBNDataSource node : nodes) {
        node.setFolder(folder);
    }
    if (parentFolder != null && activePart instanceof NavigatorViewBase) {
        final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        if (viewer != null) {
            DBeaverUI.asyncExec(new Runnable() {

                @Override
                public void run() {
                    viewer.expandToLevel(parentFolder, 1);
                }
            });
        }
    }
    DBNModel.updateConfigAndRefreshDatabases(databases);
    return true;
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Example 3 with NavigatorViewBase

use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase in project dbeaver by dbeaver.

the class NavigatorHandlerExpandAll method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof NavigatorViewBase) {
        TreeViewer navigatorViewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        ISelection selection = navigatorViewer.getSelection();
        if (selection.isEmpty()) {
            navigatorViewer.expandAll();
        } else if (selection instanceof IStructuredSelection) {
            for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                navigatorViewer.expandToLevel(iter.next(), TreeViewer.ALL_LEVELS);
            }
        }
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with NavigatorViewBase

use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase in project dbeaver by dbeaver.

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView) {
        if (activeEditor instanceof SQLEditor) {
            IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
            if (file != null) {
                showResourceInNavigator(navigatorView, file);
            }
        } else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
            IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
            showResourceInNavigator(navigatorView, editorFile);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull final DBSObject activeObject;
        if (dsContainer != null) {
            DBPDataSource dataSource = dsContainer.getDataSource();
            if (dataSource != null) {
                activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
            } else {
                activeObject = dsContainer;
            }
            final NavigatorViewBase view = navigatorView;
            DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {

                @Override
                public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    DBSObject showObject = activeObject;
                    if (showObject instanceof DBPDataSource) {
                        showObject = ((DBPDataSource) showObject).getContainer();
                    }
                    DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                    if (objectNode != null) {
                        view.showNode(objectNode);
                    }
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ProjectFileEditorInput(org.jkiss.dbeaver.ui.editors.ProjectFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) NotNull(org.jkiss.code.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 5 with NavigatorViewBase

use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase in project dbeaver by serge-rider.

the class NavigatorHandlerLocalFolderCreate method createFolder.

public static boolean createFolder(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, DBNProjectDatabases databases, final DBNLocalFolder parentFolder, final Collection<DBNDataSource> nodes, String newName) {
    if (newName == null) {
        newName = EnterNameDialog.chooseName(workbenchWindow.getShell(), "Folder name");
    }
    if (CommonUtils.isEmpty(newName)) {
        return false;
    }
    // Create folder and refresh databases root
    // DS container will reload folders on refresh
    final DBPDataSourceRegistry dsRegistry = databases.getDataSourceRegistry();
    DBPDataSourceFolder folder = dsRegistry.addFolder(parentFolder == null ? null : parentFolder.getFolder(), newName);
    for (DBNDataSource node : nodes) {
        node.setFolder(folder);
    }
    if (parentFolder != null && activePart instanceof NavigatorViewBase) {
        final TreeViewer viewer = ((NavigatorViewBase) activePart).getNavigatorViewer();
        if (viewer != null) {
            UIUtils.asyncExec(() -> viewer.expandToLevel(parentFolder, 1));
        }
    }
    DBNModel.updateConfigAndRefreshDatabases(databases);
    return true;
}
Also used : DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DBPDataSourceFolder(org.jkiss.dbeaver.model.DBPDataSourceFolder) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)

Aggregations

NavigatorViewBase (org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase)18 IEditorPart (org.eclipse.ui.IEditorPart)8 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)6 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)6 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)6 ProjectExplorerView (org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView)6 IFile (org.eclipse.core.resources.IFile)4 ISelection (org.eclipse.jface.viewers.ISelection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 NotNull (org.jkiss.code.NotNull)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)4 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Iterator (java.util.Iterator)2 IViewPart (org.eclipse.ui.IViewPart)2