Clover.NET coverage report - Coverage

Coverage timestamp: viernes, 12 de agosto de 2005 12:53:38 PM

File Stats: LOC: 328   Methods: 9
NCLOC: 169 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Web\WebBuilders\DataGridBuilder.cs 53,1 % 63,3 % 66,7 % 61,2 %
coverage coverage
1   #region Copyright
2   /*
3   ShowX. Maps business objects into presentation layer.
4   Copyright (C) 2005 Jesus Diaz.
5  
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10  
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with this library; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  
20   For project details see: http://showx.sourceforge.net
21   */
22   #endregion
23  
24   using System;
25   using System.Reflection;
26   using System.Collections;
27   using System.Web.UI;
28   using System.Web.UI.WebControls;
29   using ShowX.Web.WebBuilders;
30   using ShowX.Model;
31   using ShowX.Config;
32   using ShowX.Web.WebControls;
33   using ShowX.Web.WebBuilders.ItemTemplates;
34  
35   namespace ShowX.Web.WebBuilders
36   {
37   /// <summary>
38   /// This class generate DataGrid columns, acordingly to a certain ShowX type
39   /// </summary>
40   public class DataGridBuilder {
41  
42   /// <summary>
43   /// ShowX type
44   /// </summary>
45   Type type;
46  
47   /// <summary>
48   /// DataGrid associated to this builder
49   /// </summary>
50   ShowX.Web.WebControls.DataGrid owner;
51  
52   /// <summary>
53   /// DataGridBuilder contructor
54   /// </summary>
55   /// <param name="type">ShowX type</param>
56   /// <param name="owner">DataGrid associated to this builder</param>
57 35 public DataGridBuilder(Type type, ShowX.Web.WebControls.DataGrid owner)
58   {
59 35 this.type = type;
60 35 this.owner = owner;
61   }
62  
63   /// <summary>
64   /// Reflexs the type attribute, as a read-only value
65   /// </summary>
66 0 public Type Type { get { return this.type; }}
67  
68   /// <summary>
69   /// Reflexs the owner attribute, as a read-only value
70   /// </summary>
71 0 public System.Web.UI.WebControls.DataGrid DataGrid { get { return this.owner; }}
72  
73   /// <summary>
74   /// Builds columns over the associated DataGrid
75   /// </summary>
76 35 public void BuildColumns()
77   {
78   //Special treatment for primary keys
79 35 PropertyInfo pInfo = Configuration.Session.MappingHandler.GetPK(type);
80  
81 35 owner.Columns.Add(GenIDColumn(pInfo));
82  
83   //Generate column for primary key field, or defined sustitute attribute
84 35 DataGridColumn col = GenViewColumnForPK(pInfo);
85  
86 35 if (col != null) {
87  
88 0 col.SortExpression = pInfo.Name;
89 0 owner.Columns.Add(col);
90   }
91  
92 35 IViewCollection viewCollection = Configuration.Session
93   .MappingHandler.GetViews(type);
94  
95 35 IView activeView = ((viewCollection != null) &&
96   (viewCollection.Views.Count > 0))
97   ? viewCollection.Views[owner.ActiveView] as IView
98   : null;
99  
100 35 foreach (PropertyInfo pi in Configuration.Session.MappingHandler
101   .GetAllShowXProperties(type)) {
102  
103 245 IPropertyMap propertyMap = Configuration.Session
104   .MappingHandler.GetPropertyMap(pi);
105  
106 245 if (activeView != null && !activeView.Properties
107   .Contains(propertyMap.Name)) continue;
108  
109 245 if (propertyMap is IForeignIdentifierMap)
110 0 owner.Columns.Add(GenViewColumnForFK(pi));
111 245 else if (propertyMap is ICollectionMap)
112 35 owner.Columns.Add(GenViewColumnForCol(pi));
113   else
114 210 owner.Columns.Add(GenViewColumnForField(pi));
115  
116 245 if (col != null) {
117  
118 0 col.SortExpression = pi.Name;
119 0 owner.Columns.Add(col);
120   }
121   }
122  
123 0 if ((owner.DataGridOps & DataGridOps.None) != 0) return;
124  
125 35 if ((owner.DataGridOps & DataGridOps.All) != 0 ||
126   ((owner.DataGridOps & DataGridOps.InplaceEditing)
127   != 0)) {
128  
129 35 EditCommandColumn ecc = new EditCommandColumn();
130 35 ecc.EditText = "Edit";
131 35 ecc.UpdateText = "Update";
132 35 ecc.CancelText = "Cancel";
133 35 owner.Columns.Add(ecc);
134   }
135  
136 35 if ((owner.DataGridOps & (DataGridOps.All|DataGridOps.Deletion))
137   != 0) {
138  
139 35 ButtonColumn bc = new ButtonColumn();
140 35 bc.CommandName = "Delete";
141 35 bc.Text = "Delete";
142 35 owner.Columns.Add(bc);
143   }
144   }
145  
146   /// <summary>
147   /// Generate a column for a given PK property.
148   /// </summary>
149   /// <param name="pInfo">PropertyInfo instance that represents the
150   /// PK property</param>
151   /// <returns>A DataGridColumn instance, representing this PK property</returns>
152 35 protected DataGridColumn GenViewColumnForPK(PropertyInfo pInfo)
153   {
154 35 IIdentifierMap dbpk = Configuration.Session.MappingHandler
155   .GetPropertyMap(pInfo) as IIdentifierMap;
156  
157 35 if (!dbpk.Show) return null;
158  
159 0 BoundColumn bc = new BoundColumn();
160 0 bc.ReadOnly = true;
161  
162 0 if (dbpk.SubstituteAttr != "") {
163  
164   PropertyInfo sustAttrMethod = Configuration.Session
165   .MappingHandler.GetShowXPropertyByName(type,dbpk.SubstituteAttr);
166  
167   IPropertyMap dbAttr = Configuration.Session.MappingHandler
168   .GetPropertyMap(sustAttrMethod);
169  
170   bc.DataField = sustAttrMethod.Name;
171   bc.HeaderText = dbAttr.Heading;
172   }
173   else {
174  
175   bc.DataField = pInfo.Name;
176   bc.HeaderText = dbpk.Heading;
177   }
178  
179 0 return bc;
180   }
181  
182   /// <summary>
183   /// Generate a column for a given FK property.
184   /// </summary>
185   /// <param name="pInfo">PropertyInfo instance that represents the
186   /// FK property</param>
187   /// <returns>A DataGridColumn instance, representing this FK property</returns>
188 0 protected TemplateColumn GenViewColumnForFK(PropertyInfo pInfo)
189   {
190   IForeignIdentifierMap dbfk = Configuration.Session.MappingHandler
191   .GetPropertyMap(pInfo) as IForeignIdentifierMap;
192  
193   PropertyInfo pi = Configuration.Session.MappingHandler
194   .GetPK(pInfo.PropertyType);
195  
196   IIdentifierMap dbpk = Configuration.Session.MappingHandler
197   .GetPropertyMap(pi) as IIdentifierMap;
198  
199   TemplateColumn tc = new TemplateColumn();
200   tc.HeaderText = dbfk.Heading;
201   tc.ItemTemplate = new TextTemplate(pInfo.Name + "."
202   + dbpk.SubstituteAttr);
203   tc.EditItemTemplate = new FKEditTemplate(pInfo);
204  
205   return tc;
206   }
207  
208   /// <summary>
209   /// Generate a column for a given DBAttr property.
210   /// </summary>
211   /// <param name="pInfo">PropertyInfo instance that represents the
212   /// DBAttr property</param>
213   /// <returns>A DataGridColumn instance, representing this DBAttr property
214   /// </returns>
215 210 protected DataGridColumn GenViewColumnForField(PropertyInfo pInfo)
216   {
217 210 IPropertyMap dbattr = Configuration.Session.MappingHandler
218   .GetPropertyMap(pInfo);
219  
220 0 if (!dbattr.Show) return null;
221  
222 210 DataGridColumn result = null;
223  
224 210 if (dbattr is IXPercentMap) {
225   //pInfo.GetCustomAttributes(typeof(XPercent),true).Length != 0) {
226  
227 0 IXPercentMap xp = dbattr as IXPercentMap;
228  
229 0 if (xp.ShowLikePercent) {
230  
231   TemplateColumn tc = new TemplateColumn();
232   tc.ItemTemplate = new PercentItemTemplate(pInfo);
233   tc.EditItemTemplate = new PercentItemTemplate(pInfo);
234  
235   tc.HeaderText = dbattr.Heading;
236  
237   return tc;
238   }
239   // pInfo.GetCustomAttributes(
240   // typeof(XPercent),true)[0] as XPercent;
241   //
242   // if (xp.ShowLikePercent) {
243   //
244   // TemplateColumn tc = new TemplateColumn();
245   // tc.ItemTemplate = new PercentItemTemplate(pInfo);
246   // tc.EditItemTemplate = new PercentItemTemplate(pInfo);
247   //
248   // tc.HeaderText = dbattr.Name;
249   //
250   // return tc;
251   // }
252   }
253  
254 210 if (dbattr.IsPassword) {
255  
256 35 TemplateColumn tc = new TemplateColumn();
257 35 tc.ItemTemplate = new ItemTemplate(pInfo);
258 35 tc.EditItemTemplate = new EditItemTemplate(pInfo);
259 35 tc.HeaderText = dbattr.Heading;
260  
261 35 return tc;
262   }
263 175 if (!pInfo.PropertyType.IsByRef) {
264  
265 175 TemplateColumn tc = new TemplateColumn();
266 175 tc.ItemTemplate = new ItemTemplate(pInfo);
267  
268 175 if (dbattr.ReadOnly)
269 35 tc.EditItemTemplate = new ItemTemplate(pInfo);
270   else
271 140 tc.EditItemTemplate = new EditItemTemplate(pInfo);
272  
273 175 tc.HeaderText = dbattr.Heading;
274 175 result = tc;
275   }
276   else {
277  
278 0 result = GenViewColumnForPK(pInfo);
279   }
280  
281 175 result.SortExpression = dbattr.Name;
282 175 result.HeaderText = dbattr.Heading;
283  
284 175 return result;
285   }
286  
287   /// <summary>
288   /// Generate a column for a given collection property.
289   /// </summary>
290   /// <param name="pInfo">PropertyInfo instance that represents the
291   /// collection property.</param>
292   /// <returns>A DataGridColumn instance, representing this collection property.
293   /// </returns>
294 35 protected DataGridColumn GenViewColumnForCol(PropertyInfo pInfo)
295   {
296 35 ICollectionMap collmap = Configuration.Session.MappingHandler
297   .GetPropertyMap(pInfo) as ICollectionMap;
298  
299 35 TemplateColumn tc = new TemplateColumn();
300 35 tc.HeaderText = collmap.Heading;
301 35 tc.ItemTemplate = new CollectionItemTemplate(pInfo);
302 35 tc.EditItemTemplate = new CollectionEditItemTemplate(pInfo);
303  
304 35 return tc;
305   }
306  
307   /// <summary>
308   /// Generate a column for a given PK property.
309   /// </summary>
310   /// <remarks>
311   /// Nevertheless primary key are not shown directly on DataGrid (substitute
312   /// values are shown instead), a hidden field is inserted, in order to identify
313   /// the entry. This method generate the hidden column to store PK identifiers.
314   /// </remarks>
315   /// <param name="pInfo">PropertyInfo instance that represents the
316   /// PK property</param>
317   /// <returns>A DataGridColumn instance, representing this PK property</returns>
318 35 protected TemplateColumn GenIDColumn(PropertyInfo pInfo)
319   {
320 35 TemplateColumn tc = new TemplateColumn();
321 35 tc.ItemTemplate = new ItemTemplate(pInfo);
322 35 tc.Visible = false;
323  
324 35 return tc;
325   }
326   }
327   }
328