def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """

        factory       = self.factory
        self.filter   = factory.filter
        self.auto_add = (factory.auto_add and (factory.row_factory is not None))

        columns = factory.columns[:]
        if (len( columns ) == 0) and (len( self.value ) > 0):
            columns = [ ObjectColumn( name = name )
                        for name in self.value[0].editable_traits() ]
        self.columns = columns

        self.model = model = TableModel(
                                editor         = self,
                                reverse        = factory.reverse )
        model.on_trait_change( self._model_sorted, 'sorted', dispatch = 'ui' )
        mode     = factory.selection_mode
        row_mode = mode in ( 'row', 'rows' )
        selected = None
        items    = model.get_filtered_items()
        if factory.editable and (len( items ) > 0):
            selected = items[0]
        if (factory.edit_view == ' ') or (not row_mode):
            self.control = panel = TraitsUIPanel( parent, -1 )
            sizer        = wx.BoxSizer( wx.VERTICAL )
            self._create_toolbar( panel, sizer )

            # Create the table (i.e. grid) control:
            hsizer = wx.BoxSizer( wx.HORIZONTAL )
            self._create_grid( panel, hsizer )
            sizer.Add( hsizer, 1, wx.EXPAND )
        else:
            item         = self.item
            name         = item.get_label( self.ui )
            theme        = factory.dock_theme or item.container.dock_theme
            self.control = dw = DockWindow( parent, theme = theme ).control
            panel        = TraitsUIPanel( dw, -1, size = ( 300, 300 ) )
            sizer        = wx.BoxSizer( wx.VERTICAL )
            dc           = DockControl( name    = name + ' Table',
                                        id      = 'table',
                                        control = panel,
                                        style   = 'fixed' )
            contents     = [ DockRegion( contents = [ dc ] ) ]
            self._create_toolbar( panel, sizer )
            selected = None
            items    = model.get_filtered_items()
            if factory.editable and (len( items ) > 0):
                selected = items[0]

            # Create the table (i.e. grid) control:
            hsizer = wx.BoxSizer( wx.HORIZONTAL )
            self._create_grid( panel, hsizer )
            sizer.Add( hsizer, 1, wx.EXPAND )

            # Assign the initial object here, so a valid editor will be built
            # when the 'edit_traits' call is made:
            self.selected_row = selected
            self._ui = ui = self.edit_traits(
                     parent = dw,
                     kind   = 'subpanel',
                     view   = View( [ Item( 'selected_row',
                                          style  = 'custom',
                                          editor = InstanceEditor(
                                                       view = factory.edit_view,
                                                       kind = 'subpanel' ),
                                          resizable = True,
                                          width  = factory.edit_view_width,
                                          height = factory.edit_view_height ),
                                      '|<>' ],
                                    resizable = True,
                                    handler   = factory.edit_view_handler ) )

            # Set the parent UI of the new UI to our own UI:
            ui.parent = self.ui

            # Reset the object so that the sub-sub-view will pick up the
            # correct history also:
            self.selected_row = None
            self.selected_row = selected

            dc.style = item.dock
            contents.append( DockRegion( contents = [
                                 DockControl( name    = name + ' Editor',
                                              id      = 'editor',
                                              control = ui.control,
                                              style   = item.dock ) ] ) )

            # Finish setting up the DockWindow:
            dw.SetSizer( DockSizer( contents = DockSection(
                          contents = contents,
                          is_row   = (factory.orientation == 'horizontal') ) ) )

        # Set up the required externally synchronized traits (if any):
        sv      = self.sync_value
        is_list = (mode[-1] == 's')
        sv( factory.click,  'click',  'to' )
        sv( factory.dclick, 'dclick', 'to' )
        sv( factory.filter_name,  'filter',  'from' )
        sv( factory.columns_name, 'columns', is_list = True )
        sv( factory.filtered_indices, 'filtered_indices', 'to' )
        sv( factory.selected, 'selected_%s' % mode, is_list = is_list )
        if is_list:
            sv( factory.selected_indices, 'selected_%s_indices' % mode[:-1],
                is_list = True )
        else:
            sv( factory.selected_indices, 'selected_%s_index' % mode )

        # Listen for the selection changing on the grid:
        self.grid.on_trait_change(
            getattr( self, '_selection_%s_updated' % mode ),
            'selection_changed', dispatch = 'ui' )

        # Make sure the selection is initialized:
        if row_mode:
            self.set_selection( items[0:1] )
        else:
            self.set_selection()


        # Set the min height of the grid panel to 0, this will provide
        # a scrollbar if the window is resized such that only the first row
        # is visible
        panel.SetMinSize((-1, 0))

        # Finish the panel layout setup:
        panel.SetSizer( sizer )


    #---------------------------------------------------------------------------
    #  Creates the associated grid control used to implement the table:
    #---------------------------------------------------------------------------
dataset/ETHPy150Open enthought/traitsui/traitsui/wx/table_editor.py/TableEditor.init/original