Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/PropertySystem/PropertySpecDescriptor.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/PropertySystem/PropertySpecDescriptor.cs
r2768 r4068 1 1 using System; 2 using System.Collections.Generic;3 using System.Text;4 2 using System.ComponentModel; 5 namespace Netron.Diagramming.Core 6 { 3 namespace Netron.Diagramming.Core { 4 /// <summary> 5 /// An inherited property descriptor which can be created dynamically on the basis of a <see cref="PropertySpec"/> specification. 6 /// </summary> 7 internal class PropertySpecDescriptor : PropertyDescriptor { 8 #region events 7 9 /// <summary> 8 /// An inherited property descriptor which can be created dynamically on the basis of a <see cref="PropertySpec"/> specification.10 /// Occurs when the property grid accesses the value of the property 9 11 /// </summary> 10 internal class PropertySpecDescriptor : PropertyDescriptor 11 { 12 #region events 13 /// <summary> 14 /// Occurs when the property grid accesses the value of the property 15 /// </summary> 16 public event EventHandler<PropertyEventArgs> OnGetValue; 17 /// <summary> 18 /// Occurs when the property grid tries to set the value of the property 19 /// </summary> 20 public event EventHandler<PropertyEventArgs> OnSetValue; 21 22 #endregion 12 public event EventHandler<PropertyEventArgs> OnGetValue; 13 /// <summary> 14 /// Occurs when the property grid tries to set the value of the property 15 /// </summary> 16 public event EventHandler<PropertyEventArgs> OnSetValue; 23 17 24 #region Fields 25 private PropertySpec item; 26 #endregion 18 #endregion 27 19 28 #region Constructor 29 /// <summary> 30 /// Initializes a new instance of the <see cref="T:PropertySpecDescriptor"/> class. 31 /// </summary> 32 /// <param name="item">The item.</param> 33 /// <param name="attributes">the attributes to be used on the descriptor. Note that the attributes of the <see cref="PropertySpec"/> have to be previously taken over and overloaded.</param> 34 public PropertySpecDescriptor(PropertySpec item, Attribute[] attributes) : base(item.Name, attributes) 35 { 36 this.item = item; 37 } 38 #endregion 20 #region Fields 21 private PropertySpec item; 22 #endregion 39 23 40 #region Methods 24 #region Constructor 25 /// <summary> 26 /// Initializes a new instance of the <see cref="T:PropertySpecDescriptor"/> class. 27 /// </summary> 28 /// <param name="item">The item.</param> 29 /// <param name="attributes">the attributes to be used on the descriptor. Note that the attributes of the <see cref="PropertySpec"/> have to be previously taken over and overloaded.</param> 30 public PropertySpecDescriptor(PropertySpec item, Attribute[] attributes) 31 : base(item.Name, attributes) { 32 this.item = item; 33 } 34 #endregion 41 35 42 /// <summary> 43 /// When overridden in a derived class, gets the type of the component this property is bound to. 44 /// </summary> 45 /// <value></value> 46 /// <returns>A <see cref="T:System.Type"></see> that represents the type of component this property is bound to. When the <see cref="M:System.ComponentModel.PropertyDescriptor.GetValue(System.Object)"></see> or <see cref="M:System.ComponentModel.PropertyDescriptor.SetValue(System.Object,System.Object)"></see> methods are invoked, the object specified might be an instance of this type.</returns> 47 public override Type ComponentType 48 { 49 get 50 { 51 return item.GetType(); 52 } 53 } 36 #region Methods 54 37 55 /// <summary> 56 /// When overridden in a derived class, gets a value indicating whether this property is read-only. 57 /// </summary> 58 /// <value></value> 59 /// <returns>true if the property is read-only; otherwise, false.</returns> 60 public override bool IsReadOnly 61 { 62 get 63 { 64 return (Attributes.Matches(ReadOnlyAttribute.Yes)); 65 } 66 } 38 /// <summary> 39 /// When overridden in a derived class, gets the type of the component this property is bound to. 40 /// </summary> 41 /// <value></value> 42 /// <returns>A <see cref="T:System.Type"></see> that represents the type of component this property is bound to. When the <see cref="M:System.ComponentModel.PropertyDescriptor.GetValue(System.Object)"></see> or <see cref="M:System.ComponentModel.PropertyDescriptor.SetValue(System.Object,System.Object)"></see> methods are invoked, the object specified might be an instance of this type.</returns> 43 public override Type ComponentType { 44 get { 45 return item.GetType(); 46 } 47 } 67 48 68 /// <summary> 69 /// When overridden in a derived class, gets the type of the property. 70 /// </summary> 71 /// <value></value> 72 /// <returns>A <see cref="T:System.Type"></see> that represents the type of the property.</returns> 73 public override Type PropertyType 74 { 75 get 76 { 77 return Type.GetType(item.TypeName); 78 } 79 } 49 /// <summary> 50 /// When overridden in a derived class, gets a value indicating whether this property is read-only. 51 /// </summary> 52 /// <value></value> 53 /// <returns>true if the property is read-only; otherwise, false.</returns> 54 public override bool IsReadOnly { 55 get { 56 return (Attributes.Matches(ReadOnlyAttribute.Yes)); 57 } 58 } 80 59 81 /// <summary> 82 /// When overridden in a derived class, returns whether resetting an object changes its value. 83 /// </summary> 84 /// <param name="component">The component to test for reset capability.</param> 85 /// <returns> 86 /// true if resetting the component changes its value; otherwise, false. 87 /// </returns> 88 public override bool CanResetValue(object component) 89 { 90 if(item.DefaultValue == null) 91 return false; 92 else 93 return !this.GetValue(component).Equals(item.DefaultValue); 94 } 60 /// <summary> 61 /// When overridden in a derived class, gets the type of the property. 62 /// </summary> 63 /// <value></value> 64 /// <returns>A <see cref="T:System.Type"></see> that represents the type of the property.</returns> 65 public override Type PropertyType { 66 get { 67 return Type.GetType(item.TypeName); 68 } 69 } 95 70 96 /// <summary> 97 /// When overridden in a derived class, gets the current value of the property on a component. 98 /// </summary> 99 /// <param name="component">The component with the property for which to retrieve the value.</param> 100 /// <returns> 101 /// The value of a property for a given component. 102 /// </returns> 103 public override object GetValue(object component) 104 { 105 // Have the property bag raise an event to get the current value 106 // of the property. 71 /// <summary> 72 /// When overridden in a derived class, returns whether resetting an object changes its value. 73 /// </summary> 74 /// <param name="component">The component to test for reset capability.</param> 75 /// <returns> 76 /// true if resetting the component changes its value; otherwise, false. 77 /// </returns> 78 public override bool CanResetValue(object component) { 79 if (item.DefaultValue == null) 80 return false; 81 else 82 return !this.GetValue(component).Equals(item.DefaultValue); 83 } 107 84 108 PropertyEventArgs e = new PropertyEventArgs(component, base.Name, null); 109 RaiseOnGetValue(e); 110 return e.Value; 111 } 85 /// <summary> 86 /// When overridden in a derived class, gets the current value of the property on a component. 87 /// </summary> 88 /// <param name="component">The component with the property for which to retrieve the value.</param> 89 /// <returns> 90 /// The value of a property for a given component. 91 /// </returns> 92 public override object GetValue(object component) { 93 // Have the property bag raise an event to get the current value 94 // of the property. 112 95 113 /// <summary> 114 /// Raises the on get value. 115 /// </summary> 116 /// <param name="e">The <see cref="T:Netron.Diagramming.Core.PropertyEventArgs"/> instance containing the event data.</param> 117 private void RaiseOnGetValue(PropertyEventArgs e) 118 { 119 EventHandler<PropertyEventArgs> handler = OnGetValue; 120 if(handler != null) 121 handler(this,e); 122 } 96 PropertyEventArgs e = new PropertyEventArgs(component, base.Name, null); 97 RaiseOnGetValue(e); 98 return e.Value; 99 } 100 101 /// <summary> 102 /// Raises the on get value. 103 /// </summary> 104 /// <param name="e">The <see cref="T:Netron.Diagramming.Core.PropertyEventArgs"/> instance containing the event data.</param> 105 private void RaiseOnGetValue(PropertyEventArgs e) { 106 EventHandler<PropertyEventArgs> handler = OnGetValue; 107 if (handler != null) 108 handler(this, e); 109 } 123 110 124 111 125 /// <summary> 126 /// Raises the on set value. 127 /// </summary> 128 /// <param name="e">The <see cref="T:Netron.Diagramming.Core.PropertyEventArgs"/> instance containing the event data.</param> 129 private void RaiseOnSetValue(PropertyEventArgs e) 130 { 131 EventHandler<PropertyEventArgs> handler = OnSetValue; 132 if(handler != null) 133 handler(this,e); 134 } 112 /// <summary> 113 /// Raises the on set value. 114 /// </summary> 115 /// <param name="e">The <see cref="T:Netron.Diagramming.Core.PropertyEventArgs"/> instance containing the event data.</param> 116 private void RaiseOnSetValue(PropertyEventArgs e) { 117 EventHandler<PropertyEventArgs> handler = OnSetValue; 118 if (handler != null) 119 handler(this, e); 120 } 135 121 136 /// <summary> 137 /// When overridden in a derived class, resets the value for this property of the component to the default value. 138 /// </summary> 139 /// <param name="component">The component with the property value that is to be reset to the default value.</param> 140 public override void ResetValue(object component) 141 { 142 SetValue(component, item.DefaultValue); 143 } 122 /// <summary> 123 /// When overridden in a derived class, resets the value for this property of the component to the default value. 124 /// </summary> 125 /// <param name="component">The component with the property value that is to be reset to the default value.</param> 126 public override void ResetValue(object component) { 127 SetValue(component, item.DefaultValue); 128 } 144 129 145 /// <summary> 146 /// When overridden in a derived class, sets the value of the component to a different value. 147 /// </summary> 148 /// <param name="component">The component with the property value that is to be set.</param> 149 /// <param name="value">The new value.</param> 150 public override void SetValue(object component, object value) 151 { 152 // Have the property bag raise an event to set the current value 153 // of the property. 130 /// <summary> 131 /// When overridden in a derived class, sets the value of the component to a different value. 132 /// </summary> 133 /// <param name="component">The component with the property value that is to be set.</param> 134 /// <param name="value">The new value.</param> 135 public override void SetValue(object component, object value) { 136 // Have the property bag raise an event to set the current value 137 // of the property. 154 138 155 156 157 139 PropertyEventArgs e = new PropertyEventArgs(component, Name, value); 140 RaiseOnSetValue(e); 141 } 158 142 159 /// <summary> 160 /// When overridden in a derived class, determines a value indicating whether the value of this property needs to be persisted. 161 /// </summary> 162 /// <param name="component">The component with the property to be examined for persistence.</param> 163 /// <returns> 164 /// true if the property should be persisted; otherwise, false. 165 /// </returns> 166 public override bool ShouldSerializeValue(object component) 167 { 168 object val = this.GetValue(component); 143 /// <summary> 144 /// When overridden in a derived class, determines a value indicating whether the value of this property needs to be persisted. 145 /// </summary> 146 /// <param name="component">The component with the property to be examined for persistence.</param> 147 /// <returns> 148 /// true if the property should be persisted; otherwise, false. 149 /// </returns> 150 public override bool ShouldSerializeValue(object component) { 151 object val = this.GetValue(component); 169 152 170 if(item.DefaultValue == null && val == null)171 172 173 174 153 if (item.DefaultValue == null && val == null) 154 return false; 155 else 156 return !val.Equals(item.DefaultValue); 157 } 175 158 176 177 159 #endregion 160 } 178 161 }
Note: See TracChangeset
for help on using the changeset viewer.