use of org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput 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.ui.editors.IDatabaseEditorInput 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;
}
use of org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput in project dbeaver by serge-rider.
the class NavigatorHandlerObjectBase method getCommandTarget.
protected static CommandTarget getCommandTarget(IWorkbenchWindow workbenchWindow, DBNContainer container, Class<?> childType, boolean openEditor) throws DBException {
final Object parentObject = container.getValueObject();
DBSObject objectToSeek = null;
if (parentObject instanceof DBSObject) {
final DBEStructEditor parentStructEditor = EntityEditorsRegistry.getInstance().getObjectManager(parentObject.getClass(), DBEStructEditor.class);
if (parentStructEditor != null && RuntimeUtils.isTypeSupported(childType, parentStructEditor.getChildTypes())) {
objectToSeek = (DBSObject) parentObject;
}
}
if (objectToSeek != null) {
for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
final IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IDatabaseEditor) {
final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
if (editorInput.getDatabaseObject() == objectToSeek) {
workbenchWindow.getActivePage().activate(editor);
switchEditorFolder(container, editor);
return new CommandTarget((IDatabaseEditor) editor);
}
}
}
if (openEditor && container instanceof DBNDatabaseNode) {
final IDatabaseEditor editor = (IDatabaseEditor) NavigatorHandlerObjectOpen.openEntityEditor((DBNDatabaseNode) container, null, workbenchWindow);
if (editor != null) {
switchEditorFolder(container, editor);
return new CommandTarget(editor);
}
}
}
if (container instanceof DBNDatabaseNode) {
// No editor found - create new command context
DBPDataSource dataSource = ((DBNDatabaseNode) container).getObject().getDataSource();
if (dataSource != null) {
return new CommandTarget(new SimpleCommandContext(dataSource.getDefaultContext(true), !openEditor));
}
}
return new CommandTarget();
}
use of org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput in project dbeaver by serge-rider.
the class NavigatorHandlerObjectDelete method deleteNewObject.
private boolean deleteNewObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node) throws DBException {
for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
final IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IDatabaseEditor) {
final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
if (editorInput.getDatabaseObject() == node.getObject()) {
ConfirmResult confirmResult = confirmObjectDelete(workbenchWindow, node, false);
if (confirmResult == ConfirmResult.NO) {
return true;
}
// Just close editor
// It should dismiss new object and remove navigator node
workbenchWindow.getActivePage().closeEditor(editor, false);
return true;
}
}
}
return false;
}
use of org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput in project dbeaver by serge-rider.
the class DatabaseDataEditor method activatePart.
@Override
public void activatePart() {
createResultSetView();
IDatabaseEditorInput editorInput = getEditorInput();
boolean suspendQuery = CommonUtils.toBoolean(editorInput.getAttribute(ATTR_SUSPEND_QUERY));
DBDDataFilter dataFilter = (DBDDataFilter) editorInput.getAttribute(ATTR_DATA_FILTER);
if (!loaded && !suspendQuery) {
if (getDatabaseObject() != null && getDatabaseObject().isPersisted()) {
resultSetView.setStatus("Query data from '" + editorInput.getDatabaseObject().getName() + "'...");
if (dataFilter == null) {
resultSetView.refresh();
} else {
resultSetView.refreshWithFilter(dataFilter);
}
loaded = true;
}
}
//resultSetView.setSelection(resultSetView.getSelection());
}
Aggregations