|
@@ -0,0 +1,230 @@
|
|
|
+using com.sun.tools.corba.se.idl.toJavaPortable;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.DynamicGrid;
|
|
|
+using InABox.Wpf;
|
|
|
+using InABox.WPF;
|
|
|
+using PRS.Shared.Events;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Media;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
+
|
|
|
+namespace PRS.Shared.Grids.EventEditor;
|
|
|
+
|
|
|
+public class PropertyInitializerEditItem : BaseObject
|
|
|
+{
|
|
|
+ public PropertyInitializer PropertyInitializer { get; set; }
|
|
|
+}
|
|
|
+
|
|
|
+public class PropertyInitializerGrid : DynamicItemsListGrid<PropertyInitializerEditItem>
|
|
|
+{
|
|
|
+ private string[] ColumnNames = null!;
|
|
|
+
|
|
|
+ private Type? _entityType;
|
|
|
+ public Type? EntityType
|
|
|
+ {
|
|
|
+ get => _entityType;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ if(value != _entityType)
|
|
|
+ {
|
|
|
+ Items.Clear();
|
|
|
+ _entityType = value;
|
|
|
+
|
|
|
+ if(value is null)
|
|
|
+ {
|
|
|
+ ColumnNames = [];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var properties = DatabaseSchema.Properties(value)
|
|
|
+ .Where(x => x.IsSerializable)
|
|
|
+ .Select(x => x.Name)
|
|
|
+ .ToArray();
|
|
|
+ Array.Sort(properties);
|
|
|
+ ColumnNames = properties;
|
|
|
+ }
|
|
|
+ Reconfigure();
|
|
|
+ Refresh(true, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public IEventDataModelDefinition DataModelDefinition { get; set; } = null!;
|
|
|
+
|
|
|
+ private BitmapImage _delete = InABox.Wpf.Resources.delete.AsBitmapImage();
|
|
|
+
|
|
|
+ protected override void Init()
|
|
|
+ {
|
|
|
+ base.Init();
|
|
|
+
|
|
|
+ ActionColumns.Add(new DynamicTemplateColumn(row =>
|
|
|
+ {
|
|
|
+ var item = LoadItem(row);
|
|
|
+ var button = new Button
|
|
|
+ {
|
|
|
+ Content = item.PropertyInitializer.Property.Name,
|
|
|
+
|
|
|
+ VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
|
|
|
+ VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
|
|
|
+ HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
|
|
|
+ MinWidth = 100,
|
|
|
+
|
|
|
+ Padding = new System.Windows.Thickness(5, 0, 5, 0),
|
|
|
+ Background = new LinearGradientBrush(new GradientStopCollection()
|
|
|
+ {
|
|
|
+ new(Color.FromRgb(0xF0, 0xF0, 0xF0), 0.0),
|
|
|
+ new(Color.FromRgb(0xE5, 0xE5, 0xE5), 1.0),
|
|
|
+ })
|
|
|
+ {
|
|
|
+ StartPoint = new(0, 0),
|
|
|
+ EndPoint = new(0, 1),
|
|
|
+ },
|
|
|
+ BorderBrush = Color.FromRgb(0xAC, 0xAC, 0xAC).ToBrush(),
|
|
|
+ BorderThickness = new(0),
|
|
|
+ Tag = row
|
|
|
+ };
|
|
|
+ button.Click += PropertyNode_Click;
|
|
|
+ return button;
|
|
|
+ })
|
|
|
+ {
|
|
|
+ HeaderText = "Property"
|
|
|
+ });
|
|
|
+ ActionColumns.Add(new DynamicTemplateColumn(row =>
|
|
|
+ {
|
|
|
+ var item = LoadItem(row);
|
|
|
+
|
|
|
+ var panel = new DockPanel();
|
|
|
+
|
|
|
+ var textBox = new TextBox
|
|
|
+ {
|
|
|
+ Background = Colors.LightYellow.ToBrush(),
|
|
|
+ IsEnabled = false,
|
|
|
+ BorderThickness = new(0),
|
|
|
+ VerticalContentAlignment = VerticalAlignment.Center,
|
|
|
+ HorizontalContentAlignment = HorizontalAlignment.Left,
|
|
|
+ Padding = new(2, 0, 0, 0),
|
|
|
+ Text = item.PropertyInitializer.Value
|
|
|
+ };
|
|
|
+
|
|
|
+ var button = new Button
|
|
|
+ {
|
|
|
+ Content = "Edit",
|
|
|
+ Padding = new(5.0),
|
|
|
+ MinWidth = 30,
|
|
|
+ Tag = row
|
|
|
+ };
|
|
|
+ button.BorderBrush = Colors.Silver.ToBrush();
|
|
|
+ button.BorderThickness = new Thickness(0.75, 0.0, 0.0, 0.0);
|
|
|
+ button.Click += Value_Click;
|
|
|
+
|
|
|
+ DockPanel.SetDock(button, Dock.Right);
|
|
|
+ panel.Children.Add(button);
|
|
|
+ DockPanel.SetDock(textBox, Dock.Left);
|
|
|
+ panel.Children.Add(textBox);
|
|
|
+
|
|
|
+ return panel;
|
|
|
+ })
|
|
|
+ {
|
|
|
+ HeaderText = "Value"
|
|
|
+ });
|
|
|
+ ActionColumns.Add(new DynamicImageColumn(_delete, DeleteButton_Click));
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool DeleteButton_Click(CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null) return false;
|
|
|
+
|
|
|
+ if (CanDeleteItems([row]))
|
|
|
+ if (MessageWindow.ShowYesNo("Are you sure you wish to delete the selected records?", "Confirm Delete"))
|
|
|
+ {
|
|
|
+ DeleteItems([row]);
|
|
|
+ SelectedRows = Array.Empty<CoreRow>();
|
|
|
+ DoChanged();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region UI Component
|
|
|
+
|
|
|
+ private class UIComponent : DynamicGridGridUIComponent<PropertyInitializerEditItem>
|
|
|
+ {
|
|
|
+ protected override Brush? GetCellSelectionBackgroundBrush()
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override IDynamicGridUIComponent<PropertyInitializerEditItem> CreateUIComponent()
|
|
|
+ {
|
|
|
+ return new UIComponent { Parent = this };
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+
|
|
|
+ options.Clear();
|
|
|
+ options.ReadOnly = EntityType is null;
|
|
|
+ options.AddRows = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoAdd(bool openEditorOnDirectEdit = false)
|
|
|
+ {
|
|
|
+ if (EntityType is null) return;
|
|
|
+
|
|
|
+ if(DynamicGridColumnNameSelectorGrid.SelectColumnName(EntityType, ColumnNames, out var value))
|
|
|
+ {
|
|
|
+ var property = DatabaseSchema.PropertyStrict(EntityType, value);
|
|
|
+ CreateItems(() =>
|
|
|
+ {
|
|
|
+ return [new()
|
|
|
+ {
|
|
|
+ PropertyInitializer = new(property, "")
|
|
|
+ }];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Value_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not FrameworkElement el || el.Tag is not CoreRow row) return;
|
|
|
+ if (EntityType is null) return;
|
|
|
+
|
|
|
+ var item = LoadItem(row);
|
|
|
+
|
|
|
+ var window = new ExpressionEditorWindow(DataModelDefinition.GetVariables().Select(x => x.Name).ToArray())
|
|
|
+ {
|
|
|
+ Expression = item.PropertyInitializer.Value
|
|
|
+ };
|
|
|
+ if(window.ShowDialog() == true && item.PropertyInitializer.Value != window.Expression)
|
|
|
+ {
|
|
|
+ item.PropertyInitializer.Value = window.Expression;
|
|
|
+ UpdateRow(row, item);
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PropertyNode_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is not FrameworkElement el || el.Tag is not CoreRow row) return;
|
|
|
+ if (EntityType is null) return;
|
|
|
+
|
|
|
+ var item = LoadItem(row);
|
|
|
+
|
|
|
+ if(DynamicGridColumnNameSelectorGrid.SelectColumnName(EntityType, ColumnNames, out var value) && value != item.PropertyInitializer.Property.Name)
|
|
|
+ {
|
|
|
+ item.PropertyInitializer.Property = DatabaseSchema.PropertyStrict(EntityType, value);
|
|
|
+ UpdateRow(row, item);
|
|
|
+ DoChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|