Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/PropertySystem/Descriptors/DescriptorBase.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 8.8 KB
Line 
1using System;
2using System.ComponentModel;
3
4namespace Netron.Diagramming.Core {
5  /// <summary>
6  /// Abstract base class for custom descriptors based on our properties mechanism.
7  /// <remarks>
8  /// Usually you do not inherit from this class to describe properties of entities, use the appropriate
9  /// specializations like the <see cref="ShapeBaseDescriptor"/> or <see cref="ConnectionBaseDescriptor"/> classes instead.
10  /// Also, this class does not define any properties for the property grid but contains methods and basic stuff to make the construction of
11  /// concrete descriptors easier.
12  /// </remarks>
13  /// </summary>
14  abstract class DescriptorBase : CustomTypeDescriptor {
15    #region Fields
16    //the provider to which this descriptor is attached
17    private TypeDescriptionProvider provider;
18    /// <summary>
19    /// the type being served
20    /// </summary>
21    private Type type;
22    /// <summary>
23    /// the collection of properties displayed
24    /// </summary>
25    private PropertyDescriptorCollection mProperties;
26    #endregion
27
28    #region Properties
29    /// <summary>
30    /// Gets the collection of property descrtiptors
31    /// </summary>
32    protected PropertyDescriptorCollection Properties {
33      get { return mProperties; }
34    }
35    #endregion
36
37    #region Constructors
38
39    /// <summary>
40    /// Initializes a new instance of the <see cref="T:DescriptorBase"/> class.
41    /// </summary>
42    /// <param name="provider">The provider.</param>
43    /// <param name="parentdescriptor">The parentdescriptor.</param>
44    /// <param name="objectType">Type of the object.</param>
45    public DescriptorBase(ShapeProvider provider, ICustomTypeDescriptor parentdescriptor, Type objectType)
46      : base(parentdescriptor) {
47      this.provider = provider;
48      this.type = objectType;
49      mProperties = new PropertyDescriptorCollection(null);
50    }
51
52    /// <summary>
53    /// Initializes a new instance of the <see cref="T:DescriptorBase"/> class.
54    /// </summary>
55    /// <param name="provider">The provider.</param>
56    /// <param name="objectType">Type of the object.</param>
57    public DescriptorBase(TypeDescriptionProvider provider, Type objectType)
58      : base() {
59      this.provider = provider;
60      this.type = objectType;
61      mProperties = new PropertyDescriptorCollection(null);
62    }
63    #endregion
64
65    #region Methods
66
67    #region AddProperty overloads
68    /// <summary>
69    /// Adds a new property to the property descriptor collection.
70    /// </summary>
71    /// <param name="name">The name of the property displayed in the property grid.</param>
72    /// <param name="type">The fully qualified name of the type of the property.</param>
73    public void AddProperty(string name, Type type) {
74      PropertySpec widthSpec = new PropertySpec(name, type);
75      PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
76      pd.OnGetValue += new EventHandler<PropertyEventArgs>(GetValue);
77      pd.OnSetValue += new EventHandler<PropertyEventArgs>(SetValue);
78      mProperties.Add(pd);
79    }
80    /// <summary>
81    /// Adds a new property to the property descriptor collection.
82    /// </summary>
83    /// <param name="name">The name of the property displayed in the property grid.</param>
84    /// <param name="type">The fully qualified name of the type of the property.</param>
85    /// <param name="category">The category under which the property is displayed in the
86    /// property grid.</param>
87    public void AddProperty(string name, Type type, string category) {
88      PropertySpec widthSpec = new PropertySpec(name, type, category);
89      PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
90      pd.OnGetValue += new EventHandler<PropertyEventArgs>(GetValue);
91      pd.OnSetValue += new EventHandler<PropertyEventArgs>(SetValue);
92      mProperties.Add(pd);
93    }
94    /// <summary>
95    /// Adds a new property to the property descriptor collection.
96    /// </summary>
97    /// <param name="name">The name of the property displayed in the property grid.</param>
98    /// <param name="type">The fully qualified name of the type of the property.</param>
99    /// <param name="category">The category under which the property is displayed in the
100    /// property grid.</param>
101    /// <param name="description">A string that is displayed in the help area of the
102    /// property grid.</param>
103    public void AddProperty(string name, Type type, string category, string description) {
104      PropertySpec widthSpec = new PropertySpec(name, type, category, description);
105      PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
106      pd.OnGetValue += new EventHandler<PropertyEventArgs>(GetValue);
107      pd.OnSetValue += new EventHandler<PropertyEventArgs>(SetValue);
108      mProperties.Add(pd);
109    }
110    /// <summary>
111    /// Adds a new property to the property descriptor collection.
112    /// </summary>
113    /// <param name="name">The name of the property displayed in the property grid.</param>
114    /// <param name="type">The fully qualified name of the type of the property.</param>
115    /// <param name="category">The category under which the property is displayed in the
116    /// property grid.</param>
117    /// <param name="description">A string that is displayed in the help area of the
118    /// property grid.</param>
119    /// <param name="defaultValue">The default value of the property, or null if there is
120    /// no default value.</param>
121    public void AddProperty(string name, Type type, string category, string description, object defaultValue) {
122      PropertySpec widthSpec = new PropertySpec(name, type, category, description, defaultValue);
123      PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
124      pd.OnGetValue += new EventHandler<PropertyEventArgs>(GetValue);
125      pd.OnSetValue += new EventHandler<PropertyEventArgs>(SetValue);
126      mProperties.Add(pd);
127    }
128    /// <summary>
129    /// Adds a new property to the property descriptor collection.
130    /// </summary>
131    /// <param name="name">The name of the property displayed in the property grid.</param>
132    /// <param name="type">A Type that represents the type of the property.</param>
133    /// <param name="category">The category under which the property is displayed in the
134    /// property grid.</param>
135    /// <param name="description">A string that is displayed in the help area of the
136    /// property grid.</param>
137    /// <param name="defaultValue">The default value of the property, or null if there is
138    /// no default value.</param>
139    /// <param name="editor">The Type that represents the type of the editor for this
140    /// property.  This type must derive from UITypeEditor.</param>
141    /// <param name="typeConverter">The Type that represents the type of the type
142    /// converter for this property.  This type must derive from TypeConverter.</param>
143    public void AddProperty(string name, Type type, string category, string description, object defaultValue, Type editor, Type typeConverter) {
144      PropertySpec widthSpec = new PropertySpec(name, type, category, description, defaultValue, editor, typeConverter);
145      PropertySpecDescriptor pd = widthSpec.ToPropertyDescriptor();
146      pd.OnGetValue += new EventHandler<PropertyEventArgs>(GetValue);
147      pd.OnSetValue += new EventHandler<PropertyEventArgs>(SetValue);
148      mProperties.Add(pd);
149    }
150    #endregion
151
152
153
154
155    /// <summary>
156    /// Overrides the method to retun the collection of properties we defined internally
157    /// </summary>
158    /// <param name="attributes"></param>
159    /// <returns></returns>
160    public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
161      return mProperties;
162    }
163
164    /// <summary>
165    /// Returns a collection of property descriptors for the object represented by this type descriptor.
166    /// </summary>
167    /// <returns>
168    /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> containing the property descriptions for the object represented by this type descriptor. The default is <see cref="F:System.ComponentModel.PropertyDescriptorCollection.Empty"></see>.
169    /// </returns>
170    public override PropertyDescriptorCollection GetProperties() {
171      return GetProperties(null);
172    }
173    /// <summary>
174    /// Override this method to return the appropriate value corresponding to the property
175    /// </summary>
176    /// <param name="sender"></param>
177    /// <param name="e"></param>
178    protected virtual void GetValue(object sender, PropertyEventArgs e) {
179
180    }
181
182    /// <summary>
183    /// Override this method to set the appropriate value corresponding to the property
184    /// </summary>
185    /// <param name="sender"></param>
186    /// <param name="e"></param>
187    protected virtual void SetValue(object sender, PropertyEventArgs e) {
188    }
189    #endregion
190  }
191}
Note: See TracBrowser for help on using the repository browser.