private void CollapseChildren(GridItem gi)
        {
            if (gi == null)
            {
                return;
            }
            foreach (GridItem currentItem in gi.GridItems)
            {
                PropertyDescriptor desc = currentItem.PropertyDescriptor;
                PropertyModelView.OptionItemPropertyDescriptor item = desc as PropertyModelView.OptionItemPropertyDescriptor;
                if (item != null)
                {
                    bool oldState;
                    bool existed = collapseState.TryGetValue(item.FullyQualifiedName, out oldState);
                    if (existed)
                    {
                        currentItem.Expanded = oldState;
                        CollapseChildren(currentItem);
                    }
                    else
                    {
                        object attr = item.GetAttribute(TableEditorFactory.RENDERING_HINTS_ATTRIBUTE);
                        if (attr != null)
                        {
                            TableEditorFactory.RenderingHints attrValue = (TableEditorFactory.RenderingHints)attr;
                            if ((attrValue & TableEditorFactory.RenderingHints.Collapsed) == TableEditorFactory.RenderingHints.Collapsed)
                            {
                                currentItem.Expanded = false;
                            }
                            else
                            {
                                currentItem.Expanded = true;
                                //scan all children
                                CollapseChildren(currentItem);
                            }
                        }
                        else
                        {
                            currentItem.Expanded = true;
                            //scan all children
                            CollapseChildren(currentItem);
                        }
                    }
                }
                else
                {
                    currentItem.Expanded = true;
                    //scan all children
                    CollapseChildren(currentItem);
                }
            }
//      if(gi.GridItems.Count > 0) {
//        collapseState.Clear();
//      }
        }
Пример #2
0
            public Control AddItemControl(PropertyModelView.OptionItemPropertyDescriptor prop,
                                          TableLayoutPanel clientControl, int count)
            {
                System.Windows.Forms.Binding viewBinding;
                bool   span          = false;
                string bindingTarget = "Value";

                Control inputControl = prop.GetAttribute(OptionItem.CUSTOM_DIALOGITEM_EDITOR) as Control;

                if (inputControl != null && inputControl is IDialogItemControl)
                {
                    span = true;
                }
                else
                {
                    Type editorType = prop.GetAttribute(OptionItem.CUSTOM_DIALOGITEM_EDITOR) as Type;
                    if (editorType != null)
                    {
                        Control c = System.Activator.CreateInstance(editorType) as Control;
                        if (c != null && c is IDialogItemControl)
                        {
                            inputControl = c;
                            span         = true;
                        }
                    }
                    else
                    {
                        //now build default editors
                        if (prop is PropertyModelView.OptionGroupPropertyDescriptor)
                        {
                            inputControl =
                                new DialogSectionControl(_enclosingInstance, prop.GetChildProperties(), prop, true);
                            span = true;
                            //don't bind...
                            bindingTarget = null;
                        }
                        else if (prop.Type == typeof(bool))
                        {
                            //checkbox for bools
                            inputControl = new CheckBoxWrapper();
                            bool supportUndefined =
                                (bool)prop.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE);
                            ((CheckBoxWrapper)inputControl).ThreeState = supportUndefined &&
                                                                         prop.GetValue(this) ==
                                                                         OptionItem.VALUE_UNDEFINED;
                        }
                        else
                        {
                            inputControl = new GenericValueEditor(prop);
                        }
                    }
                }
                inputControl.Size = inputControl.GetPreferredSize(new Size());

                clientControl.Controls.Add(inputControl, 1, count);
                _enclosingInstance.inputControls.Add(inputControl);
                inputControl.Anchor  = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top;
                inputControl.Enabled = prop.Enabled;


                if (span)
                {
                    clientControl.SetColumnSpan(inputControl, 2);
                }
                else
                {
                    Label inputLabel = new Label();
                    inputLabel.AutoSize  = true;
                    inputLabel.TextAlign = ContentAlignment.MiddleLeft;
                    inputLabel.Text      = prop.DisplayName + ":";

                    //todo: needs serious overhaul...
                    inputLabel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
                    clientControl.Controls.Add(inputLabel, 0, count);
                }
                if (bindingTarget != null)
                {
                    viewBinding =
                        new System.Windows.Forms.Binding(bindingTarget,
                                                         _enclosingInstance.bindingSource, prop.Name, true,
                                                         DataSourceUpdateMode.OnPropertyChanged);

                    inputControl.DataBindings.Add(viewBinding);
                }
                return(inputControl);
            }