'Check whether the this tab is active
@param r: the S3Request'

def active(self, r):

    s3db = current.s3db
    get_components = s3db.get_components
    get_method = s3db.get_method
    get_vars = r.get_vars
    tablename = None
    if ('viewing' in get_vars):
        try:
            tablename = get_vars['viewing'].split('.', 1)[0]
        except:
            pass
    resource = r.resource
    component = self.component
    if component:
        clist = get_components(resource.table, names=[component])
        is_component = False
        if (component in clist):
            is_component = True
        elif tablename:
            clist = get_components(tablename, names=[component])
            if (component in clist):
                is_component = True
        if is_component:
            return self.authorised(clist[component])
        handler = get_method(resource.prefix, resource.name, method=component)
        if ((handler is None) and tablename):
            (prefix, name) = tablename.split('_', 1)
            handler = get_method(prefix, name, method=component)
        if (handler is None):
            handler = r.get_handler(component)
        if (handler is None):
            return (component in ('create', 'read', 'update', 'delete'))
    return True
