using System.Collections.Generic;
using Habanero.BO;
using Habanero.Faces.Base;
using <<|=BOPROJECTNAME|>>;

namespace <<|=PROJECTNAME|>>
{
    public class <<|=CLASSNAME+|>>GridControl : ControlManager
    {
        private IReadOnlyGridControl _readOnlyGridControl;

        public <<|=CLASSNAME+|>>GridControl(IControlFactory controlFactory) : base(controlFactory)
        {
        }

        protected override void InitialiseControl()
        {
            SetupGrid();
            AddGridFilters();
            LoadCollection();
        }

        private void SetupGrid()
        {
            _readOnlyGridControl = _controlFactory.CreateReadOnlyGridControl();
            BorderLayoutManager manager = _controlFactory.CreateBorderLayoutManager(_control);
            manager.AddControl(_readOnlyGridControl, BorderLayoutManager.Position.Centre);
        }

        private void AddGridFilters()
        {
            _readOnlyGridControl.FilterControl.Visible = false;
            //TODO: Add the filters you want and remove the above line
        }

        private void LoadCollection()
        {
            BusinessObjectCollection<<<|=CLASSNAME|>>> <<|=#CLASSNAME+|>> = new BusinessObjectCollection<<<|=CLASSNAME|>>>();
            <<|=#CLASSNAME+|>>.LoadAll();
            _readOnlyGridControl.SetBusinessObjectCollection(<<|=#CLASSNAME+|>>);
        }
    }
}