New test.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / AutoGeneratedField.cs
1 //
2 // System.Web.UI.WebControls.AutoGeneratedField.cs
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Web.UI;
35 using System.ComponentModel;
36 using System.Security.Permissions;
37
38 namespace System.Web.UI.WebControls {
39
40         [EditorBrowsableAttribute (EditorBrowsableState.Never)]
41         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43         public sealed class AutoGeneratedField : BoundField
44         {
45                 Type dataType = typeof(string);
46                 
47                 internal AutoGeneratedField ()
48                 {
49                 }
50                 
51                 public AutoGeneratedField (string dataField)
52                 {
53                         DataField = dataField;
54                 }
55                 
56                 internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
57                 {
58                         DataField = fieldProperties.DataField;
59                         DataType = fieldProperties.Type;
60                         SortExpression = fieldProperties.Name;
61                         HeaderText = fieldProperties.Name;
62                         ReadOnly = fieldProperties.IsReadOnly;
63                 }
64                 
65                 [MonoTODO]
66                 public Type DataType {
67                         get { return dataType; }
68                         set { dataType = value; }
69                 }
70                 
71                 public override bool ConvertEmptyStringToNull {
72                         get { return true; }
73                         set { throw new NotSupportedException (); }
74                 }
75
76                 public override string DataFormatString {
77                         get { return string.Empty; }
78                         set { throw new NotSupportedException (); }
79                 }
80
81                 public override bool InsertVisible {
82                         get { return true; }
83                         set { throw new NotSupportedException (); }
84                 }
85                 
86                 [MonoTODO ("Support other data types")]
87                 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
88                         DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
89                 {
90                         if (dataType == typeof(bool)) {
91                                 CheckBox box = (CheckBox) cell.Controls [0];
92                                 dictionary [DataField] = box.Checked;
93                         } else
94                                 base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
95                 }
96                 
97                 
98                 [MonoTODO ("Support other data types")]
99                 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
100                 {
101                         bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
102                         
103                         if (dataType == typeof(bool)) {
104                                 CheckBox box = new CheckBox ();
105                                 box.Enabled = editable && !ReadOnly;
106                                 box.ToolTip = HeaderText;
107                                 cell.Controls.Add (box);
108                         } else
109                                 base.InitializeDataCell (cell, rowState);
110                 }
111                 
112                 [MonoTODO ("Support other data types")]
113                 protected override void OnDataBindField (object sender, EventArgs e)
114                 {
115                         DataControlFieldCell cell = (DataControlFieldCell) sender;
116                         if (dataType == typeof(bool)) {
117                                 CheckBox box = (CheckBox) cell.Controls [0];
118                                 object val = GetValue (cell.BindingContainer);
119                                 if (val != null) {
120                                         box.Checked = (bool)val;
121                                         if (!box.Visible)
122                                                 box.Visible = true;
123                                 }
124                                 else
125                                         box.Visible = false;
126                         } else
127                                 base.OnDataBindField (sender, e);
128                 }
129                 
130                 public override void ValidateSupportsCallback ()
131                 {
132                 }
133                 
134                 protected override DataControlField CreateField ()
135                 {
136                         return new AutoGeneratedField ();
137                 }
138
139                 protected override void CopyProperties (DataControlField newField)
140                 {
141                         base.CopyProperties (newField);
142                         AutoGeneratedField field = (AutoGeneratedField) newField;
143                         field.DataType = DataType;
144                 }
145
146                 [MonoTODO]
147                 protected override object GetDesignTimeValue()
148                 {
149                         return base.GetDesignTimeValue ();
150                 }
151         }
152 }
153 #endif