IPanel.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Windows.Controls;
  6. using InABox.Configuration;
  7. using InABox.Core;
  8. namespace InABox.Wpf;
  9. public interface IPanelActionItem
  10. {
  11. }
  12. public class PanelAction : IPanelActionItem
  13. {
  14. public Action<PanelAction> OnExecute { get; set; }
  15. public string Caption { get; set; }
  16. public Bitmap Image { get; set; }
  17. public ContextMenu? Menu { get; set; }
  18. public PanelAction()
  19. {
  20. }
  21. public PanelAction(string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
  22. {
  23. Caption = caption;
  24. Image = image;
  25. Menu = menu;
  26. OnExecute = onExecute;
  27. }
  28. public void Execute()
  29. {
  30. OnExecute?.Invoke(this);
  31. }
  32. }
  33. public class PanelActionSeparator : IPanelActionItem
  34. {
  35. }
  36. public interface ICorePanel
  37. {
  38. void Setup();
  39. /// <summary>
  40. /// Shutdown the panel.
  41. /// </summary>
  42. /// <param name="cancel">If the operation can be cancelled, this is not <see langword="null"/></param>
  43. void Shutdown(CancelEventArgs? cancel);
  44. void Refresh();
  45. }
  46. public interface IBasePanel : ICorePanel, IDataModelSource
  47. {
  48. bool IsReady { get; set; }
  49. void CreateToolbarButtons(IPanelHost host);
  50. Dictionary<string, object[]> Selected();
  51. void Heartbeat(TimeSpan time);
  52. }
  53. public interface IPanel<T> : IBasePanel
  54. {
  55. }
  56. public interface IPropertiesPanel<TProperties>
  57. where TProperties : BaseObject, IGlobalConfigurationSettings, new()
  58. {
  59. public TProperties Properties { get; set; }
  60. }
  61. public interface IPropertiesPanel<TProperties, TSecurity> : IPropertiesPanel<TProperties>
  62. where TProperties : BaseObject, IGlobalConfigurationSettings, new()
  63. where TSecurity : ISecurityDescriptor, new()
  64. {
  65. }
  66. public interface IPanelHost
  67. {
  68. void CreatePanelAction(PanelAction action);
  69. void CreateReport(PanelAction action);
  70. void CreateSetupAction(PanelAction action);
  71. void CreateSetupSeparator();
  72. }
  73. public static class IPanelHostExtensions
  74. {
  75. public static void CreateSetupAction(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
  76. {
  77. host.CreateSetupAction(new PanelAction(caption, image, onExecute, menu));
  78. }
  79. public static void CreateSetupActionIf(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, bool canView, ContextMenu? menu = null)
  80. {
  81. if (canView)
  82. {
  83. host.CreateSetupAction(new PanelAction(caption, image, onExecute, menu));
  84. }
  85. }
  86. public static void CreateSetupActionIf<TSecurity>(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
  87. where TSecurity : ISecurityDescriptor, new()
  88. {
  89. host.CreateSetupActionIf(caption, image, onExecute, Security.IsAllowed<TSecurity>(), menu);
  90. }
  91. public static void CreateSetupActionIfCanView<T>(this IPanelHost host, string caption, Bitmap image, Action<PanelAction> onExecute, ContextMenu? menu = null)
  92. where T : Entity, new()
  93. {
  94. host.CreateSetupActionIf(caption, image, onExecute, Security.CanView<T>(), menu);
  95. }
  96. }