using AvalonDock.Controls; using FastReport.Export.Dxf.Sections; using InABox.Configuration; using InABox.Core; using InABox.Wpf; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace PRSDesktop; /// /// An which wraps a , with a header. /// must be an , so that it can act as a normal PRS panel. /// /// /// has no effect here, and instead, since must implement , /// one should use to create actions. /// /// /// /// public class DashboardContainerPanel : UserControl, IBasePanel where TDashboard : IDashboardWidget, IBasePanel, new() where TGroup : DashboardWidgetGroup where TProperties : IUserConfigurationSettings, IDashboardProperties, new() { public TDashboard Dashboard { get; set; } private StackPanel HeaderItemsLeft; private StackPanel HeaderItemsRight; public DashboardContainerPanel() { Dashboard = new TDashboard { Properties = new UserConfiguration().Load() }; var border = new Border { BorderBrush = new SolidColorBrush(Colors.Gray), BorderThickness = new Thickness(0) }; var grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); var headerBorder = new Border { BorderBrush = new SolidColorBrush(Colors.Gray), BorderThickness = new Thickness(0.75), CornerRadius = new CornerRadius(5, 5, 0, 0), Background = new SolidColorBrush(Colors.WhiteSmoke) }; var dock = new DockPanel { Background = new SolidColorBrush(Colors.Transparent) }; HeaderItemsRight = new StackPanel { Margin = new Thickness(5), Orientation = Orientation.Horizontal }; HeaderItemsLeft = new StackPanel { Margin = new Thickness(5), Orientation = Orientation.Horizontal }; DockPanel.SetDock(HeaderItemsRight, Dock.Right); dock.Children.Add(HeaderItemsRight); DockPanel.SetDock(HeaderItemsLeft, Dock.Left); dock.Children.Add(HeaderItemsLeft); headerBorder.Child = dock; var content = new ContentControl { Margin = new Thickness(0, 2, 0, 0), Content = Dashboard }; Grid.SetRow(headerBorder, 0); Grid.SetRow(content, 1); grid.Children.Add(headerBorder); grid.Children.Add(content); border.Child = grid; Content = border; if (Dashboard is IHeaderDashboard headerDashboard) { RefreshHeader(headerDashboard.Header); headerDashboard.Header.HeaderChanged += Header_HeaderChanged; } } private void RefreshHeader(DashboardHeader header) { if (HeaderItemsLeft.Children.Count > 0) { HeaderItemsLeft.Children.Clear(); } if (HeaderItemsRight.Children.Count > 0) { HeaderItemsRight.Children.Clear(); } foreach (var item in header.GetLeftElements()) { HeaderItemsLeft.Children.Add(item); } foreach (var item in header.GetRightElements()) { HeaderItemsRight.Children.Add(item); } } private void Header_HeaderChanged(DashboardHeader header) { RefreshHeader(header); } #region IBasePanel public bool IsReady { get => Dashboard.IsReady; set => Dashboard.IsReady = true; } public string SectionName => Dashboard.SectionName; public event DataModelUpdateEvent? OnUpdateDataModel { add => Dashboard.OnUpdateDataModel += value; remove => Dashboard.OnUpdateDataModel -= value; } public void CreateToolbarButtons(IPanelHost host) { Dashboard.CreateToolbarButtons(host); } public DataModel DataModel(Selection selection) { return Dashboard.DataModel(selection); } public void Heartbeat(TimeSpan time) { Dashboard.Heartbeat(time); } public void Refresh() { Dashboard.Refresh(); } public Dictionary Selected() { return Dashboard.Selected(); } public void Setup() { Dashboard.Setup(); } public void Shutdown(CancelEventArgs? cancel) { Dashboard.Shutdown(cancel); if(cancel?.Cancel != true) { new UserConfiguration().Save(Dashboard.Properties); } } #endregion }