|
@@ -4,138 +4,134 @@ using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Linq.Expressions;
|
|
-using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Imaging;
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
using InABox.WPF;
|
|
using InABox.WPF;
|
|
-using NPOI.OpenXmlFormats.Dml.Chart;
|
|
|
|
-using NPOI.OpenXmlFormats.Dml.Spreadsheet;
|
|
|
|
using Syncfusion.UI.Xaml.TreeGrid;
|
|
using Syncfusion.UI.Xaml.TreeGrid;
|
|
-using Syncfusion.Windows.Tools.Controls;
|
|
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
namespace InABox.DynamicGrid
|
|
{
|
|
{
|
|
- public class DynamicTreeNode : INotifyPropertyChanged
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- private DynamicTreeNodes _owner;
|
|
|
|
-
|
|
|
|
- public ObservableCollection<DynamicTreeNode> Children => _owner.GetChilden(_id);
|
|
|
|
-
|
|
|
|
- private Guid _id;
|
|
|
|
- public Guid ID
|
|
|
|
- {
|
|
|
|
- get { return _id; }
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _id = value;
|
|
|
|
- RaisedOnPropertyChanged("ID");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Guid _parent;
|
|
|
|
- public Guid Parent
|
|
|
|
- {
|
|
|
|
- get { return _parent; }
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _parent = value;
|
|
|
|
- RaisedOnPropertyChanged("Parent");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private string _description;
|
|
|
|
- public string Description
|
|
|
|
- {
|
|
|
|
- get { return _description; }
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _description = value;
|
|
|
|
- RaisedOnPropertyChanged("Description");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private ImageSource? _image;
|
|
|
|
- public ImageSource? Image
|
|
|
|
- {
|
|
|
|
- get { return _image; }
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- _image = value;
|
|
|
|
- RaisedOnPropertyChanged("Image");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
-
|
|
|
|
- public void RaisedOnPropertyChanged(string propertyName)
|
|
|
|
- {
|
|
|
|
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public DynamicTreeNode(DynamicTreeNodes owner)
|
|
|
|
- {
|
|
|
|
- _owner = owner;
|
|
|
|
- _description = "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public DynamicTreeNode(DynamicTreeNodes owner, Guid id, Guid parent) : this(owner)
|
|
|
|
- {
|
|
|
|
- _id = id;
|
|
|
|
- _parent = parent;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public class DynamicTreeNodes
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- private List<DynamicTreeNode> _nodes;
|
|
|
|
- public ObservableCollection<DynamicTreeNode> Nodes => new ObservableCollection<DynamicTreeNode>(_nodes.Where(x => x.Parent == Guid.Empty));
|
|
|
|
-
|
|
|
|
- public DynamicTreeNode? this[Guid id] => _nodes.FirstOrDefault(x => x.ID == id);
|
|
|
|
-
|
|
|
|
- public DynamicTreeNodes()
|
|
|
|
- {
|
|
|
|
- _nodes = new List<DynamicTreeNode>();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public DynamicTreeNode Add(Guid id, Guid parent)
|
|
|
|
- {
|
|
|
|
- var node = new DynamicTreeNode(this, id, parent);
|
|
|
|
- _nodes.Add(node);
|
|
|
|
- return node;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void GetChildren(List<Guid> nodes, Guid id)
|
|
|
|
- {
|
|
|
|
- nodes.Add(id);
|
|
|
|
- var children = GetChilden(id);
|
|
|
|
- foreach (var child in children)
|
|
|
|
- GetChildren(nodes, child.ID);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public ObservableCollection<DynamicTreeNode> GetChilden(Guid id)
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- return new ObservableCollection<DynamicTreeNode>(_nodes.Where(x => x.Parent.Equals(id) && (x.ID != id)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void Load<T>(CoreTable table, Expression<Func<T, Guid>> id, Expression<Func<T, Guid>> parentid, Expression<Func<T, String>> description)
|
|
|
|
- {
|
|
|
|
- _nodes.Clear();
|
|
|
|
- foreach (var row in table.Rows)
|
|
|
|
- {
|
|
|
|
- Guid _id = row.Get<T, Guid>(id);
|
|
|
|
- Guid _parent = row.Get<T, Guid>(parentid);
|
|
|
|
- String _description = row.Get<T, String>(description);
|
|
|
|
- Add(_id, _parent).Description = _description;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ // public class CoreTreeNode : INotifyPropertyChanged
|
|
|
|
+ // {
|
|
|
|
+ //
|
|
|
|
+ // private CoreTreeNodes _owner;
|
|
|
|
+ //
|
|
|
|
+ // public ObservableCollection<CoreTreeNode> Children => _owner.GetChilden(_id);
|
|
|
|
+ //
|
|
|
|
+ // private Guid _id;
|
|
|
|
+ // public Guid ID
|
|
|
|
+ // {
|
|
|
|
+ // get { return _id; }
|
|
|
|
+ // set
|
|
|
|
+ // {
|
|
|
|
+ // _id = value;
|
|
|
|
+ // RaisedOnPropertyChanged("ID");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // private Guid _parent;
|
|
|
|
+ // public Guid Parent
|
|
|
|
+ // {
|
|
|
|
+ // get { return _parent; }
|
|
|
|
+ // set
|
|
|
|
+ // {
|
|
|
|
+ // _parent = value;
|
|
|
|
+ // RaisedOnPropertyChanged("Parent");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // private string _description;
|
|
|
|
+ // public string Description
|
|
|
|
+ // {
|
|
|
|
+ // get { return _description; }
|
|
|
|
+ // set
|
|
|
|
+ // {
|
|
|
|
+ // _description = value;
|
|
|
|
+ // RaisedOnPropertyChanged("Description");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // private ImageSource? _image;
|
|
|
|
+ // public ImageSource? Image
|
|
|
|
+ // {
|
|
|
|
+ // get { return _image; }
|
|
|
|
+ // set
|
|
|
|
+ // {
|
|
|
|
+ // _image = value;
|
|
|
|
+ // RaisedOnPropertyChanged("Image");
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
+ //
|
|
|
|
+ // public void RaisedOnPropertyChanged(string propertyName)
|
|
|
|
+ // {
|
|
|
|
+ // PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public CoreTreeNode(CoreTreeNodes owner)
|
|
|
|
+ // {
|
|
|
|
+ // _owner = owner;
|
|
|
|
+ // _description = "";
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public CoreTreeNode(CoreTreeNodes owner, Guid id, Guid parent) : this(owner)
|
|
|
|
+ // {
|
|
|
|
+ // _id = id;
|
|
|
|
+ // _parent = parent;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public class CoreTreeNodes
|
|
|
|
+ // {
|
|
|
|
+ //
|
|
|
|
+ // private List<CoreTreeNode> _nodes;
|
|
|
|
+ // public ObservableCollection<CoreTreeNode> Nodes => new ObservableCollection<CoreTreeNode>(_nodes.Where(x => x.Parent == Guid.Empty));
|
|
|
|
+ //
|
|
|
|
+ // public CoreTreeNode? this[Guid id] => _nodes.FirstOrDefault(x => x.ID == id);
|
|
|
|
+ //
|
|
|
|
+ // public CoreTreeNodes()
|
|
|
|
+ // {
|
|
|
|
+ // _nodes = new List<CoreTreeNode>();
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public CoreTreeNode Add(Guid id, Guid parent)
|
|
|
|
+ // {
|
|
|
|
+ // var node = new CoreTreeNode(this, id, parent);
|
|
|
|
+ // _nodes.Add(node);
|
|
|
|
+ // return node;
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public void GetChildren(List<Guid> nodes, Guid id)
|
|
|
|
+ // {
|
|
|
|
+ // nodes.Add(id);
|
|
|
|
+ // var children = GetChilden(id);
|
|
|
|
+ // foreach (var child in children)
|
|
|
|
+ // GetChildren(nodes, child.ID);
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public ObservableCollection<CoreTreeNode> GetChilden(Guid id)
|
|
|
|
+ // {
|
|
|
|
+ //
|
|
|
|
+ // return new ObservableCollection<CoreTreeNode>(_nodes.Where(x => x.Parent.Equals(id) && (x.ID != id)));
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // public void Load<T>(CoreTable table, Expression<Func<T, Guid>> id, Expression<Func<T, Guid>> parentid, Expression<Func<T, String>> description)
|
|
|
|
+ // {
|
|
|
|
+ // _nodes.Clear();
|
|
|
|
+ // foreach (var row in table.Rows)
|
|
|
|
+ // {
|
|
|
|
+ // Guid _id = row.Get<T, Guid>(id);
|
|
|
|
+ // Guid _parent = row.Get<T, Guid>(parentid);
|
|
|
|
+ // String _description = row.Get<T, String>(description);
|
|
|
|
+ // Add(_id, _parent).Description = _description;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //
|
|
|
|
+ // }
|
|
|
|
|
|
public enum DynamicTreeOption
|
|
public enum DynamicTreeOption
|
|
{
|
|
{
|
|
@@ -144,9 +140,9 @@ namespace InABox.DynamicGrid
|
|
Delete
|
|
Delete
|
|
}
|
|
}
|
|
|
|
|
|
- public delegate void OnSelectItem(DynamicTreeNode node);
|
|
|
|
|
|
+ public delegate void OnSelectItem(CoreTreeNode node);
|
|
|
|
|
|
- public delegate void OnContextMenuOpening(DynamicTreeNode node, ContextMenu menu);
|
|
|
|
|
|
+ public delegate void OnContextMenuOpening(CoreTreeNode node, ContextMenu menu);
|
|
|
|
|
|
public abstract class DynamicTreeView<T> : ContentControl where T : BaseObject, new()
|
|
public abstract class DynamicTreeView<T> : ContentControl where T : BaseObject, new()
|
|
{
|
|
{
|
|
@@ -192,6 +188,17 @@ namespace InABox.DynamicGrid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private bool _shownumbers = false;
|
|
|
|
+ public bool ShowNumbers
|
|
|
|
+ {
|
|
|
|
+ get => _shownumbers;
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ _shownumbers = value;
|
|
|
|
+ _tree.Columns[1].Width = value ? 50 : 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/*public double RowHeight
|
|
/*public double RowHeight
|
|
{
|
|
{
|
|
get => _tree.RowHeight;
|
|
get => _tree.RowHeight;
|
|
@@ -216,12 +223,12 @@ namespace InABox.DynamicGrid
|
|
_tree.AutoExpandMode = AutoExpandMode.AllNodesExpanded;
|
|
_tree.AutoExpandMode = AutoExpandMode.AllNodesExpanded;
|
|
//_tree.NodeCollapsing += (o, e) => { e.Cancel = true; };
|
|
//_tree.NodeCollapsing += (o, e) => { e.Cancel = true; };
|
|
_tree.HeaderRowHeight = 0D;
|
|
_tree.HeaderRowHeight = 0D;
|
|
- _tree.SelectionChanged += (o,e) => OnSelectItem?.Invoke((_tree.SelectedItem as DynamicTreeNode)!);
|
|
|
|
|
|
+ _tree.SelectionChanged += (o,e) => OnSelectItem?.Invoke((_tree.SelectedItem as CoreTreeNode)!);
|
|
_tree.AllowSelectionOnExpanderClick = false;
|
|
_tree.AllowSelectionOnExpanderClick = false;
|
|
|
|
|
|
_menu = new ContextMenu();
|
|
_menu = new ContextMenu();
|
|
var additem = new MenuItem() { Header = "Add Child Folder" };
|
|
var additem = new MenuItem() { Header = "Add Child Folder" };
|
|
- additem.Click += (o, e) => { DoAddItem((_tree.SelectedItem as DynamicTreeNode)!.ID, true); };
|
|
|
|
|
|
+ additem.Click += (o, e) => { DoAddItem((_tree.SelectedItem as CoreTreeNode)!.ID, true); };
|
|
_menu.Items.Add(additem);
|
|
_menu.Items.Add(additem);
|
|
|
|
|
|
_tree.ContextMenuOpening += _tree_ContextMenuOpening;
|
|
_tree.ContextMenuOpening += _tree_ContextMenuOpening;
|
|
@@ -233,11 +240,21 @@ namespace InABox.DynamicGrid
|
|
_tree.RowStyle = cellStyle;
|
|
_tree.RowStyle = cellStyle;
|
|
|
|
|
|
_tree.SelectionBackground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x11, 0x9E, 0xD9));
|
|
_tree.SelectionBackground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x11, 0x9E, 0xD9));
|
|
|
|
+
|
|
_tree.Columns.Add(new TreeGridTextColumn()
|
|
_tree.Columns.Add(new TreeGridTextColumn()
|
|
{
|
|
{
|
|
MappingName = "Description"
|
|
MappingName = "Description"
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ _tree.Columns.Add(new TreeGridTextColumn()
|
|
|
|
+ {
|
|
|
|
+ MappingName = "Number",
|
|
|
|
+ Width = _shownumbers ? 50 : 0,
|
|
|
|
+ TextAlignment = TextAlignment.Right
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+
|
|
_tree.ColumnSizer = TreeColumnSizer.Star;
|
|
_tree.ColumnSizer = TreeColumnSizer.Star;
|
|
_tree.RowHeight = 30D;
|
|
_tree.RowHeight = 30D;
|
|
_tree.SetValue(Grid.RowProperty, 0);
|
|
_tree.SetValue(Grid.RowProperty, 0);
|
|
@@ -276,7 +293,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
#region Public Interface
|
|
#region Public Interface
|
|
|
|
|
|
- public void AddItem(DynamicTreeNode? parentNode = null, bool edit = true)
|
|
|
|
|
|
+ public void AddItem(CoreTreeNode? parentNode = null, bool edit = true)
|
|
{
|
|
{
|
|
var id = parentNode?.ID ?? Guid.Empty;
|
|
var id = parentNode?.ID ?? Guid.Empty;
|
|
DoAddItem(id, edit);
|
|
DoAddItem(id, edit);
|
|
@@ -290,7 +307,7 @@ namespace InABox.DynamicGrid
|
|
_menu.Items.Clear();
|
|
_menu.Items.Clear();
|
|
if (OnContextMenuOpening is not null)
|
|
if (OnContextMenuOpening is not null)
|
|
{
|
|
{
|
|
- OnContextMenuOpening.Invoke((_tree.SelectedItem as DynamicTreeNode)!, _menu);
|
|
|
|
|
|
+ OnContextMenuOpening.Invoke((_tree.SelectedItem as CoreTreeNode)!, _menu);
|
|
if(_menu.Items.Count == 0)
|
|
if(_menu.Items.Count == 0)
|
|
{
|
|
{
|
|
e.Handled = true;
|
|
e.Handled = true;
|
|
@@ -298,7 +315,7 @@ namespace InABox.DynamicGrid
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- _menu.AddItem("Add Item", null, (_tree.SelectedItem as DynamicTreeNode)!.ID, (id) => DoAddItem(id,true));
|
|
|
|
|
|
+ _menu.AddItem("Add Item", null, (_tree.SelectedItem as CoreTreeNode)!.ID, (id) => DoAddItem(id,true));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -412,7 +429,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void EditItem(Button button)
|
|
private void EditItem(Button button)
|
|
{
|
|
{
|
|
- var node = _tree.SelectedItem as DynamicTreeNode;
|
|
|
|
|
|
+ var node = _tree.SelectedItem as CoreTreeNode;
|
|
if (node == null)
|
|
if (node == null)
|
|
{
|
|
{
|
|
MessageBox.Show("Please Select an item to edit!");
|
|
MessageBox.Show("Please Select an item to edit!");
|
|
@@ -428,7 +445,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void DeleteItem(Button button)
|
|
private void DeleteItem(Button button)
|
|
{
|
|
{
|
|
- var node = _tree.SelectedItem as DynamicTreeNode;
|
|
|
|
|
|
+ var node = _tree.SelectedItem as CoreTreeNode;
|
|
if (node == null)
|
|
if (node == null)
|
|
{
|
|
{
|
|
MessageBox.Show("Please Select an item to edit!");
|
|
MessageBox.Show("Please Select an item to edit!");
|
|
@@ -441,13 +458,13 @@ namespace InABox.DynamicGrid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public DynamicTreeNodes Nodes { get; set; }
|
|
|
|
|
|
+ public CoreTreeNodes Nodes { get; set; }
|
|
|
|
|
|
protected abstract void DoRefresh(Action<CoreTable?, Exception?> action);
|
|
protected abstract void DoRefresh(Action<CoreTable?, Exception?> action);
|
|
|
|
|
|
private void AfterRefresh()
|
|
private void AfterRefresh()
|
|
{
|
|
{
|
|
- var nodes = new DynamicTreeNodes();
|
|
|
|
|
|
+ var nodes = new CoreTreeNodes();
|
|
foreach (var row in Data.Rows)
|
|
foreach (var row in Data.Rows)
|
|
{
|
|
{
|
|
var _id = row.Get(ID);
|
|
var _id = row.Get(ID);
|
|
@@ -462,6 +479,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
public void Refresh()
|
|
public void Refresh()
|
|
{
|
|
{
|
|
|
|
+ _tree.ItemsSource = null;
|
|
DoRefresh((table, exception) =>
|
|
DoRefresh((table, exception) =>
|
|
{
|
|
{
|
|
if(exception != null)
|
|
if(exception != null)
|