Search in sources :

Example 1 with ProjectExplorerView

use of org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView 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 ProjectExplorerView

use of org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView 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 3 with ProjectExplorerView

use of org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView in project dbeaver by dbeaver.

the class NavigateBookmarkHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    NavigatorViewBase activeNavigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (activeNavigatorView != null) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(HandlerUtil.getCurrentSelection(event));
        if (selectedNode instanceof DBNBookmark) {
            BookmarkStorage storage = ((DBNBookmark) selectedNode).getStorage();
            final DBPDataSourceContainer dataSourceContainer = DBUtils.findDataSource(storage.getDataSourceId());
            if (dataSourceContainer == null) {
                // $NON-NLS-2$
                log.debug("Can't find datasource '" + storage.getDataSourceId() + "'");
                return null;
            }
            final DBNDataSource dsNode = (DBNDataSource) DBNUtils.getNodeByObject(dataSourceContainer);
            if (dsNode == null) {
                // $NON-NLS-2$
                log.error("Can't find datasource node for '" + dataSourceContainer.getName() + "'");
                return null;
            }
            if (activeNavigatorView instanceof ProjectExplorerView) {
                // Show in DB navigator is we are currently in project explorer
                final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
                IViewPart dbNavigatorPart = activePage.findView(DatabaseNavigatorView.VIEW_ID);
                if (dbNavigatorPart instanceof NavigatorViewBase) {
                    activeNavigatorView = (NavigatorViewBase) dbNavigatorPart;
                    try {
                        activePage.showView(DatabaseNavigatorView.VIEW_ID);
                    } catch (PartInitException e) {
                        log.debug(e);
                    }
                }
            }
            NavigatorViewBase navigatorView = activeNavigatorView;
            try {
                dsNode.initializeNode(null, status -> {
                    if (status.isOK()) {
                        UIUtils.syncExec(() -> BookmarksHandlerImpl.navigateNodeByPath(navigatorView, dsNode, storage));
                    }
                });
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IViewPart(org.eclipse.ui.IViewPart) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BookmarkStorage(org.jkiss.dbeaver.ui.resources.bookmarks.BookmarkStorage) PartInitException(org.eclipse.ui.PartInitException) DBNBookmark(org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 4 with ProjectExplorerView

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

the class NavigateBookmarkHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    NavigatorViewBase activeNavigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (activeNavigatorView != null) {
        DBNNode selectedNode = NavigatorUtils.getSelectedNode(HandlerUtil.getCurrentSelection(event));
        if (selectedNode instanceof DBNBookmark) {
            BookmarkStorage storage = ((DBNBookmark) selectedNode).getStorage();
            final DBPDataSourceContainer dataSourceContainer = DBUtils.findDataSource(storage.getDataSourceId());
            if (dataSourceContainer == null) {
                // $NON-NLS-2$
                log.debug("Can't find datasource '" + storage.getDataSourceId() + "'");
                return null;
            }
            final DBNDataSource dsNode = (DBNDataSource) DBNUtils.getNodeByObject(dataSourceContainer);
            if (dsNode == null) {
                // $NON-NLS-2$
                log.error("Can't find datasource node for '" + dataSourceContainer.getName() + "'");
                return null;
            }
            if (activeNavigatorView instanceof ProjectExplorerView) {
                // Show in DB navigator is we are currently in project explorer
                final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
                IViewPart dbNavigatorPart = activePage.findView(DatabaseNavigatorView.VIEW_ID);
                if (dbNavigatorPart instanceof NavigatorViewBase) {
                    activeNavigatorView = (NavigatorViewBase) dbNavigatorPart;
                    try {
                        activePage.showView(DatabaseNavigatorView.VIEW_ID);
                    } catch (PartInitException e) {
                        log.debug(e);
                    }
                }
            }
            NavigatorViewBase navigatorView = activeNavigatorView;
            try {
                dsNode.initializeNode(null, status -> {
                    if (status.isOK()) {
                        UIUtils.syncExec(() -> BookmarksHandlerImpl.navigateNodeByPath(navigatorView, dsNode, storage));
                    }
                });
            } catch (DBException e) {
                log.error(e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) IViewPart(org.eclipse.ui.IViewPart) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BookmarkStorage(org.jkiss.dbeaver.ui.resources.bookmarks.BookmarkStorage) PartInitException(org.eclipse.ui.PartInitException) DBNBookmark(org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 5 with ProjectExplorerView

use of org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView 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 || (navigatorView instanceof ProjectNavigatorView && activeEditor instanceof ITextEditor)) {
        IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
        if (file != null) {
            showResourceInNavigator(navigatorView, file);
        }
    } 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 DBSObject activeObject = null;
        if (dsContainer != null) {
            if (activeEditor instanceof DBPContextProvider) {
                DBCExecutionContext executionContext = ((DBPContextProvider) activeEditor).getExecutionContext();
                if (executionContext != null) {
                    DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
                    if (contextDefaults != null) {
                        activeObject = contextDefaults.getDefaultSchema();
                        if (activeObject == null) {
                            activeObject = contextDefaults.getDefaultCatalog();
                        }
                    }
                }
            }
            if (activeObject == null) {
                DBPDataSource dataSource = dsContainer.getDataSource();
                if (dataSource != null) {
                    activeObject = DBUtils.getDefaultOrActiveObject(dataSource.getDefaultInstance());
                } else {
                    activeObject = dsContainer;
                }
            }
            DBSObject objectToSelect = activeObject;
            final NavigatorViewBase view = navigatorView;
            UIUtils.runInUI(activePage.getWorkbenchWindow(), monitor -> {
                DBSObject showObject = objectToSelect;
                if (showObject instanceof DBSInstance && !(showObject instanceof DBPDataSourceContainer)) {
                    showObject = objectToSelect.getParentObject();
                }
                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 : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) IEditorPart(org.eclipse.ui.IEditorPart) NotNull(org.jkiss.code.NotNull) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProjectNavigatorView(org.jkiss.dbeaver.ui.navigator.project.ProjectNavigatorView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)6 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)6 NavigatorViewBase (org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase)6 ProjectExplorerView (org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView)6 IFile (org.eclipse.core.resources.IFile)4 IEditorPart (org.eclipse.ui.IEditorPart)4 NotNull (org.jkiss.code.NotNull)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)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 IViewPart (org.eclipse.ui.IViewPart)2 PartInitException (org.eclipse.ui.PartInitException)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)2 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)2