private void checkBoxCreateNewEntity_CheckedChanged(object sender, EventArgs e)
        {
            // Only proceed if it is checked.
            if (checkBoxCreateNewEntity.Checked == false)
            {
                return;
            }

            switch (RequestorType)
            {
            case RequestorTypes.Entity_Select_Existing:
                labelSelectText.Text = "Select entity:";
                PopulateItemsForEntity();
                listViewEx1.Enabled = checkBoxSelectExistingEntity.Checked;
                break;

            case RequestorTypes.Entity_Select_Child:
                labelSelectText.Visible = false;
                PopulateItemsForEntity();
                listViewEx1.Enabled = true;
                break;

            case RequestorTypes.Entity_Select_Parent:
                labelSelectText.Text = "Select properties to promote to parent:";
                MultiSelect          = true;
                PopulateItemsForEntity();
                listViewEx1.Enabled    = true;
                listViewEx1.CheckBoxes = true;
                break;

            case RequestorTypes.Table:
                labelSelectText.Text = "Select columns to create properties:";
                //MultiSelect = true;
                PopulateItemsForEntity();
                //listViewEx1.Enabled = true;
                //listViewEx1.CheckBoxes = true;
                break;

            default:
                throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString());
            }
            buttonOk.Enabled = checkBoxCreateNewEntity.Checked || SelectedItems.Count > 0;
            textBoxName.Focus();
        }
        private void Populate()
        {
            #region Set hierarchy heading
            List <ITable> mappedTables = Entity.MappedTables().ToList();

            if (mappedTables.Count == 0)
            {
                labelHierarchyWarning.Visible = true;
                inheritanceHierarchy1.Visible = false;
                labelHierarchyHeader.Text     = "  Create an inheritance hierarchy from a single table, based on a discriminator.";
                labelHierarchyWarning.Text    = "  Can't create hierarchy - entity must be mapped to exactly 1 table. It has none.";
            }
            else if (mappedTables.Count > 1)
            {
                labelHierarchyWarning.Visible = true;
                inheritanceHierarchy1.Visible = false;
                labelHierarchyHeader.Text     = "  Create an inheritance hierarchy from a single table, based on a discriminator.";
                labelHierarchyWarning.Text    = string.Format("  Can't create hierarchy - entity must be mapped to exactly 1 table. It has {0}.", mappedTables.Count);
            }
            else
            {
                labelHierarchyWarning.Visible = false;
                inheritanceHierarchy1.Visible = true;
                inheritanceHierarchy1.Table   = mappedTables[0];
                labelHierarchyHeader.Text     = string.Format("  Create an inheritance hierarchy from this table [{0}], based on a discriminator.", mappedTables[0].Name);
            }
            #endregion

            #region Set Select Existing Entity Warning

            #endregion

            #region Hide/show controls
            switch (RequestorType)
            {
            case RequestorTypes.Entity_Select_Child:

                tabCreateHierarchy.Visible      = Entity.Children.Count == 0;
                tabCreateAbstractParent.Visible = false;
                textBoxName.Visible             = false;
                labelSelectText.Visible         = true;
                break;

            case RequestorTypes.Entity_Select_Parent:
            case RequestorTypes.Entity_Select_Existing:
            case RequestorTypes.Component:
                textBoxName.Visible     = true;
                labelSelectText.Visible = true;
                break;

            case RequestorTypes.Table:
                textBoxName.Visible     = true;
                labelSelectText.Text    = "Select existing entity:";
                labelSelectText.Visible = true;
                break;

            case RequestorTypes.Entity_Create_Abstract_Parent:
                Text = "Create abstract parent";
                //tabSelectEntity.Visible = false;
                //tabCreateHierarchy.Visible = false;
                textBoxName.Visible     = false;
                labelSelectText.Text    = "Select properties to extract to parent:";
                labelSelectText.Top     = 15;
                labelSelectText.Visible = true;
                break;

            default:
                throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString());
            }
            #endregion

            #region Populate Entities ListView

            listViewEntities.Items.Clear();
            listViewEntities.MultiSelect = MultiSelectEntities;

            switch (RequestorType)
            {
            case RequestorTypes.Entity_Select_Existing:
                labelSelectText.Text = "Select entity:";
                break;

            case RequestorTypes.Entity_Select_Child:
                labelSelectText.Visible = true;

                if (Entity.IsAbstract)
                {
                    labelSelectEntitiesHeading.Text = "  Table Per Concrete Class inheritance";
                    labelSelectText.Text            = "Select child entities (only entities with properties matching abstract parent):";
                    labelWarningSelectEntity.Text   = "  No entities with properties matching abstract parent";
                }
                else
                {
                    labelSelectText.Text = "Select child entities:";
                }

                listViewEntities.Enabled    = true;
                listViewEntities.CheckBoxes = true;
                break;

            case RequestorTypes.Entity_Select_Parent:
                labelSelectText.Text        = "Select parent entity:";
                listViewEntities.Enabled    = true;
                listViewEntities.CheckBoxes = false;
                break;

            case RequestorTypes.Table:
                labelSelectText.Text        = "Select existing entity:";
                listViewEntities.Enabled    = true;
                listViewEntities.CheckBoxes = false;
                break;

            default:
                throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString());
            }
            #endregion

            #region Populate Properties ListView
            switch (RequestorType)
            {
            case RequestorTypes.Entity_Select_Existing:
                labelSelectText.Text = "Select entity:";
                PopulateItemsForEntity();
                break;

            case RequestorTypes.Entity_Select_Child:
                //labelSelectText.Visible = false;
                PopulateItemsForEntity();
                listViewProperties.Enabled = true;
                break;

            case RequestorTypes.Entity_Select_Parent:
                //MultiSelectEntities = true;
                PopulateItemsForEntity();
                listViewProperties.Enabled    = true;
                listViewProperties.CheckBoxes = true;
                break;

            case RequestorTypes.Table:
                labelSelectText.Text = "Select columns to create properties:";
                PopulateItemsForEntity();
                break;

            default:
                throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString());
            }
            #endregion

            switch (RequestorType)
            {
            case RequestorTypes.Entity_Select_Existing:
            case RequestorTypes.Entity_Select_Child:
            case RequestorTypes.Entity_Select_Parent:
            case RequestorTypes.Entity_Create_Abstract_Parent:
                break;

            case RequestorTypes.Component:
                foreach (Entity entity in ComponentSpecification.EntitySet.Entities.Where(en => !UnavailableEntities.Contains(en)))
                {
                    listViewEntities.Items.Add(new ListViewItem(entity.Name)
                    {
                        Tag = entity
                    });
                }
                break;

            case RequestorTypes.Table:
                foreach (Entity entity in Table.Database.MappingSet.EntitySet.Entities.Where(en => !UnavailableEntities.Contains(en)))
                {
                    listViewEntities.Items.Add(new ListViewItem(entity.Name)
                    {
                        Tag = entity
                    });
                }
                break;

            default:
                throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString());
            }
            if (SelectedEntity != null)
            {
                foreach (ListViewItem item in listViewEntities.Items)
                {
                    if (item.Tag == SelectedEntity)
                    {
                        item.Selected = true;
                    }
                    else
                    {
                        item.Selected = false;
                    }
                }
            }
            listViewEntities.Focus();
        }