GetEditor() public method

Gets an editor of the specified type.

public GetEditor ( Type editorBaseType ) : object
editorBaseType System.Type
return object
コード例 #1
0
		public PropertyEditorCell GetEditor (PropertyDescriptor pd)
		{
			PropertyEditorCell cell = pd.GetEditor (typeof(PropertyEditorCell)) as PropertyEditorCell;
			if (cell != null)
				return cell;
			
			Type editorType = GetEditorType (pd);
			if (editorType == null)
				return Default;
			
			if (typeof(IPropertyEditor).IsAssignableFrom (editorType)) {
				if (!typeof(Gtk.Widget).IsAssignableFrom (editorType))
					throw new Exception ("The property editor '" + editorType + "' must be a Gtk Widget");
				return Default;
			}

			cell = cellCache [editorType] as PropertyEditorCell;
			if (cell != null)
				return cell;

			if (!typeof(PropertyEditorCell).IsAssignableFrom (editorType))
				throw new Exception ("The property editor '" + editorType + "' must be a subclass of Stetic.PropertyEditorCell or implement Stetic.IPropertyEditor");

			cell = (PropertyEditorCell) Activator.CreateInstance (editorType);
			cellCache [editorType] = cell;
			return cell;
		}
コード例 #2
0
        /// <summary>
        /// Parses annotations in schema sets. Override this to handle custom annotations.
        /// Supports annotations for property descriptors and palette items.</summary>
        /// <param name="schemaSet">XML schema sets being loaded</param>
        /// <param name="annotations">Dictionary of annotations in schema</param>
        protected override void ParseAnnotations(
            XmlSchemaSet schemaSet,
            IDictionary <NamedMetadata, IList <XmlNode> > annotations)
        {
            base.ParseAnnotations(schemaSet, annotations);

            IList <XmlNode> xmlNodes;

            foreach (DomNodeType nodeType in m_typeCollection.GetNodeTypes())
            {
                // parse XML annotation for property descriptors
                if (annotations.TryGetValue(nodeType, out xmlNodes))
                {
                    PropertyDescriptorCollection propertyDescriptors = Sce.Atf.Dom.PropertyDescriptor.ParseXml(nodeType, xmlNodes);

                    // Customizations
                    // The flags and enum support from annotation used to be in ATF 2.8.
                    //  Please request this feature from the ATF team if you need it and a ParseXml overload
                    //  can probably be created.
                    System.ComponentModel.PropertyDescriptor gameFlow = propertyDescriptors["Special Event"];
                    if (gameFlow != null)
                    {
                        FlagsUITypeEditor editor = (FlagsUITypeEditor)gameFlow.GetEditor(typeof(FlagsUITypeEditor));
                        editor.DefineFlags(new string[] {
                            "Reward==Give player the reward",
                            "Trophy==Give player the trophy",
                            "LevelUp==Level up",
                            "BossDies==Boss dies",
                            "PlayerDies==Player dies",
                            "EndCinematic==End cinematic",
                            "EndGame==End game",
                        });
                    }

                    nodeType.SetTag <PropertyDescriptorCollection>(propertyDescriptors);

                    // parse type annotation to create palette items
                    XmlNode xmlNode = FindElement(xmlNodes, "scea.dom.editors");
                    if (xmlNode != null)
                    {
                        string menuText = FindAttribute(xmlNode, "menuText");
                        if (menuText != null) // must have menu text and category
                        {
                            string description       = FindAttribute(xmlNode, "description");
                            string image             = FindAttribute(xmlNode, "image");
                            NodeTypePaletteItem item = new NodeTypePaletteItem(nodeType, menuText, description, image);
                            nodeType.SetTag <NodeTypePaletteItem>(item);
                        }
                    }
                }
            }
        }
