public TestContenItemControl(UIContentItem contentItem)
 {
     m_contentItem = contentItem;
     m_contentItem.StateChanged += new UIObjectStateChangedDelegate(m_contentItem_StateChanged);
     m_clientActionControl = m_contentItem.ClientActionControl;
     m_clientActionControl.ApplyToAllClicked += new EventHandler<EventArgs>(ctrl_ApplyToAllClicked);
     m_clientActionControl.ActionProperties = m_contentItem.ActionPropertySet;
 }
        public void AddClientActionControl(UIContentItem contentItem)
        {
            m_contentItems.Add(contentItem);
            IActionPropertySet propertySet = contentItem.ActionPropertySet;
            ClientActionControl clientActionControl = contentItem.ClientActionControl;
            m_containsApplyToAll = true; 
            // Doctor the action property set to make the "ApplyToAll" property invisible.
            try
            {
				IActionProperty prop;
				propertySet.TryGetValue("ApplyToAll", out prop);
				ActionPropertyFacade applyToAllProperty = (ActionPropertyFacade) prop;
				if (applyToAllProperty == null)
                {
                    m_containsApplyToAll = false;
                    m_selectAllState = true;
                    m_selectAllOverride = true;
                }
                else 
                {
                    applyToAllProperty.Visible = false;
                    m_selectAllOverride = false;
					if ((applyToAllProperty.Override == false) && ((bool)applyToAllProperty.Value))
					{
						m_selectAllState = true;
						m_selectAllOverride = true;
                }
            }
			}
            catch (InvalidCastException ice)
            {
				Logger.LogError("Invalid cast: UIContentItem.PropertySet[\"ApplyToAll\"] not ActionPropertyFacade");
				Logger.LogError(ice);
            }


            // Build the APPLYTOALL ClientActionControl
            if (m_applyToAllClientActionControl == null)
            {
                // HACK: Stops us creating the UIContentItem.ClientActionControl ....
                m_applyToAllClientActionControl = m_containsApplyToAll
                                                      ? contentItem.Action.Action2.ClientActionControl
                                                      : clientActionControl;
                m_applyToAllClientActionControl.Size = new Size(350, m_applyToAllClientActionControl.Height);
                m_applyToAllClientActionControl.Dock = DockStyle.Top;
                clientActionControlContainerPanel.Controls.Add(m_applyToAllClientActionControl);
                m_applyToAllClientActionControl.ApplyToAllClicked += clientActionControl_ApplyToAllClicked;
                m_applyToAllClientActionControl.Visible = false;
                m_controls.Add(m_applyToAllClientActionControl);
            }

            if (m_containsApplyToAll)
            {
                if (m_applyToAllActionPropertySet == null)
                {
                    m_applyToAllActionPropertySet = new ActionPropertySet();
                }
                MergePropertySets(propertySet, m_applyToAllActionPropertySet, m_contentItems.Count == 0);
            }
            else
            {
                m_applyToAllActionPropertySet = propertySet;
            }
			
			// Now we have the final propertySet we can assign it.
			clientActionControl.ActionProperties = propertySet;

            // Build the APPLYTOALL Execute Checkbox
            if (m_applyToAllExecuteCheckBox == null)
            {
                m_applyToAllExecuteCheckBox = new CheckBox();
                m_applyToAllExecuteCheckBox.Text = Properties.Resources.APPLY_ACTION_TEXT;
                m_applyToAllExecuteCheckBox.Dock = DockStyle.Left;
                m_applyToAllExecuteCheckBox.AutoSize = true;
                m_applyToAllExecuteCheckBox.Name = "APPLYTOALL";
                m_applyToAllExecuteCheckBox.Visible = executePanel.Controls.Count == 0;
                m_applyToAllExecuteCheckBox.CheckedChanged += executeCheckBox_CheckedChanged;
                // Hook up the execute
                executePanel.Controls.Add(m_applyToAllExecuteCheckBox);
				IActionProperty executeProperty;
				m_applyToAllActionPropertySet.TryGetValue(PropertyNames.Execute, out executeProperty);
                if (executeProperty != null)
                {
                    ExecutePropertyController.Hook(executeProperty, m_applyToAllExecuteCheckBox, "CheckedChanged", "Checked");
                }

                m_applyToAllClientActionControl.Tag = m_applyToAllExecuteCheckBox;
                m_applyToAllExecuteCheckBox.Tag = m_applyToAllClientActionControl;
            }

            if (!m_containsApplyToAll)
                return;
            
            // Check to see if the client action control instance already exists as some of the actions
            // have implemented a singleton for the ClientActionControl. This has consequences when attempting
            // sync of ActionProperty's.
			if (m_controls.Contains(clientActionControl))
			{
				m_singleton = true;
			}
            CheckBox executeCheckBox = new CheckBox();
            executeCheckBox.Text = Properties.Resources.APPLY_ACTION_TEXT;
            executeCheckBox.Dock = DockStyle.Left;
            executeCheckBox.AutoSize = true;
            executeCheckBox.Name = contentItem.Id;
            executeCheckBox.Visible = executePanel.Controls.Count == 0;
            executeCheckBox.CheckedChanged += executeCheckBox_CheckedChanged;
            
            // Hook up the execute
            executePanel.Controls.Add(executeCheckBox);
			IActionProperty execProperty;
			propertySet.TryGetValue(PropertyNames.Execute, out execProperty);
            if (execProperty != null)
            {
                ExecutePropertyController.Hook(execProperty, executeCheckBox, "CheckedChanged", "Checked");
            }

            
            // Add client action control to the checkbox TAG
            executeCheckBox.Tag = clientActionControl;

            if (m_singleton)
                return;
            clientActionControl.Name = contentItem.Id;
            clientActionControl.Tag = executeCheckBox;
            clientActionControl.Size = new Size(350, clientActionControl.Height);
            clientActionControl.Dock = DockStyle.Top;
            clientActionControlContainerPanel.Controls.Add(clientActionControl);
            m_controls.Add(clientActionControl);
            clientActionControl.Visible = false;
            // We're only doing this here to ensure the control has a stab at setup before the initial display.  
            // For some ClientActionControl implementations this does not work as the Visible property for controls
            // is linked to Parent.Visisble and makes the control !Visible regardless of any assignment.
            
        }