disable broken tests on net_4_0
[mcs.git] / class / System.Web.DynamicData / System.Web.DynamicData / DynamicField.cs
blobf88b02af5b7e49dff992bc18fad5da004d2e8b09
1 //
2 // DynamicField.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Marek Habersack <mhabersack@novell.com>
7 //
8 // Copyright (C) 2008-2009 Novell Inc. http://novell.com
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Collections;
33 using System.Collections.Generic;
34 using System.Collections.Specialized;
35 using System.Globalization;
36 using System.Security.Permissions;
37 using System.Security.Principal;
38 using System.Web.Caching;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
42 namespace System.Web.DynamicData
44 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
45 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 public class DynamicField : DataControlField, IAttributeAccessor, IFieldFormattingOptions
48 MetaColumn myColumn;
49 Dictionary <string, string> attributes;
51 public DynamicField ()
53 DataFormatString = String.Empty;
54 HtmlEncode = true;
55 NullDisplayText = String.Empty;
58 public bool ApplyFormatInEditMode {
59 get; set;
62 public bool ConvertEmptyStringToNull {
63 get; set;
66 public virtual string DataField {
67 get { return ViewState.GetString ("_DataField", String.Empty); }
68 set {
69 ViewState ["_DataField"] = value;
70 OnFieldChanged ();
74 public string DataFormatString {
75 get; set;
78 public override string HeaderText {
79 get {
80 string s = ViewState.GetString ("headerText", null);
81 if (s != null)
82 return s;
84 MetaColumn column = MyColumn;
85 if (column != null)
86 return column.DisplayName;
88 return DataField;
91 set { base.HeaderText = value; }
94 public bool HtmlEncode {
95 get; set;
98 MetaColumn MyColumn {
99 get {
100 if (myColumn != null)
101 return myColumn;
102 Control owner = Control;
103 if (owner == null)
104 return null;
106 MetaTable table = owner.FindMetaTable ();
107 if (table == null)
108 return null;
110 myColumn = table.GetColumn (DataField);
111 return myColumn;
115 public string NullDisplayText {
116 get; set;
119 public override string SortExpression {
120 get {
121 string s = ViewState.GetString ("sortExpression", null);
122 if (s != null)
123 return s;
125 MetaColumn column = MyColumn;
126 if (column != null)
127 return column.SortExpression;
129 return String.Empty;
132 set { base.SortExpression = value; }
135 public virtual string UIHint {
136 get {
137 string s = ViewState.GetString ("uiHint", null);
138 if (s == null)
139 return String.Empty;
140 return s;
143 set {
144 ViewState ["uiHint"] = value;
145 OnFieldChanged ();
149 [MonoTODO]
150 protected override void CopyProperties (DataControlField newField)
152 throw new NotImplementedException ();
155 [MonoTODO]
156 protected override DataControlField CreateField ()
158 throw new NotImplementedException ();
161 [MonoTODO]
162 public override void ExtractValuesFromCell (IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
164 throw new NotImplementedException ();
167 public string GetAttribute (string key)
169 if (attributes == null)
170 return null;
172 string ret;
173 if (attributes.TryGetValue (key, out ret))
174 return ret;
176 return null;
179 public override void InitializeCell (DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
181 if (cellType == DataControlCellType.Header || cellType == DataControlCellType.Footer) {
182 base.InitializeCell (cell, cellType, rowState, rowIndex);
183 return;
186 DynamicControl dc = new DynamicControl ();
187 dc.ApplyFormatInEditMode = ApplyFormatInEditMode;
188 dc.ConvertEmptyStringToNull = ConvertEmptyStringToNull;
189 dc.Column = MyColumn;
190 dc.DataField = DataField;
191 dc.DataFormatString = DataFormatString;
192 dc.HtmlEncode = HtmlEncode;
193 dc.Mode = (rowState & DataControlRowState.Edit) != 0 ? DataBoundControlMode.Edit :
194 (rowState & DataControlRowState.Insert) != 0 ? DataBoundControlMode.Insert : DataBoundControlMode.ReadOnly;
195 dc.NullDisplayText = NullDisplayText;
196 dc.UIHint = UIHint;
197 dc.InternalSetAttributes (attributes);
199 cell.Controls.Add (dc);
202 public void SetAttribute (string key, string value)
204 if (attributes == null)
205 attributes = new Dictionary <string, string> ();
207 if (attributes.ContainsKey (key))
208 attributes [key] = value;
209 else
210 attributes.Add (key, value);