Search in sources :

Example 1 with IDatabaseEditorInput

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;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IRefreshablePart(org.jkiss.dbeaver.ui.IRefreshablePart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with IDatabaseEditorInput

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;
}
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 IDatabaseEditorInput

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();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IEditorReference(org.eclipse.ui.IEditorReference) SimpleCommandContext(org.jkiss.dbeaver.ui.SimpleCommandContext) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBEStructEditor(org.jkiss.dbeaver.model.edit.DBEStructEditor) IEditorPart(org.eclipse.ui.IEditorPart) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Example 4 with IDatabaseEditorInput

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;
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IEditorPart(org.eclipse.ui.IEditorPart) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Example 5 with IDatabaseEditorInput

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());
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter)

Aggregations

IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)6 IEditorPart (org.eclipse.ui.IEditorPart)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)3 IEditorReference (org.eclipse.ui.IEditorReference)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 IDatabaseEditor (org.jkiss.dbeaver.ui.editors.IDatabaseEditor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 Canvas (org.eclipse.swt.widgets.Canvas)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 NotNull (org.jkiss.code.NotNull)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)1