Exemplo n.º 1
0
        public PropertyListUserControl(ConfigurationItem item, EventHandler valueChangedHandler, int leftOffset, ConfigApiClient configApiClient, string toHaveFocus)
        {
            InitializeComponent();

            _configApiClient     = configApiClient;
            _valueChangedHandler = valueChangedHandler;

            if (item.EnableProperty != null)
            {
                EnabledCheckBox.Visible = true;
                EnabledCheckBox.Checked = item.EnableProperty.Enabled;
                EnabledCheckBox.Text    = item.EnableProperty.DisplayName;
            }
            else
            {
                EnabledCheckBox.Visible = false;
                textBoxName.Location    = EnabledCheckBox.Location;
            }

            textBoxName.Text = item.DisplayName;

            int totalContentHeight = this.Height;            // panelContent.Location.Y;

            totalContentHeight += PanelUtils.BuildPropertiesUI(item, 0, leftOffset, panelContent, valueChangedHandler, _configApiClient, toHaveFocus);

            if (!item.ChildrenFilled)                   //TODO exception stuff, or load elsewhere
            {
                try
                {
                    item.Children       = _configApiClient.GetChildItems(item.Path);
                    item.ChildrenFilled = true;
                } catch (Exception ex)
                {
                    MessageBox.Show(String.Format("GetChildItems({0}) : {1}", item.Path, ex.Message));
                }
            }

            if (item.Children != null)
            {
                leftOffset += Constants.LeftIndentChildControl;
                foreach (ConfigurationItem child in item.Children)
                {
                    if ((child.Children == null || child.Children.Length == 0) && child.EnableProperty != null)
                    {
                        UserControl uc = new PropertyEnableUserControl(child, valueChangedHandler, leftOffset, _configApiClient, toHaveFocus);
                        uc.Width            = panelContent.Width;
                        uc.Location         = new Point(Constants.LeftIndentChildControl, panelContent.Height);
                        uc.Anchor           = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        this.Height        += uc.Height;
                        totalContentHeight += uc.Height;
                        panelContent.Controls.Add(uc);
                    }
                    else
                    {
                        UserControl uc = new PropertyListUserControl(child, valueChangedHandler, leftOffset, _configApiClient, toHaveFocus);
                        uc.Width            = panelContent.Width;
                        uc.Location         = new Point(Constants.LeftIndentChildControl, panelContent.Height);
                        uc.Anchor           = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        this.Height        += uc.Height;
                        totalContentHeight += uc.Height;
                        panelContent.Controls.Add(uc);
                    }
                }
                //panelContent.Height = totalContentHeight;
            }
            this.Height = totalContentHeight;
        }
        private void InitalizeUI(string propertyToFocus = null)
        {
            buttonSave.Enabled = (_item.ItemCategory != ItemCategories.Group);

            scrollPanel1.Clear();
            _originalName        = _item.DisplayName;
            textBoxName.Text     = _item.DisplayName;
            textBoxName.ReadOnly = true;

            if (_item.EnableProperty != null)
            {
                EnabledCheckBox.Text       = _item.EnableProperty.DisplayName;
                EnabledCheckBox.Checked    = _item.EnableProperty.Enabled;
                scrollPanel1.EnableContent = _item.EnableProperty.Enabled || !_item.EnableProperty.UIToFollowEnabled;
            }
            else
            {
                EnabledCheckBox.Visible = false;
            }

            pictureBox1.Image = UI.Icons.IconListBlack.Images[UI.Icons.GetImageIndex(_item.ItemType)];

            if (!_item.ChildrenFilled)
            {
                try
                {
                    _item.Children = _configApiClient.GetChildItems(_item.Path);
                }
                catch (Exception)
                {
                    _item.Children = new ConfigurationItem[0];
                }
                _item.ChildrenFilled = true;
            }

            int top = 10; // panelId.Height;

            if (_item.Properties != null)
            {
                top = ConfigAPIClient.Panels.PanelUtils.BuildPropertiesUI(_item, top, 0, scrollPanel1, ValueChangedHandler, _configApiClient, propertyToFocus);
                if (_item.ItemType == ItemTypes.PrivacyMask)
                {
                    _privacyMaskUserControl          = new UI.PrivacyMaskUserControl(_item, _configApiClient);
                    _privacyMaskUserControl.Location = new Point(80, top);
                    top += _privacyMaskUserControl.Height + 10;
                    scrollPanel1.Add(_privacyMaskUserControl);
                }
                else if (_item.ItemType == ItemTypes.MotionDetection)
                {
                    _motionDetectMaskUserControl          = new UI.MotionDetectUserControl(_item, _privacyMaskItem, _configApiClient);
                    _motionDetectMaskUserControl.Location = new Point(80, top);
                    top += _motionDetectMaskUserControl.Height + 10;
                    scrollPanel1.Add(_motionDetectMaskUserControl);
                }
                else
                {
                    _privacyMaskUserControl      = null;
                    _motionDetectMaskUserControl = null;
                }
            }

            // Show command buttons
            if (_item.MethodIds != null && _item.MethodIds.Length > 0)
            {
                foreach (String id in _item.MethodIds)
                {
                    if (_configApiClient.AllMethodInfos.ContainsKey(id))
                    {
                        MethodInfo mi = _configApiClient.AllMethodInfos[id];
                        Button     b  = new Button()
                        {
                            Text = mi.DisplayName, Tag = mi, UseVisualStyleBackColor = true
                        };
                        ToolTip toolTip = new ToolTip();
                        toolTip.SetToolTip(b, mi.MethodId);
                        int width = mi.DisplayName.Length < 20 ? 150 : 300;
                        b.Size     = new System.Drawing.Size(width, 24);
                        b.Location = new Point(10, top);
                        top       += b.Height + 10;
                        b.Click   += PerformAction;
                        scrollPanel1.Add(b);
                    }
                }
            }

            if (_showChildren && _item.Children != null)
            {
                int leftOffset = Constants.LeftIndentChildControl;
                foreach (ConfigurationItem child in _item.Children)
                {
                    if (MainForm._navItemTypes.Contains(child.ItemType))    // Do not repeat what is on the navigation tree
                    {
                        continue;
                    }

                    if ((child.Children == null || child.Children.Length == 0) && child.EnableProperty != null)
                    {
                        UserControl uc = new PropertyEnableUserControl(child, ValueChangedHandler, leftOffset, _configApiClient, null);
                        uc.Width    = scrollPanel1.Width;
                        uc.Location = new Point(leftOffset, top);
                        uc.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        top        += uc.Height;
                        scrollPanel1.Add(uc);
                    }
                    else
                    {
                        UserControl uc = new PropertyListUserControl(child, ValueChangedHandler, leftOffset, _configApiClient, null);
                        uc.Width    = scrollPanel1.Width;
                        uc.Location = new Point(leftOffset, top);
                        uc.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                        top        += uc.Height;
                        scrollPanel1.Add(uc);
                    }

                    if (_item.ItemCategory == ItemCategories.Group)
                    {
                        // Add save button on individual items as group can not be saved
                        Button b = new Button()
                        {
                            Text = "Save", Tag = child, UseVisualStyleBackColor = true
                        };
                        b.Size     = new System.Drawing.Size(75, 24);
                        b.Location = new Point(10, top);
                        top       += b.Height + 10;
                        b.Click   += PerformItemSave;
                        scrollPanel1.Add(b);
                    }
                }
            }

            if (propertyToFocus == null)
            {
                scrollPanel1.ScrollToTop();
            }
        }