using System;
using System.Collections.Generic;
using JD.Collections.Interfaces;
using JD.TeaBoxAddinSystem.Addins.Description.Conditions;
namespace JD.TeaBoxAddinSystem.Addins.Description
{
///
/// Defines an in an .
///
public sealed class ExtensionNodeDescription : NodeDescription
{
#region Variables
private const string AnonymousId = "";
internal const string IdAttributeName = "id";
internal const string InsertAfterAttributeName = "insertafter";
internal const string InsertBeforeAttributeName = "insertbefore";
private readonly ExtensionNodeDescriptionCollection m_childNodes = new ExtensionNodeDescriptionCollection();
private readonly AddinObjectCollection m_conditions = new AddinObjectCollection();
#endregion
#region Constructor
///
/// Constructor.
///
///
public ExtensionNodeDescription(string name)
: base(name)
{
}
#endregion
#region Properties
///
/// Child Nodes.
///
public IKeyedList ChildNodes
{
get
{
return m_childNodes;
}
}
///
/// Conditions that affect this node.
///
public IList Conditions
{
get
{
return m_conditions;
}
}
///
/// Id.
///
public string Id
{
get
{
return Attributes[IdAttributeName];
}
set
{
Attributes[IdAttributeName] = value;
}
}
///
/// Id to display in error messages.
///
internal string DisplayId
{
get
{
string id = Id;
if (!string.IsNullOrEmpty(id))
{
return id;
}
return AnonymousId;
}
}
///
/// Gets/Sets the extension node Ids (comma separated) that this node should be inserted after.
///
///
/// This is no guarantee. If there is circular dependency between the nodes, this order will probably not be respected
///
public string InsertAfter
{
get
{
return Attributes[InsertAfterAttributeName];
}
set
{
Attributes[InsertAfterAttributeName] = value;
}
}
///
/// Gets/Sets the extension node Ids (comma separated) that this node should be inserted before.
///
///
/// This is no guarantee. If there is circular dependency between the nodes, this order will probably not be respected
///
public string InsertBefore
{
get
{
return Attributes[InsertBeforeAttributeName];
}
set
{
Attributes[InsertBeforeAttributeName] = value;
}
}
#endregion
#region Methods
///
/// Overriden.
///
///
internal override void OnModuleChanged(EventArgs e)
{
m_childNodes.Owner = Module;
m_conditions.Owner = Module;
base.OnModuleChanged(e);
}
///
/// Overriden.
///
///
public override string ToString()
{
return
$"[ExtensionNodeDescription ({Name}): Id={(string.IsNullOrEmpty(Id) ? AnonymousId : Id)}, {ChildNodes.Count} child nodes, {Conditions.Count} conditions]";
}
#endregion
}
}