'Page load
@param r: the S3Request
@param attr: controller attributes'

def tree(self, r, **attr):

    output = {}
    tablename = self.resource.tablename
    widget_id = ('%s-hierarchy' % tablename)
    try:
        tree = self.render_tree(widget_id, record=r.record)
    except SyntaxError:
        r.error(405, ('No    hierarchy    configured    for    %s' % tablename))
    if r.record:
        title = self.crud_string(tablename, 'title_display')
    else:
        title = self.crud_string(tablename, 'title_list')
    output['title'] = title
    form = FORM(DIV(tree, _class='s3-hierarchy-tree'), _id=widget_id)
    output['form'] = form
    T = current.T
    crud_string = (lambda name: self.crud_string(tablename, name))
    widget_opts = {'widgetID': widget_id, 'openLabel': str(T('Open')), 'openURL': r.url(method='read', id='[id]'), 'ajaxURL': r.url(id=None, representation='json'), 'editLabel': str(T('Edit')), 'editTitle': str(crud_string('title_update')), 'editURL': r.url(method='update', id='[id]', representation='popup'), 'addLabel': str(T('Add')), 'addTitle': str(crud_string('label_create')), 'deleteLabel': str(T('Delete')), 'deleteURL': r.url(method='delete', id='[id]', representation='json'), 'addURL': r.url(method='create', representation='popup')}
    theme = current.deployment_settings.get_ui_hierarchy_theme()
    icons = theme.get('icons', False)
    if icons:
        widget_opts['icons'] = icons
    stripes = theme.get('stripes', True)
    if (not stripes):
        widget_opts['stripes'] = stripes
    self.include_scripts(widget_id, widget_opts)
    current.response.view = self._view(r, 'hierarchy.html')
    return output
