use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class NavigatorHandlerObjectRename method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structSelection = (IStructuredSelection) selection;
Object element = structSelection.getFirstElement();
if (element instanceof DBNNode) {
renameNode(HandlerUtil.getActiveWorkbenchWindow(event), (DBNNode) element, null);
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method refreshNavigator.
public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
Job refreshJob = new AbstractJob("Refresh navigator object(s)") {
public Throwable error;
@Override
protected IStatus run(DBRProgressMonitor monitor) {
addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (error != null) {
UIUtils.showErrorDialog(null, "Refresh", "Error refreshing node", error);
}
}
});
Set<DBNNode> refreshedSet = new HashSet<>();
for (DBNNode node : refreshObjects) {
if (node.isDisposed() || node.isLocked()) {
// Skip locked nodes
continue;
}
// Check this node was already refreshed
if (!refreshedSet.isEmpty()) {
boolean skip = false;
for (DBNNode refreshed : refreshedSet) {
if (node == refreshed || node.isChildOf(refreshed)) {
skip = true;
break;
}
}
if (skip) {
continue;
}
}
setName("Refresh '" + node.getNodeName() + "'...");
try {
DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
if (refreshed != null) {
refreshedSet.add(refreshed);
}
} catch (Throwable ex) {
error = ex;
}
}
return Status.OK_STATUS;
}
};
refreshJob.setUser(true);
refreshJob.schedule();
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView;
if (workbenchPart instanceof INavigatorModelView) {
navigatorView = (INavigatorModelView) workbenchPart;
} else {
navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
}
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.
the class NavigatorHandlerFilterConfig method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
configureFilters(HandlerUtil.getActiveShell(event), node);
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNNode 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;
}
Aggregations