Author: toshok
Date: 2005-08-31 19:40:32 -0400 (Wed, 31 Aug 2005)
New Revision: 49234

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs
Log:
2005-08-31  Chris Toshok  <[EMAIL PROTECTED]>

        * Repeater.cs: lots of 2.0 work, much of it c&p'ed from
        {Base}DataList, and also from debug spew garnered from some
        Repeater subclass tests on MS.
        (CreateControlHierarchy): in 2.0 if IsBonudUsingDataSourceID get
        the IEnumerable by calling GetData().
        (DataBind): reset RequiresDataBinding to false (2.0).
        (DataMember): copy the set implementation from DataList, and add
        2.0 code to call OnDataPropertyChanged if we're !Initialiezd.
        (DataSource): more c&p.
        (DataSourceID); implement (2.0)
        (Initialized): implement (2.0)
        (IsBoundUsingDataSource): implement (2.0)
        (RequiresDataBinding): implement (2.0)
        (SelectArguments): implement (2.0)
        (CreateDataSourceSelectArguments): implement (2.0)
        (EnsureDataBound): implement (2.0)
        (GetData): implement.
        (OnDataPropertyChanged): remove the NIE, but leave the MonoTODO
        (2.0)
        (OnDataSourceViewChanged): set RequiresDataBinding to true, but
        leave the MonoTODO. (2.0)
        (OnInit): call base.OnInit instead of throwing NIE, but leave the
        MonoTODO (2.0)
        (OnLoad): implement.
        (OnPreRender): implement.
        (ConnectToDataSource): new method - look for the right control.



Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2005-08-31 23:34:22 UTC (rev 49233)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2005-08-31 23:40:32 UTC (rev 49234)
@@ -1,5 +1,34 @@
 2005-08-31  Chris Toshok  <[EMAIL PROTECTED]>
 
+       * Repeater.cs: lots of 2.0 work, much of it c&p'ed from
+       {Base}DataList, and also from debug spew garnered from some
+       Repeater subclass tests on MS.
+       (CreateControlHierarchy): in 2.0 if IsBonudUsingDataSourceID get
+       the IEnumerable by calling GetData().
+       (DataBind): reset RequiresDataBinding to false (2.0).
+       (DataMember): copy the set implementation from DataList, and add
+       2.0 code to call OnDataPropertyChanged if we're !Initialiezd.
+       (DataSource): more c&p.
+       (DataSourceID); implement (2.0)
+       (Initialized): implement (2.0)
+       (IsBoundUsingDataSource): implement (2.0)
+       (RequiresDataBinding): implement (2.0)
+       (SelectArguments): implement (2.0)
+       (CreateDataSourceSelectArguments): implement (2.0)
+       (EnsureDataBound): implement (2.0)
+       (GetData): implement.
+       (OnDataPropertyChanged): remove the NIE, but leave the MonoTODO
+       (2.0)
+       (OnDataSourceViewChanged): set RequiresDataBinding to true, but
+       leave the MonoTODO. (2.0)
+       (OnInit): call base.OnInit instead of throwing NIE, but leave the
+       MonoTODO (2.0)
+       (OnLoad): implement.
+       (OnPreRender): implement.
+       (ConnectToDataSource): new method - look for the right control.
+
+2005-08-31  Chris Toshok  <[EMAIL PROTECTED]>
+
        * XmlDataSourceView.cs: fix the scope of our select.  Don't use
        call SelectNodes on the XmlDocument, not on
        XmlDocument.DocumentElement.

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs    
2005-08-31 23:34:22 UTC (rev 49233)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/Repeater.cs    
2005-08-31 23:40:32 UTC (rev 49234)
@@ -48,6 +48,15 @@
        [PersistChildren (false)]
        public class Repeater : Control, INamingContainer {
 
+               object dataSource;
+               IDataSource boundDataSource;
+#if NET_2_0
+               private bool initialized;
+               private bool requiresDataBinding;
+               private DataSourceSelectArguments selectArguments;
+               private IEnumerable data;
+#endif
+
                // See Kothari, listing 20-3
 #if NET_2_0
                protected internal
@@ -108,11 +117,19 @@
                        items = new ArrayList ();
                        itemscol = null;
                        
-                       if (useDataSource)
-                               ds = DataSourceResolver.ResolveDataSource 
(DataSource, DataMember);
-                       else
+                       if (useDataSource) {
+#if NET_2_0
+                               if (IsBoundUsingDataSourceID) {
+                                       ds = GetData ();
+                               }
+                               else
+#endif
+                                       ds = 
DataSourceResolver.ResolveDataSource (DataSource, DataMember);
+                       }
+                       else {
                                // Optimize (shouldn't need all this memory ;-)
                                ds = new object [(int) ViewState ["Items"]];
+                       }
 
                        // If there is no datasource, then we don't show 
anything. the "Items"
                        // viewstate won't get set, so on postback, we won't 
get here
@@ -145,6 +162,9 @@
                        // windows, this doesn't seem to be the case here.
                        OnDataBinding (EventArgs.Empty);
 
+#if NET_2_0
+                       RequiresDataBinding = false;
+#endif
                }
                
                protected virtual RepeaterItem CreateItem (int itemIndex, 
ListItemType itemType)
@@ -219,38 +239,63 @@
                                return ViewState.GetString ("DataMember", "");
                        }
                        set {
-                               ViewState ["DataMember"] = value;
+                               if (value == null)
+                                       ViewState.Remove ("DataMember");
+                               else
+                                       ViewState ["DataMember"] = value;
+
+#if NET_2_0
+                               if (!Initialized)
+                                       OnDataPropertyChanged ();
+#endif
                        }
                }
 
