using ActiproSoftware.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
namespace EmpirBus.Switching.FirmwareManager.App.Feature.Common
{
[ContentProperty("Children")]
public partial class TreeNodeModel : ObservableObject
{
public ObservableCollection<TreeNodeModel> Children { get; set; } = new ObservableCollection<TreeNodeModel>();
[ObservableProperty]
private ICommand _defaultActionCommand;
[ObservableProperty]
private ImageSource _imageSource;
[ObservableProperty]
private bool _isDraggable = true;
[ObservableProperty]
private bool _isEditable;
[ObservableProperty]
private bool _isEditing;
[ObservableProperty]
private bool _isExpanded = true;
[ObservableProperty]
private bool _isLoading;
[ObservableProperty]
private bool _isSelectable = true;
[ObservableProperty]
private bool _isSelected;
[ObservableProperty]
private string _name;
[ObservableProperty]
private object _tag;
/// <summary>
/// The Firmware model
/// </summary>
[ObservableProperty]
private object _innerModel;
}
}
public class DefaultTreeListBoxItemAdapter : TreeListBoxItemAdapter
{
public SortDescription? SortDescription { get; set; }
public DefaultTreeListBoxItemAdapter()
{
this.ChildrenPath = "Children";
this.IsEditingPath = "IsEditing";
this.IsExpandedPath = "IsExpanded";
this.IsLoadingPath = "IsLoading";
this.IsSelectablePath = "IsSelectable";
this.IsSelectedPath = "IsSelected";
}
public override IEnumerable GetChildren(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
var enumerable = (model != null ? model.Children : null);
if (this.SortDescription.HasValue)
{
var collectionViewSource = new CollectionViewSource()
{
SortDescriptions = {
this.SortDescription.Value
},
Source = enumerable,
};
return collectionViewSource.View;
}
return base.GetChildren(ownerControl, item);
}
public override ICommand GetDefaultActionCommand(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.DefaultActionCommand : null);
}
public override bool GetIsDraggable(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsDraggable : false);
}
public override bool GetIsEditable(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsEditable : false);
}
public override bool GetIsEditing(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsEditing : false);
}
public override bool GetIsExpanded(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsExpanded : false);
}
public override bool GetIsLoading(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsLoading : false);
}
public override bool GetIsSelectable(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsSelectable : true);
}
public override bool GetIsSelected(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.IsSelected : false);
}
public override string GetPath(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.Name : null);
}
public override string GetSearchText(TreeListBox ownerControl, object item)
{
var model = item as TreeNodeModel;
return (model != null ? model.Name : null);
}
public override void SetIsEditing(TreeListBox ownerControl, object item, bool value)
{
var model = item as TreeNodeModel;
if (model != null)
model.IsEditing = value;
}
public override void SetIsExpanded(TreeListBox ownerControl, object item, bool value)
{
var model = item as TreeNodeModel;
if (model != null)
model.IsExpanded = value;
}
public override void SetIsSelected(TreeListBox ownerControl, object item, bool value)
{
var model = item as TreeNodeModel;
if (model != null)
model.IsSelected = value;
}
}