コード例 #3
0
		/// <summary>
		/// Factory method for creating the appropriate drop-down control based on the given property descriptor.
		/// If the property descriptor supports a UITypeEditor, a TypeEditorHost will be created with that editor.
		/// If not, and the TypeConverver attached to the PropertyDescriptor supports standard values, a
		/// TypeEditorHostListBox will be created with this TypeConverter.
		/// </summary>
		/// <param name="propertyDescriptor">A property descriptor describing the property being set</param>
		/// <param name="instance">The object instance being edited</param>
		/// <param name="editControlStyle">The type of control to show in the edit area.</param>
		/// <returns>A TypeEditorHost instance if the given property descriptor supports it, null otherwise.</returns>
		public static new TypeEditorHost Create(PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
		{
			TypeEditorHost host = null;
			if (propertyDescriptor != null)
			{
				UITypeEditor editor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
				if (editor != null)
				{
					return new OnScreenTypeEditorHost(editor, propertyDescriptor, instance, editControlStyle);
				}
				TypeConverter typeConverter = propertyDescriptor.Converter;
				if ((typeConverter != null) && typeConverter.GetStandardValuesSupported(null))
				{
					host = new OnScreenTypeEditorHostListBox(typeConverter, propertyDescriptor, instance, editControlStyle);
				}
			}
			return host;
		}
コード例 #4
0
        /// <summary>
        /// Gets a UI type editor for the given property descriptor and context</summary>
        /// <param name="descriptor">Property descriptor</param>
        /// <param name="context">Type descriptor context</param>
        /// <returns>UI type editor for the given property descriptor and context</returns>
        public static UITypeEditor GetUITypeEditor(
            PropertyDescriptor descriptor,
            ITypeDescriptorContext context)
        {
            UITypeEditor editor = descriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
            if (editor == null)
            {
                if (StandardValuesUIEditor.CanCreateStandardValues(descriptor, context))
                {
                    editor = new StandardValuesUIEditor(descriptor);
                }
                else
                {
                    Type type = descriptor.PropertyType;
                    editor = TypeDescriptor.GetEditor(type, typeof(UITypeEditor)) as UITypeEditor;
                }
            }

            return editor;
        }
コード例 #5
0
		/// <summary>
		/// Invokes the editor for the items of the designed ImageListView.
		/// </summary>
		public void EditItems()
		{
			// IComponentChangeService is used to pass change notifications to the designer
			IComponentChangeService ccs = (IComponentChangeService)GetService(typeof(IComponentChangeService));

			// Get the collection editor
			itemProperty = GetPropertyByName("Items");
			UITypeEditor editor = (UITypeEditor)itemProperty.GetEditor(typeof(UITypeEditor));
			object value = imageListView.Items;

			// Notify the designers of the change
			if (ccs != null)
				ccs.OnComponentChanging(imageListView, itemProperty);

			// Edit the value
			value = editor.EditValue(this, this, value);
			imageListView.Items = (ImageListView.ImageListViewItemCollection)value;

			// Notify the designers of the change
			if (ccs != null)
				ccs.OnComponentChanged(imageListView, itemProperty, null, null);

			designerService.Refresh(Component);
		}
コード例 #6
0
        /// <summary>
        ///     Factory method for creating the appropriate drop-down control based on the given property descriptor.
        ///     If the property descriptor supports a UITypeEditor, a TypeEditorHost will be created with that editor.
        ///     If not, and the TypeConverver attached to the PropertyDescriptor supports standard values, a
        ///     TypeEditorHostListBox will be created with this TypeConverter.
        /// </summary>
        /// <param name="propertyDescriptor">A property descriptor describing the property being set</param>
        /// <param name="instance">The object instance being edited</param>
        /// <param name="editControlStyle">The type of control to show in the edit area.</param>
        /// <returns>A TypeEditorHost instance if the given property descriptor supports it, null otherwise.</returns>
        public static TypeEditorHost Create(
            PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
        {
            TypeEditorHost dropDown = null;

            if (propertyDescriptor != null)
            {
                var uiTypeEditor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (uiTypeEditor != null) // UITypeEditor case
                {
                    dropDown = new TypeEditorHost(uiTypeEditor, propertyDescriptor, instance, editControlStyle);
                }
                else
                {
                    var converter = propertyDescriptor.Converter;
                    if (converter != null
                        && converter.GetStandardValuesSupported(null)) // converter case
                    {
                        dropDown = new TypeEditorHostListBox(converter, propertyDescriptor, instance, editControlStyle);
                    }
                }
            }

            return dropDown;
        }
コード例 #7
0
 /// <summary>
 /// Invokes the editor for the columns of the designed ImageListView.
 /// </summary>
 public void EditColumns()
 {
     // TODO: Column editing cannot be undone in the designer.
     property = TypeDescriptor.GetProperties(imageListView)["Columns"];
     UITypeEditor editor = (UITypeEditor)property.GetEditor(typeof(UITypeEditor));
     object value = imageListView.Columns;// property.GetValue(imageListView);
     value = editor.EditValue(this, this, value);
     SetProperty("Columns", value);
     designerService.Refresh(Component);
 }
コード例 #8
0
        /// <summary>
        ///     Factory method for creating the appropriate drop-down control based on the given property descriptor
        /// </summary>
        /// <param name="propertyDescriptor">
        ///     Property descriptor used to create the drop-down.  If the property descriptor supports a UITypeEditor,
        ///     that will be used first.  Otherwise, the type converter will be used.
        /// </param>
        /// <param name="instance">Instance of the object being edited.</param>
        /// <param name="editStyle">
        ///     In the case that a UITypeEditor is used, controls the style of drop-down created.  This
        ///     parameter is not used in the TypeConverter case.
        /// </param>
        /// <returns>A DropDownControl instance if the given property descriptor supports it, null otherwise.</returns>
        internal static TypeEditorHost CreateTypeEditorHost(
            PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
        {
            TypeEditorHost dropDown = null;

            if (propertyDescriptor != null)
            {
                var uiTypeEditor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (uiTypeEditor != null) // UITypeEditor case
                {
                    dropDown = new TreeGridDesignerInPlaceEditDropDown(uiTypeEditor, propertyDescriptor, instance, editControlStyle);
                }
                else
                {
                    var converter = propertyDescriptor.Converter;
                    if (converter != null
                        && converter.GetStandardValuesSupported(null)) // converter case
                    {
                        dropDown = new TreeGridDesignerInPlaceEditCombo(converter, propertyDescriptor, instance, editControlStyle);
                    }
                }
            }

            return dropDown;
        }
コード例 #9
0
        /// <summary>
        /// EditRows
        /// </summary>
        private void EditRows()
        {
            _PropertyDescriptor = TypeDescriptor.GetProperties(_SuperGrid.PrimaryGrid)["Rows"];

            UITypeEditor editor = (UITypeEditor)_PropertyDescriptor.GetEditor(typeof(UITypeEditor));

            if (editor != null)
                editor.EditValue(this, this, _SuperGrid.PrimaryGrid.Rows);
        }
コード例 #10
0
        internal static Control CreateEditorControl(PropertyDescriptor descriptor)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            var propertyType = descriptor.PropertyType;
            object editor = null;
            
            try
            {
                editor = descriptor.GetEditor(typeof(IEditorPartField));
            }
            catch (Exception e)
            {
                Logger.WriteException(e);
            }

            var propName = descriptor.Name;

            if (editor != null)
            {
                var partField = editor as IEditorPartField;
                if (partField != null)
                {
                    partField.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                    partField.TitleContainerCssClass = "sn-iu-label";
                    partField.TitleCssClass = "sn-iu-title";
                    partField.DescriptionCssClass = "sn-iu-desc";
                    partField.ControlWrapperCssClass = "sn-iu-control";
                    partField.Title = GetDisplayName(descriptor);
                    partField.Description = GetDescription(descriptor);
                    partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
                    partField.PropertyName = propName;

                    if (propertyType == typeof (bool))
                        partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                    if (typeof (Enum).IsAssignableFrom(propertyType))
                    {
                        // TODO: fill the instance of the EditorPart control with datas. Best solution is extend the IEditorPartField interface with Fill method 
                    }
                    var result = partField as Control;
                    result.ID = "Custom" + propName;
                    return result;
                }
            }

            if (propertyType == typeof (bool))
            {
                var checkBox = new CheckBoxEditorPartField();
                checkBox.ID = "CheckBox" + propName;
                checkBox.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                checkBox.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                checkBox.Title = GetDisplayName(descriptor);
                checkBox.Description = GetDescription(descriptor);
                checkBox.TitleContainerCssClass = "sn-iu-label";
                checkBox.TitleCssClass = "sn-iu-title";
                checkBox.DescriptionCssClass = "sn-iu-desc";
                checkBox.ControlWrapperCssClass = "sn-iu-control";
                checkBox.PropertyName = propName;

                return checkBox;
            }

            if (typeof (Enum).IsAssignableFrom(propertyType))
            {
                ICollection standardValues = descriptor.Converter.GetStandardValues();
                if (standardValues != null)
                {
                    var list = new DropDownPartField();
                    list.ID = "DropDown" + propName;
                    list.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                    list.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-enum sn-editorpart-" + propName;
                    list.Title = GetDisplayName(descriptor);
                    list.Description = GetDescription(descriptor);
                    list.TitleContainerCssClass = "sn-iu-label";
                    list.TitleCssClass = "sn-iu-title";
                    list.DescriptionCssClass = "sn-iu-desc";
                    list.ControlWrapperCssClass = "sn-iu-control";
                    list.PropertyName = propName;
                    foreach (object value in standardValues)
                    {
                        var resourceKey = String.Concat("Enum-", propName, "-", value.ToString());
                        var text = SenseNetResourceManager.Current.GetStringOrNull("PortletFramework", resourceKey) as string;
                        if (string.IsNullOrEmpty(text))
                            text = descriptor.Converter.ConvertToString(value);
                        list.Items.Add(new ListItem(text, value.ToString()));
                    }
                    return list;
                }

                return null;
            }

            var textBox = new TextEditorPartField();
            textBox.ID = "TextBox" + propName;
            textBox.Options = GetEditorOptionsAttribute(descriptor.Attributes);
            textBox.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
            textBox.Title = GetDisplayName(descriptor);
            textBox.Description = GetDescription(descriptor);
            textBox.TitleContainerCssClass = "sn-iu-label";
            textBox.TitleCssClass = "sn-iu-title";
            textBox.DescriptionCssClass = "sn-iu-desc";
            textBox.ControlWrapperCssClass = "sn-iu-control";
            textBox.Columns = 30;
            textBox.PropertyName = propName;
            return textBox;
        }