IDynamicGridEditorColumn.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Core;
  4. using Syncfusion.UI.Xaml.Grid;
  5. using Syncfusion.UI.Xaml.TreeGrid;
  6. namespace InABox.DynamicGrid;
  7. /// <remarks>
  8. /// Unless <see cref="IDynamicGridEditorColumn{TEntity}"/> is used, the editor type <b>must</b> be non-generic.
  9. /// </remarks>
  10. public interface IDynamicGridEditorColumn : IDynamicColumnBase
  11. {
  12. DynamicGridColumn Definition { get; set; }
  13. string MappingName { get; }
  14. string TreeMappingName { get; }
  15. List<string> ExtraColumns { get; }
  16. bool VariableWidth { get; }
  17. bool VariableHeight { get; }
  18. bool Filtered { get; }
  19. bool Editable { get; }
  20. IDynamicGridSummary? Summary();
  21. GridColumn CreateGridColumn();
  22. TreeGridColumn CreateTreeGridColumn();
  23. void UpdateUIComponent(IDynamicGridGridUIComponent component);
  24. }
  25. /// <summary>
  26. /// Indicates that this editor only makes sense in a context with a parent entity. If this interface is used, the editor <b>must</b> have
  27. /// a single generic type argument, which is <typeparamref name="TEntity"/>.
  28. /// </summary>
  29. public interface IDynamicGridEditorColumn<TEntity> : IDynamicGridEditorColumn
  30. {
  31. Func<BaseObject?>? GetEntity { get; set; }
  32. event DynamicColumnEntityChangedEvent? EntityChanged;
  33. void DoEntityChanged(String columnname, Dictionary<string, object?> changes);
  34. }
  35. public static class DynamicGridEditorColumnExtensions
  36. {
  37. public static void UpdateData<T>(this IDynamicGridEditorColumn<T> column, Dictionary<string, object?> updates)
  38. {
  39. var entity = column.GetEntity?.Invoke();
  40. if (entity != null)
  41. {
  42. var changes = new Dictionary<string, object?>();
  43. foreach (var key in updates.Keys)
  44. DynamicGridUtils.UpdateEditorValue(new BaseObject[] { entity }, key, updates[key], changes);
  45. column.DoEntityChanged(column.Definition.ColumnName, changes);
  46. }
  47. }
  48. }