@Nullable
    public static DBPDataSourceContainer getActiveDataSourceContainer(IEditorPart activeEditor, IWorkbenchPart activePart, ISelection selection) {
        if (activeEditor != null) {
            DBPDataSourceContainer container = getDataSourceContainerFromPart(activeEditor);
            if (container != null) {
                return container;
            }
            return null;
        }
        DBPDataSourceContainer container = getDataSourceContainerFromPart(activePart);
        if (container != null) {
            return container;
        }

        DBSObject selectedObject = NavigatorUtils.getSelectedObject(selection);
        if (selectedObject instanceof DBPDataSourceContainer) {
            return (DBPDataSourceContainer) selectedObject;
        } else if (selectedObject != null) {
            DBPDataSource dataSource = selectedObject.getDataSource();
            return dataSource == null ? null : dataSource.getContainer();
        }

        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