//If two IGridBehaviors of the same type match the same //datasource, only the one added last will be used. To //do this, I maintain the behaviors set backwards, then //call Distinct with a custom IEqualityComparer before //returning matching behaviors. The Distinct() method //will return the first of each set of duplicates from //the original. I cannot maintain the uniqueness when //adding the behaviors because I can't compare selector //delegates. This allows specific programs to override //the built-in default schema settings. //This means that behaviors will be applied in reverse. //I want behaviors to be completely independent, so I'm //keeping this behavior. To change it, call .Reverse() //after .Distinct(). ///<summary>Gets the grid behaviors that should be applied to the given datasource.</summary> public static IEnumerable <IGridBehavior> GetBehaviors(object dataSource) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } UIThread.Verify(); return(behaviors.Where(kvp => kvp.Key(dataSource)) .Select(kvp => kvp.Value) .Distinct(new TypeComparer <IGridBehavior>())); }
///<summary>Registers an IEditorSettings preset for a column in a Singularity schema.</summary> public static void Register(Column column, IEditorSettings settings) { if (column == null) { throw new ArgumentNullException("column"); } if (settings == null) { throw new ArgumentNullException("settings"); } UIThread.Verify(); dictionary.Add(column, settings); }
///<summary>Registers an IGridBehavior for matching datasources.</summary> ///<param name="selector">A delegate that determines which datasources the behavior should be applied to.</param> ///<param name="behavior">The IGridBehavior instance.</param> public static void RegisterBehavior(Func <object, bool> selector, IGridBehavior behavior) { if (selector == null) { throw new ArgumentNullException("selector"); } if (behavior == null) { throw new ArgumentNullException("behavior"); } UIThread.Verify(); behaviors.AddFirst(new KeyValuePair <Func <object, bool>, IGridBehavior>(selector, behavior)); }
///<summary>Gets an IEditorSettings to use for the given column, or null if there is no preset for that column.</summary> public static IEditorSettings GetSettings(object dataSource, string columnName) { UIThread.Verify(); var schema = TableSchema.GetSchema(dataSource); if (schema == null) { return(null); } var column = schema.Columns[columnName]; if (column == null) { return(null); //eg, unbound columns } return(GetSettings(column)); }