///<summary>
/// Builds a Panel for a single Tab as defined in the <see cref="UIForm"/>.
/// There will be one <see cref="IPanelInfo"/> for the defined uiForm.<br/>
/// If there are multiple tabs defined for the <paramref name="uiForm"/> then
/// an actual <see cref="ITabPage"/> is created for each <see cref="UIFormTab"/>
/// and the <see cref="IPanel"/> created by <see cref="BuildPanelForTab"/> will
/// be placed on this TabPage.<br></br>
/// Else the <see cref="IPanel"/> is placed on the form directly.
///</summary>
/// <param name="uiForm">The UIForm object that indicates which controls
/// to create and how the controls are laid out</param>
///<param name="groupControlCreator">The <see cref="GroupControlCreator"/></param>
/// <returns>Returns an IPanelInfo object that contains access to the
/// BusinessObject instance, the created panel, and all the controls,
/// mappers, labels and error providers that were created.
/// </returns>
public IPanelInfo BuildPanelForForm(IUIForm uiForm, GroupControlCreator groupControlCreator)
{
if (uiForm == null)
{
throw new ArgumentNullException("uiForm");
}
if (groupControlCreator == null)
{
throw new ArgumentNullException("groupControlCreator");
}
var panelInfo = new PanelInfo();
// generic interface
foreach (UIFormTab formTab in uiForm)
{
var tabPagePanelInfo = BuildPanelForTab(formTab);
panelInfo.PanelInfos.Add(tabPagePanelInfo);
foreach (PanelInfo.FieldInfo fieldInfo in tabPagePanelInfo.FieldInfos)
{
panelInfo.FieldInfos.Add(fieldInfo);
}
if (tabPagePanelInfo.MinimumPanelHeight > panelInfo.MinimumPanelHeight)
{
panelInfo.MinimumPanelHeight = tabPagePanelInfo.MinimumPanelHeight;
}
}
IPanel mainPanel;
if (panelInfo.PanelInfos.Count == 0)
{
mainPanel = ControlFactory.CreatePanel();
}
else if (panelInfo.PanelInfos.Count == 1)
{
mainPanel = panelInfo.PanelInfos[0].Panel;
int lesserHeight = panelInfo.MinimumPanelHeight;
if (uiForm.Height < lesserHeight)
{
lesserHeight = uiForm.Height;
}
mainPanel.MinimumSize = new Size(uiForm.Width, lesserHeight);
}
else
{
var groupControl = groupControlCreator();
foreach (var childPanelInfo in panelInfo.PanelInfos)
{
var uiFormTab = childPanelInfo.UIFormTab;
var childPanel = childPanelInfo.Panel;
groupControl.AddControl(childPanel, uiFormTab.Name, childPanel.Height, childPanel.Width);
}
var panel = ControlFactory.CreatePanel();
groupControl.Dock = DockStyle.Fill;
panel.MinimumSize = groupControl.Size;
panel.Controls.Add(groupControl);
mainPanel = panel;
}
panelInfo.Panel = mainPanel;
mainPanel.Name = _controlNamingStrategy.GetUIFormControlName(uiForm);
mainPanel.Size = new Size(uiForm.Width, uiForm.Height);
panelInfo.UIForm = uiForm;
return(panelInfo);
}