123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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;
- /// <summary>
- /// An <see cref="IPanel{T}"/> which wraps a <typeparamref name="TDashboard"/>, with a header. <typeparamref name="TDashboard"/>
- /// must be an <see cref="IBasePanel"/>, so that it can act as a normal PRS panel.
- /// </summary>
- /// <remarks>
- /// <see cref="IActionsDashboard"/> has no effect here, and instead, since <typeparamref name="TDashboard"/> must implement <see cref="IBasePanel"/>,
- /// one should use <see cref="IBasePanel.CreateToolbarButtons(PRSDesktop.IPanelHost)"/> to create actions.
- /// </remarks>
- /// <typeparam name="TDashboard"></typeparam>
- /// <typeparam name="TGroup"></typeparam>
- /// <typeparam name="TProperties"></typeparam>
- public class DashboardContainerPanel<TDashboard, TGroup, TProperties> : UserControl, IBasePanel
- where TDashboard : IDashboardWidget<TGroup, TProperties>, 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<TProperties>().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<string, object[]> Selected()
- {
- return Dashboard.Selected();
- }
- public void Setup()
- {
- Dashboard.Setup();
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- Dashboard.Shutdown(cancel);
- if(cancel?.Cancel != true)
- {
- new UserConfiguration<TProperties>().Save(Dashboard.Properties);
- }
- }
- #endregion
- }
|