Search in sources :

Example 1 with INavigatorModelView

use of org.jkiss.dbeaver.ui.navigator.INavigatorModelView 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 INavigatorModelView

use of org.jkiss.dbeaver.ui.navigator.INavigatorModelView in project dbeaver by serge-rider.

the class NavigatorHandlerObjectGoto method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = null;
    DBSObject container = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        context = ((DBPContextProvider) activePart).getExecutionContext();
    } else if (activePart instanceof INavigatorModelView) {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBSWrapper) {
                DBSObject object = ((DBSWrapper) element).getObject();
                if (object != null) {
                    container = object;
                    while (container instanceof DBSFolder) {
                        container = container.getParentObject();
                    }
                    DBPDataSource dataSource = object.getDataSource();
                    if (dataSource != null) {
                        context = dataSource.getDefaultContext(true);
                    }
                }
            }
        }
    }
    if (context == null) {
        DBUserInterface.getInstance().showError("Go to object", "No active datasource");
        return null;
    }
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
    dialog.open();
    Object[] objectsToOpen = dialog.getResult();
    if (!ArrayUtils.isEmpty(objectsToOpen)) {
        Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
        for (DBNDatabaseNode node : nodes) {
            NavigatorUtils.openNavigatorNode(node, workbenchWindow);
        }
    }
    return null;
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 3 with INavigatorModelView

use of org.jkiss.dbeaver.ui.navigator.INavigatorModelView in project dbeaver by serge-rider.

the class WorkbenchContextListener method partDeactivated.

@Override
public void partDeactivated(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (activationNavigator != null && part instanceof INavigatorModelView) {
            contextService.deactivateContext(activationNavigator);
            activationNavigator = null;
        }
        if (activationSQL != null && part instanceof SQLEditorBase) {
            contextService.deactivateContext(activationSQL);
            activationSQL = null;
        }
    } finally {
        contextService.deferUpdates(false);
    }
//        log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView)

Aggregations

INavigatorModelView (org.jkiss.dbeaver.ui.navigator.INavigatorModelView)3 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IContextService (org.eclipse.ui.contexts.IContextService)1 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)1 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBSFolder (org.jkiss.dbeaver.model.struct.DBSFolder)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)1 IRefreshablePart (org.jkiss.dbeaver.ui.IRefreshablePart)1 GotoObjectDialog (org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog)1 IDatabaseEditorInput (org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput)1 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)1