forked from MeowBot/OpenQuant.API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltIDGroupListEditor.cs
More file actions
75 lines (75 loc) · 2.08 KB
/
Copy pathAltIDGroupListEditor.cs
File metadata and controls
75 lines (75 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using SmartQuant.FIX;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace OpenQuant.API.Design
{
internal class AltIDGroupListEditor : ArrayEditor
{
private Instrument instrument;
public AltIDGroupListEditor() : base(typeof(ArrayList))
{
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (context != null && context.Instance is Instrument)
{
this.instrument = (Instrument)context.Instance;
}
return base.EditValue(context, provider, value);
}
protected override object CreateInstance(Type itemType)
{
if (itemType == typeof(AltIDGroup))
{
AltIDGroup[] result = null;
AltSourceForm altSourceForm = new AltSourceForm();
if (altSourceForm.ShowDialog() == DialogResult.OK)
{
AltIDGroup altIDGroup = this.instrument.AltIDGroups.Add(altSourceForm.AltSource);
result = new AltIDGroup[]
{
altIDGroup
};
}
return result;
}
return base.CreateInstance(itemType);
}
protected override IList GetObjectsFromInstance(object instance)
{
if (instance is ICollection)
{
return new ArrayList((ICollection)instance);
}
return null;
}
protected override object[] GetItems(object editValue)
{
List<object> list = new List<object>();
foreach (FIXSecurityAltIDGroup group in this.instrument.instrument.SecurityAltIDGroup)
{
list.Add(new AltIDGroup(this.instrument, group));
}
return list.ToArray();
}
protected override object SetItems(object editValue, object[] value)
{
AltIDGroupList altIDGroupList = editValue as AltIDGroupList;
altIDGroupList.instrument.instrument.SecurityAltIDGroup.Clear();
for (int i = 0; i < value.Length; i++)
{
AltIDGroup altIDGroup = (AltIDGroup)value[i];
altIDGroupList.instrument.instrument.SecurityAltIDGroup.Add(altIDGroup.group);
}
return altIDGroupList;
}
protected override Type CreateCollectionItemType()
{
return typeof(AltIDGroup);
}
}
}