Beispiel #1
0
        /// <summary>
        /// Add input control to client pane.
        /// </summary>
        /// <param name="clientControl"></param>
        /// <param name="count"></param>
        /// <param name="prop"></param>
        private void AddControlToClientPane(TableLayoutPanel clientControl, int count,
                                            PropertyModelView.OptionItemPropertyDescriptor prop)
        {
            Control inputControl;

            inputControl = itemFactory.AddItemControl(prop, clientControl, count);
            propertyControlMapping.Add(prop.ID, inputControl);
//      clientControl.RowStyles.Add(new RowStyle(SizeType.AutoSize));
        }
        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();
//      }
        }
Beispiel #3
0
 /// <summary>
 /// Create new view that is associated to the given OptionHandler
 /// </summary>
 public DescriptorProxy(PropertyDescriptorCollection descriptors)
 {
     //no GC problem here
     this._descriptorCache = descriptors;
     foreach (PropertyDescriptor entry in descriptors)
     {
         PropertyModelView.OptionItemPropertyDescriptor desc =
             entry as PropertyModelView.OptionItemPropertyDescriptor;
         if (desc != null)
         {
             desc.PropertyChanged += OnPropertyChanged;
         }
     }
 }
 private void SaveCollapsedState(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)
         {
             collapseState[item.FullyQualifiedName] = currentItem.Expanded;
             //scan all children
         }
         SaveCollapsedState(currentItem);
     }
 }
Beispiel #5
0
        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return(delegateEditor.GetPaintValueSupported(context));
            }

            PropertyModelView.OptionItemPropertyDescriptor desc =
                context.PropertyDescriptor as PropertyModelView.OptionItemPropertyDescriptor;
            if (desc != null)
            {
                object value = desc.GetValue(null);
                if (value == OptionItem.VALUE_UNDEFINED)
                {
                    return(true);
                }
            }
            return(delegateEditor.GetPaintValueSupported(context));
        }
Beispiel #6
0
        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            //todo: fix this for dialog editor
//            if (context == null)
//            {
//                return true;
//            }
            if (delegateEditor != null)
            {
                return(delegateEditor.GetPaintValueSupported(context));
            }

            PropertyModelView.OptionItemPropertyDescriptor desc =
                context.PropertyDescriptor as PropertyModelView.OptionItemPropertyDescriptor;
            if (desc != null)
            {
                object value = desc.GetValue(null);
                if (value == OptionItem.VALUE_UNDEFINED)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #7
0
        internal virtual object CreateUIEditor(PropertyModelView.OptionItemPropertyDescriptor desc)
        {
            OptionItem item = desc.Item;
//      EditorAttribute editorAttribute =
//        TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(EditorAttribute)]
//        as EditorAttribute;

//      UITypeEditor coreEditor;
//      if (editorAttribute.EditorTypeName != "") {
//        //attribute set, get the converter that is set by the attribute
//        coreEditor = TypeDescriptor.GetProperties(item, false)["Value"].GetEditor();
//      } else {
//        //no attribute, delegate to base
//        coreEditor = TypeDescriptor.GetConverter(item.Type);
//      }

            object       editor    = TypeDescriptor.GetEditor(desc.PropertyType, typeof(UITypeEditor));
            UITypeEditor _delegate = editor as UITypeEditor;

            object editorOverride = item.GetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR);

            if (editorOverride != null)
            {
                if (editorOverride is Type)
                {
                    try {
                        UITypeEditor o = System.Activator.CreateInstance((Type)editorOverride) as UITypeEditor;
                        if (o != null)
                        {
                            _delegate = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create UI editor instance");
                    }
                }
                else if (editorOverride is string)
                {
                    try {
                        UITypeEditor o =
                            System.Activator.CreateInstance(Type.GetType((string)editorOverride)) as UITypeEditor;
                        if (o != null)
                        {
                            _delegate = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create UI editor instance");
                    }
                }
                else if (editorOverride is UITypeEditor)
                {
                    _delegate = (UITypeEditor)editorOverride;
                }
                else
                {
                    Trace.WriteLine("Invalid type for UI editor attribute");
                }
            }

//      if(_delegate != null && _delegate is EnumUITypeEditor) {
//        IItemRenderer renderer = GetRenderer(item);
//        if(renderer != null) {
//          ((EnumUITypeEditor) _delegate).Renderer = renderer;
//        }
//      }

            bool supportNull  = (bool)desc.Item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE);
            bool supportUndef = (bool)desc.Item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE);

            if (supportNull)
            {
                return(_delegate == null
                 ? (supportUndef ? new UndefinedValueUITypeEditor() : editor)
                 :
                       new NullableUITypeEditor(_delegate));
            }
            else
            {
                return(supportUndef ? new UndefinedValueUITypeEditor(_delegate) : _delegate);
            }
        }
