function grid_controls = draw_onto( object, parent_handle, grid, grid_controls)
%DRAW_ONTO Draws the controls onto the parent_handle.  This function needs to be called everytime an update happens.
%   This function draws the entire handle onto the handle.  This function
%   needs to be called everytime the back table is updated.  The class will
%   notify when its necessary.

    if nargin == 2
        %Need to invert y, so need total size
        [x, y] = object.get_bounding_box();
        
        object.controls = draw_onto(object, parent_handle, object.my_grid, object.controls);
       
        if ishandle(object.pb_delete)
            pb_delete = object.pb_delete;
        else
            pb_delete = uicontrol(parent_handle, 'Style', 'pushbutton', 'String', 'Remove', 'Callback', @(src, event)object.my_grid.delete_cell([], object.my_grid.get_cell(object.my_grid.length) ) );
            object.pb_delete = pb_delete;
        end
       
        if ishandle(object.pb_new)
            pb_new = object.pb_new;
        else
            pb_new = uicontrol(parent_handle, 'Style', 'pushbutton', 'String', 'Add', 'Callback', @(src, event)object.my_grid.add_cell([], []));
            object.pb_new = pb_new;
        end
        
        set(pb_delete, 'Position', [x-80, 0, 80, 20]);
        set(pb_new, 'Position', [x-80, 20, 80, 20]);
        
        return ;
    end

    % First delete an extra controls
    for i = grid.length()+1:size(grid_controls, 2)
        delete(grid_controls{i});
        grid_controls(i) = [];
    end
    assert( ~(size(grid_controls, 2) > grid.length()), 'Delete failed to shrink things appropriately.');
        
    for i = 1:grid.length()
        if size(grid_controls, 2) >= i && ishandle(grid_controls{i})
            delete(grid_controls{i});
        end
        grid_controls{i} = uicontrol(parent_handle, 'Style', 'edit', 'Position', [(i-1)*object.gui_params.edit_width, 0, object.gui_params.edit_width, object.gui_params.edit_height], 'String', grid.get_cell(i).get_user_string(), 'Callback', @(src,event)GUIHelpers.update_cell(src, event, grid.get_cell(i)) );
    end

end

