classdef VerticalHierarchicalGridDraw < GUIBase
    %TABLEGRIDDRAW Draw a TableGrid into a uipanel
    %   Draws a 2D Grid inside a uipanel (Yay!)
    
    properties
        my_grid = []
        controls = {}
        root_controls = [];
        
        gui_params = []
        
        pb_new = []
        pb_delete = []
    end
    
    methods
        function object = VerticalHierarchicalGridDraw(my_grid, gui_params)
            if nargin == 1
                gui_params = GUIParameters();
            end
            
           object.my_grid = my_grid;
           object.gui_params = gui_params;
           
           object.root_controls = struct();
           object.root_controls.pb_new = -1;
           object.root_controls.pb_delete = -1;
           
           my_grid.addlistener('StructureChanged', @(src, event)redraw_and_update_bb(object, src, event));
        end
    end
    
    methods
        function recurse_delete(object, controls)
            delete(controls.control);
            if ishandle(controls.pb_extend)
                delete(controls.pb_extend);
            end
            if ishandle(controls.cell_controls.pb_new)
                delete(controls.cell_controls.pb_new);
                delete(controls.cell_controls.pb_delete);
            end
            for i = 1:size(controls.subgrid, 2)
                object.recurse_delete(controls.subgrid{i});
            end
        end
    end
    
end