Beispiel #8
0
        internal virtual TypeConverter CreateConverter(PropertyModelView.OptionItemPropertyDescriptor desc,
                                                       I18NFactory i18NFactory, string context)
        {
            OptionItem             item          = desc.Item;
            TypeConverterAttribute converterAttr =
                TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(TypeConverterAttribute)]
                as TypeConverterAttribute;

            TypeConverter coreConverter;

            if (desc is PropertyModelView.ListPropertyDescriptor && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter =
                    new I18NTypeConverter(((PropertyModelView.ListPropertyDescriptor)desc).GetStringRepresentation(),
                                          (bool)
                                          item.GetAttribute(
                                              CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE));
            }
            else if (item is ICollectionSupport && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter = new ListTypeConverter(((ICollectionSupport)item).Domain,
                                                      ((ICollectionSupport)item).EntryType,
                                                      (bool)
                                                      item.GetAttribute(
                                                          CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE),
                                                      i18NFactory, desc.I18nKey, context);
            }
            else if (converterAttr.ConverterTypeName != "")
            {
                //attribute set, get the converter that is set by the attribute
                coreConverter = TypeDescriptor.GetProperties(item, false)["Value"].Converter;
            }
            else
            {
                //no attribute, delegate to base
                coreConverter = TypeDescriptor.GetConverter(item.Type);
            }

            //TypeConverter coreConverter = converterAttr.ConverterTypeName != "" ? itemConverter : base.Converter;
            //todo: make this dependent on item attribute
            bool   supportNull             = (bool)item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE);
            bool   supportUndefined        = (bool)item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE);
            string nullValueRepresentation = item.GetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE) as string;

            if (i18NFactory != null)
            {
                nullValueRepresentation = PropertyModelView.GetLocalizedString(
                    i18NFactory, context, desc.I18nKey + ".VALUE.", nullValueRepresentation);
            }
            //test for overrides
            object converterOverride = item.GetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE);

            if (converterOverride != null)
            {
                if (converterOverride is TypeConverter)
                {
                    return((TypeConverter)converterOverride);
                }
                if (converterOverride is Type)
                {
                    try {
                        TypeConverter o = System.Activator.CreateInstance((Type)converterOverride) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else if (converterOverride is string)
                {
                    try {
                        TypeConverter o =
                            System.Activator.CreateInstance(Type.GetType((string)converterOverride)) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else
                {
                    Trace.WriteLine("Invalid type for converter attribute");
                }
            }
            if (supportNull || supportUndefined)
            {
                //custom conversions needed...
                if (coreConverter is ExpandableObjectConverter ||
                    coreConverter is FontConverter ||
                    coreConverter is PointConverter
                    )
                {
                    return(new ExpandableNullableTypeConverter(coreConverter,
                                                               supportNull,
                                                               supportUndefined,
                                                               nullValueRepresentation == null
                                                       ? ""
                                                       : nullValueRepresentation));
                }
                else
                {
                    return(new NullableTypeConverter(coreConverter,
                                                     supportNull,
                                                     supportUndefined,
                                                     nullValueRepresentation == null ? "" : nullValueRepresentation));
                }
            }
            return(coreConverter);
        }
Beispiel #9
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);
            }