public static DBCExecutionContext getActiveExecutionContext(ExecutionEvent event, boolean useEditor) {
        if (useEditor) {
            IEditorPart editor = HandlerUtil.getActiveEditor(event);
            if (editor instanceof DBPContextProvider) {
                return ((DBPContextProvider) editor).getExecutionContext();
            }
            return null;
        }
        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);

        if (activePart instanceof DBPContextProvider) {
            return ((DBPContextProvider) activePart).getExecutionContext();
        }

        ISelection selection = HandlerUtil.getCurrentSelection(event);
        DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
        if (selectedObject != null) {
            return DBUtils.getDefaultContext(selectedObject, false);
        }

        return null;
    }
Get execution context from active editor or active selection
plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/actions/AbstractDataSourceHandler.java