Ejemplo n.º 1
0
        /// <summary>
        ///     Crea la etiqueta.
        /// </summary>
        protected virtual Control CreateLabel(string name)
        {
            IFormModel formModel = this.FormModel;

            PropertyDescription propDescription = formModel.GetDescription(name);

            Label label = new Label();

            label.Name         = name + "_label";
            label.Text         = propDescription.Label;
            label.AutoEllipsis = this.LabelAutoEllipsis;
            label.TextAlign    = this.LabelTextAlign;
            label.AutoSize     = this.LabelAutoSize;
            label.Anchor       = this.LabelAnchor;
            label.Dock         = this.LabelDock;
            label.Padding      = this.LabelPadding;
            label.Margin       = this.LabelMargin;

            string description = propDescription.Description;

            if (!string.IsNullOrEmpty(description))
            {
                ToolTip toolTip = new ToolTip();
                toolTip.SetToolTip(label, description);
            }

            return(label);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Crea el editor.
        /// </summary>
        protected virtual Control CreateEditor(string name, ErrorProvider errorProvider)
        {
            IFormModel formModel = this.FormModel;

            PropertyDescription propDescription = formModel.GetDescription(name);
            Type tipo = formModel.GetPropertyType(name);

            // Se busca la fabrica de editores.
            IEditorFactory editorFactory = propDescription.EditorFactory ?? this.DefaultEditorFactory;

            Contract.Assert(editorFactory != null);

            ViewProperties[] viewProperties  = formModel.GetViewProperties(name).ToArray();
            IServiceProvider serviceProvider = this.GetServiceProvider();

            // Se crea el control mediante la fabrica de editores.
            Control editor = (Control)editorFactory.Create(tipo, viewProperties, serviceProvider);

            if (editor == null)
            {
                Log <FormViewControl <TControl> > .ErrorFormat("No se encuentra mapeo para la propiedad de formulario {0} [{1}]", formModel, name);

                editor      = new System.Windows.Forms.Label();
                editor.Text = "<ERROR>";
            }

            //editor.Site = mySite;
            editor.Name     = name;
            editor.Enabled  = true;
            editor.AutoSize = this.EditorAutoSize;
            editor.Anchor   = this.EditorAnchor;
            editor.Dock     = this.EditorDock;
            editor.Padding  = this.EditorPadding;
            editor.Margin   = this.EditorMargin;

            string description = propDescription.Description;

            if (!string.IsNullOrEmpty(description))
            {
                ToolTip toolTip = new ToolTip();
                toolTip.SetToolTip(editor, description);
            }

            ControlExchange exchange = ControlExchange.Get(editor);

            if (exchange != null)
            {
                exchange.PopertyName = name;
            }

            return(editor);
        }
Ejemplo n.º 3
0
        protected IDictionary <string, PropertyData> BuildControls(bool showCategories)
        {
            IFormModel formModel = this.FormModel;

            Dictionary <string, Control>      categories = new Dictionary <string, Control>();
            Dictionary <string, PropertyData> lines      = new Dictionary <string, PropertyData>();

            if (formModel == null)
            {
                return(lines);
            }

            if (showCategories)
            {
                foreach (string category in formModel.GetCategories())
                {
                    Contract.Assert(!string.IsNullOrWhiteSpace(category));

                    Control categoryControl = this.CreateCategory(category);
                    categories.Add(category, categoryControl);
                }
            }

            foreach (string name in formModel.GetProperties())
            {
                try
                {
                    PropertyDescription propDescription = formModel.GetDescription(name);

                    PropertyData line = new PropertyData();
                    line.Name = name;

                    // Se crea y configura el editor.
                    Control editorControl = this.CreateEditor(name, this.ErrorProvider);
                    line.EditorControl = editorControl;

                    // Se trata la etiqueta.
                    if (!propDescription.HideLabel)
                    {
                        // Se crea y configura la etiqueta.
                        Control labelControl = this.CreateLabel(name);
                        line.LabelControl = labelControl;
                    }

                    string category = propDescription.Category;
                    line.Category = category;

                    if (showCategories)
                    {
                        Control categoryControl = categories[category];
                        line.CategoryControl = categoryControl;
                    }

                    lines.Add(name, line);
                }
                catch (Exception e)
                {
                    Log <FormViewControl <TControl> > .Error(e);
                }
            }

            return(lines);
        }