public static DBPDataSourceContainer getDataSourceContainerFromPart(IWorkbenchPart activePart) {
        if (activePart instanceof DBPDataSourceContainerProvider) {
            return ((DBPDataSourceContainerProvider) activePart).getDataSourceContainer();
        }
        if (activePart instanceof DBPContextProvider) {
            DBCExecutionContext context = ((DBPContextProvider) activePart).getExecutionContext();
            return context == null ? null : context.getDataSource().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