2005-01-24 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data / DataRowView.cs
1 //
2 // System.Data.DataRowView.cs
3 //
4 // Author:
5 //    Rodrigo Moya <rodrigo@ximian.com>
6 //    Miguel de Icaza <miguel@ximian.com>
7 //    Daniel Morgan <danmorg@sc.rr.com>
8 //
9 // (C) Ximian, Inc 2002
10 // (C) Daniel Morgan 2002
11 //
12
13 //
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 //
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 // 
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 // 
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 //
35
36 using System;
37 using System.Collections;
38 using System.ComponentModel;
39 using System.Reflection;
40
41 namespace System.Data
42 {
43         /// <summary>
44         /// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.
45         /// </summary>
46         public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo
47         {
48                 #region Fields
49
50                 DataView dataView;
51                 DataRow dataRow;
52                 DataRowVersion rowVersion = DataRowVersion.Default;
53
54                 // FIXME: what are the defaults?
55                 bool isEdit = false;
56                 bool isNew = false;
57
58                 #endregion // Fields
59
60                 #region Constructors
61
62                 internal DataRowView (DataView dataView, DataRow row) : this(dataView, row, false){
63                 }
64
65                 internal DataRowView (DataView dataView, DataRow row, bool isNew) {
66                         this.dataView = dataView;
67                         this.dataRow = row;
68                         this.isNew = isNew;
69                 }
70
71                 #endregion // Constructors
72
73                 #region Methods
74
75                 public override bool Equals(object other)
76                 {
77                         return (other != null &&
78                                         other is DataRowView && 
79                                         ((DataRowView)other).dataRow != null && 
80                                         ((DataRowView)other).dataRow.Equals(this.dataRow));
81                 }
82
83                 [MonoTODO]
84                 public void BeginEdit ()
85                 {
86                         // FIXME:
87                         dataRow.BeginEdit();
88                         isEdit = true;
89                 }
90
91                 [MonoTODO]
92                 public void CancelEdit ()
93                 {
94                         // FIXME:
95                         dataRow.CancelEdit();
96                         isEdit = false;
97                 }
98
99                 public DataView CreateChildView (DataRelation relation)
100                 {
101                         if (relation == null)
102                                 throw new ArgumentException ("The relation is not parented to the table.");
103                         return new DataView (relation.ChildTable);
104                 }
105
106                 public DataView CreateChildView (string name)
107                 {
108                         return CreateChildView (
109                                 dataRow.Table.ChildRelations [name]);
110                 }
111
112                 [MonoTODO]
113                 public void Delete ()
114                 {
115                         throw new NotImplementedException ();
116                 }
117
118                 [MonoTODO]
119                 public void EndEdit ()
120                 {
121                         // FIXME:
122                         dataRow.EndEdit();
123                         isEdit = false;
124                 }
125
126                 #endregion // Methods
127
128                 #region Properties
129                 
130                 public DataView DataView
131                 {
132                         [MonoTODO]
133                         get {
134                                 return dataView;
135                         }
136                 }
137
138                 public bool IsEdit {
139                         [MonoTODO]
140                         get {
141                                 return isEdit;
142                         }
143                 }
144
145                 public bool IsNew {
146                         [MonoTODO]
147                         get {
148                                 return isNew;
149                         }
150                 }
151                 
152                 [System.Runtime.CompilerServices.IndexerName("Item")]
153                 public object this[string column] {
154                         [MonoTODO]
155                         get {
156                                 DataColumn dc = dataView.Table.Columns[column];
157                                 return dataRow[dc];
158                         }
159                         [MonoTODO]
160                         set {
161                                 DataColumn dc = dataView.Table.Columns[column];
162                                 dataRow[dc] = value;
163                                 dataView.ChangedList(ListChangedType.ItemChanged,dc.Ordinal,-1);
164                         }
165                 }
166
167                 // the compiler creates a DefaultMemeberAttribute from
168                 // this IndexerNameAttribute
169                 public object this[int column] {
170                         [MonoTODO]
171                         get {
172                                 DataColumn dc = dataView.Table.Columns[column];
173                                 return dataRow[dc];
174                         }
175                         [MonoTODO]
176                         set {
177                                 DataColumn dc = dataView.Table.Columns[column];
178                                 dataRow[dc] = value;
179
180                         }
181                 }
182
183                 public DataRow Row {
184                         [MonoTODO]
185                         get {
186                                 return dataRow;
187                         }
188                 }
189
190                 public DataRowVersion RowVersion {
191                         [MonoTODO]
192                         get {
193                                 return rowVersion;
194                         }
195                 }
196
197                 [MonoTODO]
198                 public override int GetHashCode() {
199                         throw new NotImplementedException ();
200                 }       
201
202                 #endregion // Properties
203                 
204                 #region ICustomTypeDescriptor implementations
205                 
206                 [MonoTODO]
207                 AttributeCollection ICustomTypeDescriptor.GetAttributes  ()
208                 {
209                         System.ComponentModel.AttributeCollection attributes;
210                         attributes = AttributeCollection.Empty;
211                         return attributes;
212                 }
213
214                 [MonoTODO]
215                 string ICustomTypeDescriptor.GetClassName ()
216                 {
217                         return "";
218                 }
219                 
220                 [MonoTODO]
221                 string ICustomTypeDescriptor.GetComponentName ()
222                 {
223                         return null;
224                 }
225
226                 [MonoTODO]
227                 TypeConverter ICustomTypeDescriptor.GetConverter ()
228                 {
229                         return null;
230                 }
231
232                 [MonoTODO]
233                 EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
234                 {
235                         return null;
236                 }
237                 
238                 [MonoTODO]
239                 PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
240                 {
241                         return null;
242                 }
243                 
244                 [MonoTODO]
245                 object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
246                 {
247                         return null;
248                 }
249                 
250                 [MonoTODO]
251                 EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
252                 {
253                         return new EventDescriptorCollection(null);
254                 }
255
256                 [MonoTODO]
257                 EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
258                 {
259                         return new EventDescriptorCollection(null);
260                 }
261
262                 [MonoTODO]
263                 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
264                 {
265                         ITypedList typedList = (ITypedList) dataView;
266                         return typedList.GetItemProperties(new PropertyDescriptor[0]);
267                 }
268
269                 [MonoTODO]
270                 PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)
271                 {
272                         PropertyDescriptorCollection descriptors;
273                         descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
274                         // TODO: filter out descriptors which do not contain
275                         //       any of those attributes
276                         //       except, those descriptors 
277                         //       that contain DefaultMemeberAttribute
278                         return descriptors;
279                 }
280                 
281                 [MonoTODO]
282                 object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
283                 {
284                         return this;
285                 }
286
287                 #endregion // ICustomTypeDescriptor implementations
288
289                 #region IDataErrorInfo implementation
290
291                 string IDataErrorInfo.Error {
292                         [MonoTODO]
293                         get {
294                                 return ""; // FIXME
295                         }
296                 }
297
298                 string IDataErrorInfo.this[string columnName] {
299                         [MonoTODO]
300                         get {
301                                 return ""; // FIXME
302                         }
303                 }
304
305                 #endregion // IDataErrorInfo implementation
306         }
307 }