Esempio n. 1
0
        private void RenderPartContentsInternal(HtmlTextWriter writer, EditorPart editorPart)
        {
            if (editorPart == null)
            {
                throw new ArgumentNullException("editorPart");
            }

            Style style2     = this.Zone.PartStyle;
            var   editorName = editorPart.GetType().Name;

            if (!style2.IsEmpty)
            {
                style2.AddAttributesToRender(writer, this.Zone);
            }

            AddAttributes(writer, editorPart);

            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            if (!editorName.Equals("PropertyEditorPart"))
            {
                PropertyFieldPanel.RenderBeginTagInternal(writer, editorPart.Title, editorPart.ID);
                PropertyFieldPanel.RenderContentsStart(writer);
            }
            this.RenderPartContents(writer, editorPart);
            if (!editorName.Equals("PropertyEditorPart"))
            {
                PropertyFieldPanel.RenderContentsEnd(writer);
                PropertyFieldPanel.RenderEndTagInternal(writer);
            }
            writer.RenderEndTag();

            this.EditorZone.EditorPartsAdded = true;
        }
Esempio n. 2
0
        public override bool ApplyChanges()
        {
            object editableObject = EditableObject;

            if (editableObject == null)
            {
                return(true);
            }

            EnsureChildControls();
            if (Controls.Count == 0)
            {
                return(true);
            }

            for (var i = 0; i < EditorControls.Count; i++)
            {
                object control     = EditorControls[i];
                var    placeHolder = control as PlaceHolder;
                if (placeHolder == null)
                {
                    continue;
                }

                foreach (var entry in _groupProperties)
                {
                    string title = entry.Key;
                    List <PropertyDescriptor> descriptors = entry.Value;

                    if (String.IsNullOrEmpty(title) || descriptors == null)
                    {
                        continue;
                    }

                    foreach (PropertyDescriptor descriptor in descriptors)
                    {
                        var editorControl = CreateEditorControl(descriptor);
                        if (editorControl == null)
                        {
                            continue;
                        }
                        var c = GetControlRecursive(placeHolder, editorControl.ID);
                        if (c == null)
                        {
                            continue;
                        }

                        try
                        {
                            object editorControlValue = GetEditorControlValue(c, descriptor);
                            descriptor.SetValue(editableObject, editorControlValue);
                        }
                        catch (Exception ex)
                        {
                            var panel        = c.Parent as PropertyFieldPanel;
                            var panelTitle   = panel == null ? "Unknown" : panel.Title;
                            var eField       = c as IEditorPartField;
                            var eFieldTitle  = eField == null ? "unknown field" : eField.Title;
                            var errorMessage = string.Format("{0} ({1} panel, {2} field)", ex.Message, panelTitle, eFieldTitle);

                            Logger.WriteException(ex);
                            _errorMessages.Add(errorMessage);
                            _errorNum++;
                        }
                    }
                }
            }

            if (HasError)
            {
                var errorGroupFieldPanel = new PropertyFieldPanel {
                    Title = "Error", EnableViewState = false
                };
                var erros = new StringBuilder();

                foreach (var errorMessage in _errorMessages)
                {
                    erros.Append(errorMessage + "<br />");
                }

                errorGroupFieldPanel.Controls.Add(new LiteralControl(erros.ToString()));

                var errorControl = Controls[0] as PlaceHolder;
                if (errorControl != null)
                {
                    errorControl.Controls.Add(errorGroupFieldPanel);
                }
            }

            return(HasError);
        }
Esempio n. 3
0
        // Internals //////////////////////////////////////////////////////////////
        private void CollectEditableProperties(object editableObject)
        {
            _groupProperties = new Dictionary <string, List <PropertyDescriptor> >();

            var controls = Controls;

            controls.Clear();
            EditorControls.Clear();
            controls.Add(new PlaceHolder());
            var properties = GetEditableProperties(editableObject);

            // grouping
            foreach (PropertyDescriptor descriptor in properties)
            {
                if ((this.HiddenProperties != null) && (this.HiddenProperties.Contains(descriptor.Name)))
                {
                    continue;
                }

                var categoryTitle = GetCategoryTitle(descriptor);
                if (HiddenCategories == null || !HiddenCategories.Contains(categoryTitle))
                {
                    if (!String.IsNullOrEmpty(categoryTitle))
                    {
                        List <PropertyDescriptor> categoryValue = null;
                        categoryValue = _groupProperties.ContainsKey(categoryTitle) ? _groupProperties[categoryTitle] : new List <PropertyDescriptor>();

                        categoryValue.Add(descriptor);
                        if (!_groupProperties.ContainsKey(categoryTitle))
                        {
                            _groupProperties.Add(categoryTitle, categoryValue);
                        }
                    }
                }

                if (_categories.Contains(categoryTitle) || String.IsNullOrEmpty(categoryTitle))
                {
                    continue;
                }
                _categories.Add(categoryTitle);
            }

            // create controls
            var editorControls = new PlaceHolder {
                ID = "GroupProperties", EnableViewState = false
            };

            foreach (var entry in _groupProperties)
            {
                var title = entry.Key;
                entry.Value.Sort(new WebOrderComparer());
                var descriptors = entry.Value;

                if (String.IsNullOrEmpty(title) || descriptors == null)
                {
                    continue;
                }

                var groupControl = new PropertyFieldPanel {
                    Title = title
                };
                groupControl.EnableViewState = false;
                foreach (var descriptor in descriptors)
                {
                    var editorControl = CreateEditorControl(descriptor);
                    if (editorControl == null)
                    {
                        continue;
                    }
                    editorControl.EnableViewState = false;
                    groupControl.Controls.Add(editorControl);
                }
                if (groupControl.Controls.Count > 0)
                {
                    editorControls.Controls.Add(groupControl);
                }
            }
            if (editorControls.Controls.Count == 0)
            {
                return;
            }
            EditorControls.Add(editorControls);
            controls.Add(editorControls);
        }