(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Design / System.Web.UI.Design.WebControls / BaseDataListDesigner.cs
blobddb3f321be72881043b5caf2795856a507d883be
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 /**
23 * Namespace: System.Web.UI.Design.WebControls
24 * Class: BaseDataListDesigner
26 * Author: Gaurav Vaish
27 * Maintainer: mastergaurav AT users DOT sf DOT net
29 * (C) Gaurav Vaish (2002)
32 using System;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.ComponentModel.Design;
36 using System.Reflection;
37 using System.Web.UI.Design;
38 using System.Web.UI;
39 using System.Web.UI.WebControls;
40 using System.Data;
42 namespace System.Web.UI.Design.WebControls
44 public abstract class BaseDataListDesigner : TemplatedControlDesigner,
45 IDataSourceProvider
47 private BaseDataList baseDataList;
48 private DataTable desTimeDataTable;
49 private DataTable dummyDataTable;
51 private static readonly string[] validNames = new string[] {
52 "AlternatingItemStyle",
53 "BackColor",
54 "DataSource",
55 "DataMember",
56 "EditItemStyle",
57 "Font",
58 "ForeColor",
59 "HeaderStyle",
60 "FooterStyle",
61 "ItemStyle",
62 "SelectedItemStyle",
63 "SeparatorStyle"
66 public BaseDataListDesigner()
70 public string DataKeyField
72 get
74 return baseDataList.DataKeyField;
76 set
78 baseDataList.DataKeyField = value;
82 public string DataMember
84 get
86 return baseDataList.DataMember;
88 set
90 baseDataList.DataMember = value;
94 public string DataSource
96 get
98 DataBinding element = DataBindings["DataSource"];
99 if(element != null)
101 return element.Expression;
103 return String.Empty;
107 if(value == null && value.Length == 0)
109 DataBindings.Remove("DataSource");
110 } else
112 DataBinding element = DataBindings["DataSource"];
113 if(element == null)
115 element = new DataBinding("DataSource",
116 typeof(IEnumerable),
117 value);
118 } else
120 element.Expression = value;
122 DataBindings.Add(element);
124 OnDataSourceChanged();
125 OnBindingsCollectionChanged("DataSource");
129 protected internal virtual void OnDataSourceChanged()
131 desTimeDataTable = null;
134 public override bool DesignTimeHtmlRequiresLoadComplete
138 return (DataSource.Length > 0);
142 public override DesignerVerbCollection Verbs
146 throw new NotImplementedException();
150 public object GetSelectedDataSource()
152 object retVal = null;
153 DataBinding element = DataBindings["DataSource"];
154 if(element != null)
156 retVal = DesignTimeData.GetSelectedDataSource(baseDataList,
157 element.Expression);
159 return retVal;
162 public IEnumerable GetResolvedSelectedDataSource()
164 IEnumerable retVal = null;
165 DataBinding element = DataBindings["DataSource"];
166 if(element != null)
168 retVal = DesignTimeData.GetSelectedDataSource(baseDataList,
169 element.Expression,
170 DataMember);
172 return retVal;
175 public override IEnumerable GetTemplateContainerDataSource(
176 string templateName)
178 return GetResolvedSelectedDataSource();
181 public override void Initialize(IComponent component)
183 baseDataList = (BaseDataList)component;
184 base.Initialize(component);
187 public override void OnComponentChanged(object sender,
188 ComponentChangedEventArgs e)
190 if(e.Member != null)
192 string name = e.Member.Name;
193 foreach(string current in validNames)
195 if(name == current)
197 OnStylesChanged();
198 break;
202 base.OnComponentChanged(sender, e);
205 protected internal void OnStylesChanged()
207 OnTemplateEditingVerbsChanged();
210 protected abstract void OnTemplateEditingVerbsChanged();
212 protected override void Dispose(bool disposing)
214 if(disposing)
215 baseDataList = null;
216 base.Dispose(disposing);
219 protected IEnumerable GetDesignTimeDataSource(int minimumRows,
220 out bool dummyDataSource)
222 return GetDesignTimeDataSource(GetResolvedSelectedDataSource(),
223 minimumRows,
224 out dummyDataSource);
227 protected IEnumerable GetDesignTimeDataSource(IEnumerable selectedDataSource,
228 int minimumRows,
229 out bool dummyDataSource)
231 DataTable toDeploy = desTimeDataTable;
232 dummyDataSource = false;
233 if(minimumRows == 0)
235 if(selectedDataSource != null)
237 desTimeDataTable = DesignTimeData.CreateSampleDataTable(
238 selectedDataSource);
239 toDeploy = desTimeDataTable;
241 if(toDeploy == null)
243 if(dummyDataTable == null)
244 dummyDataTable = DesignTimeData.CreateDummyDataTable();
245 toDeploy = dummyDataTable;
246 dummyDataSource = true;
249 return DesignTimeData.GetDesignTimeDataSource(toDeploy, minimumRows);