2015-06-11 17:01:52 -04:00
|
|
|
|
using System;
|
2015-06-18 16:08:44 -04:00
|
|
|
|
using System.Collections.Generic;
|
2015-06-08 15:17:34 -04:00
|
|
|
|
|
2015-06-24 14:57:16 -04:00
|
|
|
|
namespace Filtration.ObjectModel
|
2015-06-08 15:17:34 -04:00
|
|
|
|
{
|
2015-06-24 14:57:16 -04:00
|
|
|
|
public class ItemFilterBlockGroup
|
2015-06-08 15:17:34 -04:00
|
|
|
|
{
|
2018-09-06 06:54:54 -04:00
|
|
|
|
private bool? _isShowChecked;
|
|
|
|
|
private bool? _isEnableChecked;
|
2015-06-11 16:01:33 -04:00
|
|
|
|
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false, bool isLeafNode = false)
|
2015-06-08 17:29:39 -04:00
|
|
|
|
{
|
|
|
|
|
GroupName = groupName;
|
|
|
|
|
ParentGroup = parent;
|
2015-06-14 14:17:39 -04:00
|
|
|
|
Advanced = advanced;
|
2015-06-18 16:08:44 -04:00
|
|
|
|
ChildGroups = new List<ItemFilterBlockGroup>();
|
2018-09-06 06:54:54 -04:00
|
|
|
|
IsLeafNode = isLeafNode;
|
2015-06-08 17:29:39 -04:00
|
|
|
|
}
|
2015-06-18 16:08:44 -04:00
|
|
|
|
|
2015-12-13 15:17:15 -05:00
|
|
|
|
public string GroupName { get; }
|
2018-09-07 08:26:12 -04:00
|
|
|
|
public ItemFilterBlockGroup ParentGroup { get; set; }
|
2015-12-13 15:17:15 -05:00
|
|
|
|
public List<ItemFilterBlockGroup> ChildGroups { get; }
|
|
|
|
|
public bool Advanced { get; }
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public bool IsLeafNode { get; }
|
2015-06-14 14:17:39 -04:00
|
|
|
|
|
2018-09-07 08:26:12 -04:00
|
|
|
|
public event EventHandler BlockGroupStatusChanged;
|
|
|
|
|
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public bool? IsShowChecked
|
2015-06-11 16:01:33 -04:00
|
|
|
|
{
|
2018-09-06 02:59:09 -04:00
|
|
|
|
get { return _isShowChecked; }
|
2015-06-11 16:01:33 -04:00
|
|
|
|
set
|
|
|
|
|
{
|
2018-09-06 02:59:09 -04:00
|
|
|
|
if (value != _isShowChecked)
|
2015-06-11 16:01:33 -04:00
|
|
|
|
{
|
2018-09-06 02:59:09 -04:00
|
|
|
|
_isShowChecked = value;
|
2015-06-11 17:01:52 -04:00
|
|
|
|
// Raise an event to let blocks that have this block group assigned that
|
|
|
|
|
// they might need to change their Action due to the block group status changing.
|
2015-12-13 15:17:15 -05:00
|
|
|
|
BlockGroupStatusChanged?.Invoke(null, null);
|
2015-06-11 16:01:33 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public bool? IsEnableChecked
|
2018-09-06 02:59:09 -04:00
|
|
|
|
{
|
|
|
|
|
get { return _isEnableChecked; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _isEnableChecked)
|
|
|
|
|
{
|
|
|
|
|
_isEnableChecked = value;
|
|
|
|
|
// Raise an event to let blocks that have this block group assigned that
|
|
|
|
|
// they might need to change their Enabled due to the block group status changing.
|
|
|
|
|
BlockGroupStatusChanged?.Invoke(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-07 08:26:12 -04:00
|
|
|
|
public void ClearStatusChangeSubscribers()
|
|
|
|
|
{
|
|
|
|
|
BlockGroupStatusChanged = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddOrJoinBlockGroup(ItemFilterBlockGroup blockGroup)
|
|
|
|
|
{
|
|
|
|
|
var childIndex = ChildGroups.FindIndex(item => item.GroupName.Equals(blockGroup.GroupName));
|
|
|
|
|
if (!blockGroup.IsLeafNode && childIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
while(blockGroup.ChildGroups.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ChildGroups[childIndex].AddOrJoinBlockGroup(blockGroup.ChildGroups[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(blockGroup.ParentGroup != null)
|
|
|
|
|
{
|
|
|
|
|
blockGroup.ParentGroup.ChildGroups.Remove(blockGroup);
|
|
|
|
|
}
|
|
|
|
|
blockGroup.ParentGroup = this;
|
|
|
|
|
ChildGroups.Add(blockGroup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DetachSelf(bool keepChildren)
|
|
|
|
|
{
|
|
|
|
|
if(ParentGroup == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(IsLeafNode && ParentGroup.ParentGroup != null && ParentGroup.ChildGroups.Count < 2)
|
|
|
|
|
{
|
|
|
|
|
ParentGroup.DetachSelf(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ParentGroup.ChildGroups.Remove(this);
|
|
|
|
|
|
|
|
|
|
if (keepChildren)
|
|
|
|
|
{
|
|
|
|
|
foreach(var child in ChildGroups)
|
|
|
|
|
{
|
|
|
|
|
ParentGroup.AddOrJoinBlockGroup(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParentGroup = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 16:08:44 -04:00
|
|
|
|
public override string ToString()
|
2015-06-14 14:17:39 -04:00
|
|
|
|
{
|
2018-09-06 07:31:06 -04:00
|
|
|
|
if(ParentGroup == null)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
2015-06-14 14:17:39 -04:00
|
|
|
|
|
2015-06-24 18:04:54 -04:00
|
|
|
|
var outputString = (Advanced ? "~" : string.Empty) + GroupName;
|
2015-06-14 14:17:39 -04:00
|
|
|
|
|
2018-09-06 07:31:06 -04:00
|
|
|
|
var parentOutput = ParentGroup.ToString();
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(parentOutput))
|
2015-06-14 14:17:39 -04:00
|
|
|
|
{
|
2018-09-06 07:31:06 -04:00
|
|
|
|
outputString = parentOutput + (IsLeafNode ? string.Empty : " - " + outputString);
|
2015-06-14 14:17:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 16:08:44 -04:00
|
|
|
|
return outputString;
|
2015-06-11 16:01:33 -04:00
|
|
|
|
}
|
2015-06-08 15:17:34 -04:00
|
|
|
|
}
|
|
|
|
|
}
|