1 using System.Diagnostics.CodeAnalysis;
3 namespace System.Activities.Presentation.PropertyEditing
5 using System.ComponentModel;
6 using System.Collections;
8 using System.Diagnostics;
9 using System.Activities.Presentation;
12 /// The PropertyEntry class provides additional, mostly type-specific data for a property.
14 public abstract class PropertyEntry : INotifyPropertyChanged, IPropertyFilterTarget {
16 private PropertyValue _parentValue;
17 private bool _matchesFilter = true;
18 private PropertyValue _value;
21 /// Creates a PropertyEntry. For host infrastructure derived classes.
23 protected PropertyEntry() : this(null) { }
26 /// Creates a PropertyEntry that acts as a sub-property of the specified PropertyValue.
27 /// For host infrastructure derived classes.
29 /// <param name="parentValue">The parent PropertyValue.
30 /// Root properties do not have a parent PropertyValue.</param>
31 protected PropertyEntry(PropertyValue parentValue) {
32 _parentValue = parentValue;
36 /// Gets the name of the encapsulated property.
38 public abstract string PropertyName { get; }
41 /// Gets the DisplayName for the property. By default, it is the
44 public virtual string DisplayName { get { return this.PropertyName; } }
47 /// Gets the Type of the encapsulated property.
49 public abstract Type PropertyType { get; }
52 /// Gets the name of the category that this property resides in.
54 public abstract string CategoryName { get; }
57 /// Gets the description of the encapsulated property.
59 public abstract string Description { get; }
62 /// Returns true if there are standard values for this property.
63 /// The default implementation checks if the StandardValues property
64 /// returns a non-null collection with a count > 0.
66 protected virtual bool HasStandardValues {
68 ICollection values = StandardValues;
69 return values != null && values.Count > 0;
74 /// Accessor because we use this property in the property container.
76 internal bool HasStandardValuesInternal {
77 get { return HasStandardValues; }
81 /// Gets the read-only attribute of the encapsulated property.
83 public abstract bool IsReadOnly { get; }
86 /// Gets a flag indicating whether the encapsulated property is an advanced property.
88 public abstract bool IsAdvanced { get; }
91 /// Gets any StandardValues that the encapsulated property supports.
93 public abstract ICollection StandardValues { get; }
96 /// Gets to PropertyValueEditor to be used for editing of this PropertyEntry.
97 /// May be null. PropertyContainer listens to changes made to this property.
98 /// If the value changes, it's the responsibility of the deriving class to fire the
99 /// appropriate PropertyChanged event.
101 public abstract PropertyValueEditor PropertyValueEditor { get; }
104 /// Gets the parent PropertyValue. This is only used for sub-properties and,
105 /// hence, its balue may be null.
107 public PropertyValue ParentValue {
114 /// Gets the PropertyValue (data model) for this PropertyEntry.
116 public PropertyValue PropertyValue {
119 _value = CreatePropertyValueInstance();
126 /// Used by the host infrastructure to create a new host-specific PropertyValue instance.
128 /// <returns>new PropertyValue</returns>
129 protected abstract PropertyValue CreatePropertyValueInstance();
131 // IPropertyFilterTarget Members
134 /// IPropertyFilterTarget event
136 public event EventHandler<PropertyFilterAppliedEventArgs> FilterApplied;
139 /// IPropertyFilterTarget method. PropertyContainer listens to changes made to this property.
141 public bool MatchesFilter {
143 return _matchesFilter;
146 if (value != _matchesFilter) {
147 _matchesFilter = value;
148 OnPropertyChanged("MatchesFilter");
154 /// IPropertyFilterTarget method
156 /// <param name="predicate">the predicate to match against</param>
157 /// <returns>true if there is a match</returns>
158 public virtual bool MatchesPredicate(PropertyFilterPredicate predicate) {
159 return predicate == null ?
161 predicate.Match(this.DisplayName) || predicate.Match(this.PropertyType.Name);
165 /// IPropertyFilterTarget method
167 /// <param name="filter">the PropertyFilter to apply</param>
168 public virtual void ApplyFilter(PropertyFilter filter) {
169 this.MatchesFilter = filter == null ? true : filter.Match(this);
170 OnFilterApplied(filter);
174 /// Used to raise the IPropertyFilterTarget FilterApplied event
176 /// <param name="filter"></param>
177 protected virtual void OnFilterApplied(PropertyFilter filter) {
178 if (FilterApplied != null)
179 FilterApplied(this, new PropertyFilterAppliedEventArgs(filter));
183 // INotifyPropertyChanged
186 /// INotifyPropertyChanged event
188 public event PropertyChangedEventHandler PropertyChanged;
191 /// Used to raise the INotifyPropertyChanged PropertyChanged event
193 /// <param name="e">EventArgs for this event</param>
194 protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
196 throw FxTrace.Exception.ArgumentNull("e");
198 if (this.PropertyChanged != null)
199 this.PropertyChanged(this, e);
203 /// Used to raise the INotifyPropertyChanged event
205 /// <param name="propertyName"></param>
206 /// <exception cref="ArgumentNullException">When propertyName is null</exception>
207 protected virtual void OnPropertyChanged(string propertyName) {
208 if (propertyName == null)
209 throw FxTrace.Exception.ArgumentNull("propertyName");
211 if (this.PropertyChanged != null)
212 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));