Search in sources :

Example 1 with DBNBookmark

use of org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark 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 2 with DBNBookmark

use of org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark 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)

Aggregations

IViewPart (org.eclipse.ui.IViewPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 PartInitException (org.eclipse.ui.PartInitException)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 NavigatorViewBase (org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase)2 ProjectExplorerView (org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView)2 BookmarkStorage (org.jkiss.dbeaver.ui.resources.bookmarks.BookmarkStorage)2 DBNBookmark (org.jkiss.dbeaver.ui.resources.bookmarks.DBNBookmark)2