-               object datasource;
                [Bindable(true)]
                [DefaultValue(null)]
                
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public virtual object DataSource {
                        get {
-                               return datasource;
+                               return dataSource;
                        }
                        
                        set {
                                if (value == null || value is IListSource || 
value is IEnumerable)
-                                       datasource = value;
+#if NET_2_0
+// FIXME - can't duplicate in a test case ? LAMESPEC ?
+// can't duplicate in a test case
+//                                     if ((dataSourceId != null) && 
(dataSourceId.Length != 0))
+//                                             throw new HttpException 
(Locale.GetText ("DataSourceID is already set."));
+
+                                       dataSource = value;
+
+                                       if (!Initialized)
+                                               OnDataPropertyChanged ();
+#else
+                                       dataSource = value;
+#endif
                                else
-                                       throw new ArgumentException ();
+                                       throw new ArgumentException 
(String.Format (
+                                           "An invalid data source is being 
used for {0}. A valid data source must implement either IListSource or 
IEnumerable",
+                                           ID));
                        }
                }
 
 #if NET_2_0
                [DefaultValue ("")]
                [IDReferenceProperty (typeof (DataSourceControl))]
-               [MonoTODO]
                public virtual string DataSourceID
                {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetString ("DataSourceID", "");
                        }
                        set {
-                               throw new NotImplementedException ();
+                               if (dataSource != null)
+                                       throw new HttpException ("Only one of 
DataSource and DataSourceID can be specified.");
+                               ViewState ["DataSourceID"] = value;
+
+                               if (!Initialized)
+                                       OnDataPropertyChanged ();
                        }
                }
 
@@ -379,88 +424,117 @@
                }
 
 #if NET_2_0
-               [MonoTODO]
-               protected bool Initialized
-               {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+               protected bool Initialized {
+                       get { return initialized; }
                }
 
-               [MonoTODO]
                protected bool IsBoundUsingDataSourceID
                {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return (DataSourceID.Length != 0); }
                }
 
-               [MonoTODO]
                protected bool RequiresDataBinding
                {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return requiresDataBinding; }
+                       set { requiresDataBinding = value; }
                }
 
-               [MonoTODO]
                protected DataSourceSelectArguments SelectArguments
                {
                        get {
-                               throw new NotImplementedException ();
+                               /* i know this seems weird - i mean, why
+                                * don't we call
+                                * CreateDataSourceSelectArguments here?  i
+                                * have no idea. ask MS */
+                               if (selectArguments == null)
+                                       selectArguments = new 
DataSourceSelectArguments ();
+                               return selectArguments;
                        }
                }
 
-               [MonoTODO]
                protected virtual DataSourceSelectArguments 
CreateDataSourceSelectArguments ()
                {
-                       throw new NotImplementedException ();
+                       if (selectArguments == null)
+                               selectArguments = new DataSourceSelectArguments 
();
+                       return selectArguments;
                }
 
-               [MonoTODO]
                protected void EnsureDataBound ()
                {
-                       throw new NotImplementedException ();
+                       if (IsBoundUsingDataSourceID && RequiresDataBinding)
+                               DataBind ();
                }
 
-               [MonoTODO]
+               private void SelectCallback (IEnumerable data)
+               {
+                       this.data = data;
+               }
+
                protected virtual IEnumerable GetData ()
                {
-                       throw new NotImplementedException ();
+                       if (DataSourceID.Length == 0)
+                               return null;
+
+                       DataSourceView dsv = boundDataSource.GetView 
(String.Empty);
+                       dsv.Select (SelectArguments, new 
DataSourceViewSelectCallback (SelectCallback));
+                       return data;
                }
 
                [MonoTODO]
                protected virtual void OnDataPropertyChanged ()
                {
-                       throw new NotImplementedException ();
                }
 
                [MonoTODO]
                protected virtual void OnDataSourceViewChanged (object sender, 
EventArgs e)
                {
-                       throw new NotImplementedException ();
+                       RequiresDataBinding = true;
                }
 
                [MonoTODO]
                protected internal override void OnInit (EventArgs e)
                {
-                       throw new NotImplementedException ();
+                       base.OnInit (e);
                }
 
-               [MonoTODO]
                protected internal override void OnLoad (EventArgs e)
                {
-                       throw new NotImplementedException ();
+                       if ((Page != null) && !Page.IsPostBack)
+                               RequiresDataBinding = true;
+
+                       initialized = true;
+                       base.OnLoad (e);
+
+                       if (IsBoundUsingDataSourceID)
+                               ConnectToDataSource ();
                }
 
-               [MonoTODO]
                protected internal override void OnPreRender (EventArgs e)
                {
-                       throw new NotImplementedException ();
+                       EnsureDataBound ();
+                       base.OnPreRender (e);
                }
+
+               void ConnectToDataSource ()
+               {
+                       /* verify that the data source exists and is an 
IDataSource */
+                       object ctrl = null;
+                       if (Page != null)
+                               ctrl = Page.FindControl (DataSourceID);
+
+                       if (ctrl == null || !(ctrl is IDataSource)) {
+                               string format;
+
+                               if (ctrl == null)
+                                       format = "DataSourceID of '{0}' must be 
the ID of a control of type IDataSource.  A control with ID '{1}' could not be 
found.";
+                               else
+                                       format = "DataSourceID of '{0}' must be 
the ID of a control of type IDataSource.  '{1}' is not an IDataSource.";
+
+                               throw new HttpException (String.Format (format, 
ID, DataSourceID));
+                       }
+
+                       boundDataSource = (IDataSource)ctrl;
+               }
 #endif
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to