use of org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase 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;
}
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 || (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;
}
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 || (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;
}
Aggregations