|
using System;
using System.Collections;
using System.ComponentModel;
namespace GFramework
{
/// <summary>
/// Represents the root of the element hierachy.
/// </summary>
public class GRootElement : GElement, IGServiceManager
{
#region Constructor
public GRootElement()
{
m_Services = new Hashtable();
m_EventListeners = new GNodeCollection(this);
}
#endregion
#region Interface Implementation
#region IGServiceManager
public void RegisterService(object key, GService service)
{
if (m_Services.ContainsKey(key))
{
m_Services[key] = service;
}
else
{
m_Services.Add(key, service);
}
}
public void UnRegisterService(object key)
{
if (m_Services.ContainsKey(key))
{
m_Services.Remove(key);
}
}
public GService GetService(object key)
{
return (GService)m_Services[key];
}
#endregion
#endregion
#region Public Overridables
public virtual void BeginInit()
{
m_InitializeLock++;
}
public virtual void EndInit()
{
m_InitializeLock--;
m_InitializeLock = Math.Max(0, m_InitializeLock);
if (m_InitializeLock > 0)
{
return;
}
OnEndInit();
}
#endregion
#region Protected Overridables
protected virtual void OnEndInit()
{
int count = m_Children.Count;
for (int i = 0; i < count; i++)
{
m_Children[i].SetRoot(this);
}
}
#endregion
#region Protected Overrides
protected internal override void OnCollectionNotification(GEventArgs e)
{
base.OnCollectionNotification(e);
if (m_InitializeLock > 0)
{
return;
}
GCollectionEventData data = (GCollectionEventData)e.m_Data;
switch (data.m_Notification)
{
case CollectionNotification.ElementAdded:
case CollectionNotification.ElementInserted:
((GNode)data.m_Element).SetRoot(this);
break;
case CollectionNotification.ElementRemoved:
((GNode)data.m_Element).SetRoot(null);
break;
}
}
#endregion
#region Properties
public GNodeCollection EventListeners
{
get
{
return m_EventListeners;
}
}
#endregion
#region Fields
[NonSerialized]
internal int m_InitializeLock;
[NonSerialized]
internal GNodeCollection m_EventListeners;
[NonSerialized]
internal Hashtable m_Services;
#endregion
#region BiState Constants
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
.NET & C# addicted. Win8 & WinRT enthusiast and researcher @Telerik.