77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing.Design;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using System.Xml;
|
|
|
|
namespace JD.Winforms.XmlGrid
|
|
{
|
|
class FactoryVar : ContainerCollectionClass
|
|
{
|
|
private List<string> factoryTypes;
|
|
|
|
private FactoryVar()
|
|
{
|
|
factoryTypes = new List<string>();
|
|
}
|
|
|
|
public List<string> GetTypes()
|
|
{
|
|
return factoryTypes;
|
|
}
|
|
|
|
public static FactoryVar ParseXml(XmlNode Node, IObjectNodeInterface Parent )
|
|
{
|
|
FactoryVar ret = new FactoryVar();
|
|
|
|
ret.SetParent(Parent);
|
|
ret.name = Node.Attributes["strTAG"].Value;
|
|
|
|
foreach (XmlNode child in Node.ChildNodes)
|
|
{
|
|
ret.factoryTypes.Add(child.Name);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
public class FactoryEditor : System.Drawing.Design.UITypeEditor
|
|
{
|
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
|
{
|
|
if (context != null && context.Instance != null)
|
|
{
|
|
if (!context.PropertyDescriptor.IsReadOnly)
|
|
{
|
|
return UITypeEditorEditStyle.Modal;
|
|
}
|
|
}
|
|
return UITypeEditorEditStyle.None;
|
|
}
|
|
|
|
[RefreshProperties(RefreshProperties.All)]
|
|
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
|
|
{
|
|
if (context == null || provider == null || context.Instance == null)
|
|
{
|
|
return base.EditValue(provider, value);
|
|
}
|
|
|
|
FactoryVar factory = (FactoryVar)value;
|
|
CommonDialogs.SelectItemListDlg dlg = new CommonDialogs.SelectItemListDlg();
|
|
|
|
dlg.SetComponents(factory.GetTypes());
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
factory.SetIsObject(true);
|
|
factory.CreateObject(dlg.SelectedComponent);
|
|
}
|
|
|
|
return factory;
|
|
}
|
|
}
|
|
}
|