/// <summary>
    /// Removes the selected Property Definition.
    /// </summary>
    private void RemovePropertyDefinition()
    {
        // Need to get the selected domain
        Domain domain = propertyListCtl.GetSelectedDomain();

        if (domain != null)
        {
            // Have the user verify that we really want to remove the
            // selected object.
            MessageDialog dlg = new MessageDialog(this,
                                                  DialogFlags.DestroyWithParent,
                                                  MessageType.Question,
                                                  ButtonsType.YesNo,
                                                  string.Format("Are you sure you wish to remove property '{0}'?",
                                                                domain.GetValue("Name")));
            int result = dlg.Run();
            dlg.Destroy();

            if (result == ResponseType.Yes.value__)
            {
                log.InfoFormat("User chose to remove property '{0}'",
                               domain.GetValue("Name"));
                if (! domain.NewObject)
                {
                    domain.ForDelete = true;

                    if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
                    {
                        BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                        bdDlg.DoModal(this, domain);
                    }
                    // Now, delete the object.
                    if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
                    {
                        domain.Save();
                    }
                    propertyListCtl.RemoveSelected();
                }
            }
        }
    }
    /// <summary>
    /// Edits the selected Form
    /// </summary>
    private void EditForm()
    {
        log.Debug("Editing form");
        // Need to get the selected domain
        Domain domain = formListCtl.GetSelectedDomain();

        FormEntryDlg dlg = new FormEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on FormEntryDlg");
            if (domain.Dirty)
            {
                if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
                {
                    BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                    bdDlg.DoModal(this, domain);
                }
                if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
                {
                    domain.Save();
                }
                formListCtl.UpdateSelectedLabel();
            }
        }
    }
    /// <summary>
    /// Edits the selected Property Definition.
    /// </summary>
    private void EditPropertyDefinition()
    {
        // Need to get the selected domain
        Domain domain = propertyListCtl.GetSelectedDomain();

        PropertyDefinitionEntryDlg dlg = new PropertyDefinitionEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on PropertyDefinitionEntryDlg");
            if (domain.Dirty)
            {
                if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
                {
                    BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                    bdDlg.DoModal(this, domain);
                }
                if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
                {
                    domain.Save();
                }
                propertyListCtl.UpdateSelectedLabel();
            }
        }
    }
    /// <summary>
    /// Edits the selected application.
    /// </summary>
    private void EditApplication()
    {
        // Need to get the selected domain
        Domain domain = applicationListCtl.GetSelectedDomain();

        ApplicationEntryDlg dlg = new ApplicationEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on ApplicationEntryDlg");
            if (domain.Dirty)
            {
                if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
                {
                    BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                    bdDlg.DoModal(this, domain);
                }
                if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
                {
                    domain.Save();
                }
                applicationListCtl.UpdateSelectedLabel();
            }
        }
        log.DebugFormat("Application Name: {0}", domain.GetValue("Name"));
    }
    /// <summary>
    /// Adds a new Property Definition.
    /// </summary>
    private void AddPropertyDefinition()
    {
        // Create a new Application domain
        Domain selDomain = propertyListCtl.GetSelectedDomain();

        Domain domain = DomainFactory.Create("PropertyDefinition");
        if (selDomain != null)
        {
            domain.SetValue("Category", selDomain.GetValue("Category"));
        }

        PropertyDefinitionEntryDlg dlg = new PropertyDefinitionEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on PropertyDefinitionEntryDlg");
            if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
            {
                BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                bdDlg.DoModal(this, domain);
            }
            if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
            {
                domain.Save();
            }

            propertyListCtl.AddDomain(domain);
        }
    }
    /// <summary>
    /// Adds a new Form
    /// </summary>
    private void AddForm()
    {
        log.Debug("Adding new form");
        // Create a new Form domain
        Domain domain = DomainFactory.Create("Form");

        FormEntryDlg dlg = new FormEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on FormEntryDlg");
            if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
            {
                BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                bdDlg.DoModal(this, domain);
            }
            if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
            {
                domain.Save();
            }

            formListCtl.AddDomain(domain);
        }
    }
    /// <summary>
    /// Adds a new Dynamic Property.
    /// </summary>
    private void AddDynamicProperty()
    {
        log.Debug("Adding new Dynamic Property");
        // Create a new Dynamic Property domain
        Domain domain = DomainFactory.Create("DynamicProperty");
        Domain app = null;
        Domain prop = null;

        switch (dynPropertyListCtl.SelectedLevel)
        {
        case DynamicPropertyLevels.Application:
            app = dynPropertyListCtl.GetSelectedDomain();
            break;

        case DynamicPropertyLevels.Category:
            app = dynPropertyListCtl.GetSelectedDomainParent();
            break;

        case DynamicPropertyLevels.Property:
            app = dynPropertyListCtl.GetSelectedDomainGrandParent();
            prop = dynPropertyListCtl.GetSelectedDomain();
            break;
        }

        if (app != null)
        {
            domain.SetValue("ApplicationId", app.GetValue("Id"));
        }

        if (prop != null)
        {
            domain.SetValue("PropertyId", prop.GetValue("PropertyId"));
        }

        DynPropEntryDlg dlg = new DynPropEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on DynPropEntryDlg");
            if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
            {
                BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                bdDlg.DoModal(this, domain);
            }
            if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
            {
                domain.Save();
            }

            dynPropertyListCtl.AddDomain(domain);
        }
    }
    /// <summary>
    /// Adds a new application.
    /// </summary>
    private void AddApplication()
    {
        // Create a new Application domain
        Domain domain = DomainFactory.Create("Application");

        ApplicationEntryDlg dlg = new ApplicationEntryDlg();

        if (dlg.DoModal(this, domain))
        {
            log.Info("OK pressed on ApplicationEntryDlg");
            if (ConfigurationManager.AppSettings[DISPLAY_SQL_CFG].Equals("true"))
            {
                BufferDisplayDlg bdDlg = new BufferDisplayDlg();
                bdDlg.DoModal(this, domain);
            }
            if (ConfigurationManager.AppSettings[UPDATE_DB_CFG].Equals("true"))
            {
                domain.Save();
            }

            applicationListCtl.AddDomain(domain);
        }
    }