Author: toshok
Date: 2006-06-21 06:41:07 -0400 (Wed, 21 Jun 2006)
New Revision: 61897
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/BindingContext.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyManager.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedCurrencyManager.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedPropertyManager.cs
Log:
2006-06-21 Chris Toshok <[EMAIL PROTECTED]>
* CurrencyManager.cs: push some of the original type checking from
BindingContext.CreateBindingManager to here, and remove some of
the finalType stuff. Need more tests to make sure I've got the
ListName part right, and we might need more in SetDataSource.
* PropertyManager.cs: add a ctor that takes just the datasource,
and no property name. Make SetDataSource work with a null
property_name, and make Current return the data_source if the
property descriptor is null. this makes 'string foo = "hi";
BindingContext[foo].Current' return "hi" as it should.
* RelatedCurrencyManager.cs: make this code more generic - there's
no reason the parent manager has to be CurrencyManager, and
there's no reason to pass the DataRelation. It suffices to use a
BindingManagerBase and PropetyDescriptor.
* RelatedPropertyManager.cs: make a similar change here.
* BindingContext.cs: make CreateBindingManager the beautiful, tiny
flower I knew it could be.
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/BindingContext.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/BindingContext.cs
2006-06-21 10:30:58 UTC (rev 61896)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/BindingContext.cs
2006-06-21 10:41:07 UTC (rev 61897)
@@ -89,7 +89,6 @@
return res;
res = CreateBindingManager (data_source,
data_member);
- Console.WriteLine ("CREATED: {0}", res);
if (res == null)
return null;
managers [key] = res;
@@ -99,158 +98,35 @@
private BindingManagerBase CreateBindingManager (object
data_source, string data_member)
{
-#if true
- /* the following is gross and special cased
- and needs to die. a more proper
- implementation would be something like
- what's down below in the #else section,
- where the recursion over the nagivation
- path is at the toplevel.
- */
-
- DataTable table = data_source as DataTable;
- if (table == null && data_source is DataView)
- table = ((DataView) data_source).Table;
-
- DataSet dataset = data_source as DataSet;
- if (table != null) {
- if (data_member == "")
- return new CurrencyManager (new
DataView (table));
- else {
- BindingMemberInfo info = new
BindingMemberInfo (data_member);
-
- Console.WriteLine ("Getting
parent_manager for {0}", info.BindingPath);
- CurrencyManager parent_manager =
(CurrencyManager) this[data_source, info.BindingPath];
-
- DataColumn col = table.Columns
[info.BindingField];
-
- if (col != null) {
- Console.WriteLine ("+ creating
related property manager for column {0}", info.BindingField);
- return new
RelatedPropertyManager (parent_manager, info.BindingField);
- }
- throw new ArgumentException
(String.Format ("Specified data member {0} does not exist in the data table
{1}",
-
info.BindingField, table.TableName));
-
- }
- }
- else if (data_member != "" && dataset != null) {
- BindingMemberInfo info = new BindingMemberInfo
(data_member);
-
- if (info.BindingPath == "") {
- table = dataset.Tables
[info.BindingField];
- if (table == null)
- throw new ArgumentException
(String.Format ("Specified data member table `{0}' does not exist in the data
source DataSet", info.BindingField));
-
- return new CurrencyManager (new
DataView (table));
- }
- else {
- Console.WriteLine ("Getting
parent_manager for {0}", info.BindingPath);
- CurrencyManager parent_manager =
(CurrencyManager) this[data_source, info.BindingPath];
-
- table =
((DataView)parent_manager.data_source).Table;
-
- DataColumn col = table.Columns
[info.BindingField];
- DataRelation rel = dataset.Relations
[info.BindingField];
-
- if (col != null) {
- Console.WriteLine ("+ creating
related property manager for column {0}", info.BindingField);
- return new
RelatedPropertyManager (parent_manager, info.BindingField);
- }
- else if (rel != null) {
- Console.WriteLine ("+ creating
related currency manager for relation {0}", info.BindingField);
- return new
RelatedCurrencyManager (parent_manager, rel);
- }
- else
- throw new ArgumentException
(String.Format ("Specified data member {0} does not exist in the data table
{1}",
-
info.BindingField, table.TableName));
-
- }
- }
- else if (data_source is IList) {
- IList list = (IList)data_source;
-
- if (data_member == "") {
- return new CurrencyManager (list);
- }
- else {
- CurrencyManager parent_manager =
(CurrencyManager) this[data_source, ""];
-
- if (parent_manager.Count == 0 ||
- TypeDescriptor.GetProperties
(parent_manager.GetItem (0)).Find (data_member, true) == null) {
- throw new ArgumentException
("Cannot create a child list for field {0}", data_member);
- }
-
-
- Console.WriteLine ("creating related
property manager for column {0} on an IList source", data_member);
- return new RelatedPropertyManager
(parent_manager, data_member);
- }
- } else if (data_source is IListSource) {
- return new CurrencyManager (((IListSource)
data_source).GetList ());
- }
- else {
- /* must be a property */
- Console.WriteLine ("creating PropertyManager");
- return new PropertyManager (data_source,
data_member);
- }
-#else
if (data_member == "") {
- if (data_source is DataSet) {
- return new CurrencyManager (new
DataViewManager ((DataSet)data_source));
- }
- else if (data_source is DataTable) {
- return new CurrencyManager (new
DataView ((DataTable)data_source));
- }
- else if (data_source is DataView) {
- return new CurrencyManager
((DataView)data_source);
- }
- else if (data_source is IListSource) {
- return new CurrencyManager
(((IListSource) data_source).GetList ());
- }
- else if (data_source is IList) {
- return new CurrencyManager ((IList)
data_source);
- }
- else {
- return new PropertyManager
(data_source, data_member);
- }
+ if (IsListType (data_source.GetType ()))
+ return new CurrencyManager
(data_source);
+ else
+ return new PropertyManager
(data_source);
}
else {
BindingMemberInfo info = new BindingMemberInfo
(data_member);
- Console.WriteLine ("Getting parent_manager for
{0}", info.BindingPath);
BindingManagerBase parent_manager =
this[data_source, info.BindingPath];
- CurrencyManager cm = parent_manager as
CurrencyManager;
PropertyDescriptor pd = parent_manager == null
? null : parent_manager.GetItemProperties ().Find (info.BindingField, true);
- if (pd != null) {
- Console.WriteLine
("parent_manager.GetItemProperties returned property descriptor for {0}",
pd.Name);
- if (cm != null) {
- if (cm.data_source is
DataViewManager)
- return new
RelatedCurrencyManager (cm, );
- else
- return new
RelatedPropertyManager (cm, info.BindingField);
- }
- }
- else {
- /* null property. extra checks here,
for e.g. DataRelations */
- if (cm != null) {
- if (cm.data_source is
DataViewManager) {
- DataSet ds =
((DataViewManager)cm.data_source).DataSet;
- DataRelation rel =
ds.Relations [info.BindingField];
+ if (pd == null)
+ throw new ArgumentException
(String.Format ("Cannot create a child list for field {0}.",
info.BindingField));
- if (rel != null) {
-
Console.WriteLine ("+ creating related currency manager for relation {0}",
info.BindingField);
- return new
RelatedCurrencyManager (cm, rel);
- }
- }
- }
- }
-
- throw new ArgumentException (String.Format
("Cannot create a child list for field {0}", info.BindingField));
+ if (IsListType (pd.PropertyType))
+ return new RelatedCurrencyManager
(parent_manager, pd);
+ else
+ return new RelatedPropertyManager
(parent_manager, info.BindingField);
}
-#endif
}
+ bool IsListType (Type t)
+ {
+ return (typeof (IList).IsAssignableFrom (t)
+ || typeof (IListSource).IsAssignableFrom (t));
+ }
+
#region Public Instance Methods
public bool Contains(object dataSource)
{
@@ -341,21 +217,15 @@
}
int ICollection.Count {
- get {
- return managers.Count;
- }
+ get { return managers.Count; }
}
bool ICollection.IsSynchronized {
- get {
- return false;
- }
+ get { return false; }
}
object ICollection.SyncRoot {
- get {
- return null;
- }
+ get { return null; }
}
#endregion // ICollection Interfaces
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-06-21 10:30:58 UTC (rev 61896)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2006-06-21 10:41:07 UTC (rev 61897)
@@ -1,3 +1,26 @@
+2006-06-21 Chris Toshok <[EMAIL PROTECTED]>
+
+ * CurrencyManager.cs: push some of the original type checking from
+ BindingContext.CreateBindingManager to here, and remove some of
+ the finalType stuff. Need more tests to make sure I've got the
+ ListName part right, and we might need more in SetDataSource.
+
+ * PropertyManager.cs: add a ctor that takes just the datasource,
+ and no property name. Make SetDataSource work with a null
+ property_name, and make Current return the data_source if the
+ property descriptor is null. this makes 'string foo = "hi";
+ BindingContext[foo].Current' return "hi" as it should.
+
+ * RelatedCurrencyManager.cs: make this code more generic - there's
+ no reason the parent manager has to be CurrencyManager, and
+ there's no reason to pass the DataRelation. It suffices to use a
+ BindingManagerBase and PropetyDescriptor.
+
+ * RelatedPropertyManager.cs: make a similar change here.
+
+ * BindingContext.cs: make CreateBindingManager the beautiful, tiny
+ flower I knew it could be.
+
2006-06-20 Chris Toshok <[EMAIL PROTECTED]>
* PropertyManager.cs: the PropertyChangedHandler is invoked when
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
2006-06-21 10:30:58 UTC (rev 61896)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
2006-06-21 10:41:07 UTC (rev 61897)
@@ -33,24 +33,19 @@
[DefaultMember("Item")]
public class CurrencyManager : BindingManagerBase {
- protected Type finalType;
protected int listposition;
private IList list;
private bool binding_suspended;
- internal object data_source;
+ private object data_source;
- internal CurrencyManager (IList data_source)
+ internal CurrencyManager ()
{
- if (data_source as ArrayList != null) {
- finalType = ((ArrayList) data_source).GetType
();
- } else if (data_source as Array != null) {
- finalType = ((Array) data_source).GetType ();
- } else {
- finalType = null;
- }
+ }
+ internal CurrencyManager (object data_source)
+ {
SetDataSource (data_source);
}
@@ -87,18 +82,6 @@
}
}
- internal string ListName {
- get {
- ITypedList typed = list as ITypedList;
-
- if (typed == null) {
- return finalType.Name;
- } else {
- return typed.GetListName (null);
- }
- }
- }
-
internal void SetDataSource (object data_source)
{
if (this.data_source is IBindingList)
@@ -111,6 +94,9 @@
dataview.Table.Constraints.CollectionChanged -=
new CollectionChangeEventHandler (MetaDataChangedHandler);
}
+ if (data_source is IListSource)
+ data_source =
((IListSource)data_source).GetList();
+
this.data_source = data_source;
if (this.data_source is IBindingList)
@@ -123,7 +109,7 @@
dataview.Table.Constraints.CollectionChanged +=
new CollectionChangeEventHandler (MetaDataChangedHandler);
}
- list = data_source as IList;
+ list = (IList)data_source;
if (list.Count > 0)
listposition = 0;
@@ -133,18 +119,16 @@
public override PropertyDescriptorCollection GetItemProperties
()
{
- ITypedList typed = list as ITypedList;
-
if (list is Array) {
Type element = list.GetType ().GetElementType
();
return TypeDescriptor.GetProperties (element);
}
- if (typed != null) {
- return typed.GetItemProperties (null);
+ if (list is ITypedList) {
+ return ((ITypedList)list).GetItemProperties
(null);
}
- PropertyInfo [] props = finalType.GetProperties ();
+ PropertyInfo [] props =
data_source.GetType().GetProperties ();
for (int i = 0; i < props.Length; i++) {
if (props [i].Name == "Item") {
Type t = props [i].PropertyType;
@@ -262,11 +246,18 @@
protected internal override string GetListName (ArrayList
accessors)
{
if (list is ITypedList) {
- PropertyDescriptor [] pds;
- pds = new PropertyDescriptor [accessors.Count];
- accessors.CopyTo (pds, 0);
+ PropertyDescriptor [] pds = null;
+ if (accessors != null) {
+ pds = new PropertyDescriptor
[accessors.Count];
+ accessors.CopyTo (pds, 0);
+ }
return ((ITypedList) list).GetListName (pds);
}
+#if false
+ else if (finalType != null) {
+ return finalType.Name;
+ }
+#endif
return String.Empty;
}
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyManager.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyManager.cs
2006-06-21 10:30:58 UTC (rev 61896)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyManager.cs
2006-06-21 10:41:07 UTC (rev 61897)
@@ -30,14 +30,19 @@
public class PropertyManager : BindingManagerBase {
- private object data_source;
private string property_name;
private PropertyDescriptor prop_desc;
private bool binding_suspended;
+ private object data_source;
public PropertyManager() {
}
+ internal PropertyManager (object data_source)
+ {
+ SetDataSource (data_source);
+ }
+
internal PropertyManager (object data_source, string
property_name)
{
this.property_name = property_name;
@@ -52,16 +57,18 @@
data_source = new_data_source;
- prop_desc = TypeDescriptor.GetProperties
(data_source).Find (property_name, true);
+ if (property_name != null) {
+ prop_desc = TypeDescriptor.GetProperties
(data_source).Find (property_name, true);
- if (prop_desc == null)
- return;
+ if (prop_desc == null)
+ return;
- prop_desc.AddValueChanged (data_source, new
EventHandler (PropertyChangedHandler));
+ prop_desc.AddValueChanged (data_source, new
EventHandler (PropertyChangedHandler));
+ }
}
public override object Current {
- get { return prop_desc == null ? null :
prop_desc.GetValue (data_source); }
+ get { return prop_desc == null ? data_source :
prop_desc.GetValue (data_source); }
}
public override int Position {
@@ -134,6 +141,8 @@
protected internal override void OnCurrentChanged (EventArgs e)
{
+ PushData ();
+
if (onCurrentChangedHandler != null) {
onCurrentChangedHandler (this, e);
}
@@ -141,8 +150,6 @@
private void PropertyChangedHandler (object sender, EventArgs e)
{
- PushData ();
-
OnCurrentChanged (EventArgs.Empty);
}
}
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedCurrencyManager.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedCurrencyManager.cs
2006-06-21 10:30:58 UTC (rev 61896)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedCurrencyManager.cs
2006-06-21 10:41:07 UTC (rev 61897)
@@ -33,21 +33,21 @@
[DefaultMember("Item")]
internal class RelatedCurrencyManager : CurrencyManager {
- CurrencyManager parent;
- DataRelation rel;
+ BindingManagerBase parent;
+ PropertyDescriptor prop_desc;
- public RelatedCurrencyManager (CurrencyManager parent,
DataRelation rel)
- : base
(((DataView)parent.data_source)[parent.Position].CreateChildView (rel))
+ public RelatedCurrencyManager (BindingManagerBase parent,
PropertyDescriptor prop_desc)
+ : base (prop_desc.GetValue (parent.Current))
{
this.parent = parent;
- this.rel = rel;
+ this.prop_desc = prop_desc;
parent.PositionChanged += new EventHandler
(parent_PositionChanged);
}
private void parent_PositionChanged (object sender, EventArgs
args)
{
- SetDataSource
(((DataView)parent.data_source)[parent.Position].CreateChildView (rel));
+ SetDataSource (prop_desc.GetValue (parent.Current));
}
}
}
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedPropertyManager.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedPropertyManager.cs
2006-06-21 10:30:58 UTC (rev 61896)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RelatedPropertyManager.cs
2006-06-21 10:41:07 UTC (rev 61897)
@@ -30,10 +30,10 @@
internal class RelatedPropertyManager : PropertyManager {
- CurrencyManager parent;
+ BindingManagerBase parent;
- public RelatedPropertyManager (CurrencyManager parent, string
property_name)
- : base (parent.GetItem (parent.Position), property_name)
+ public RelatedPropertyManager (BindingManagerBase parent,
string property_name)
+ : base (parent.Current, property_name)
{
this.parent = parent;
parent.PositionChanged += new EventHandler
(parent_PositionChanged);
@@ -41,7 +41,8 @@
void parent_PositionChanged (object sender, EventArgs args)
{
- SetDataSource (parent.GetItem (parent.Position));
+ Console.WriteLine ("parent_PositionChanged");
+ SetDataSource (parent.Current);
OnCurrentChanged (EventArgs.Empty);
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches