PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Web.Extensions/System.Web.UI.WebControls/DataPagerFieldCollection.cs

https://bitbucket.org/danipen/mono
C# | 204 lines | 145 code | 31 blank | 28 comment | 15 complexity | e85cf85fdfa2054d0c06f0d475d36ee2 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // System.Web.UI.WebControls.DataPagerFieldCollection
  3. //
  4. // Authors:
  5. // Marek Habersack (mhabersack@novell.com)
  6. //
  7. // (C) 2007-2008 Novell, Inc
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_3_5
  30. using System;
  31. using System.Collections;
  32. using System.ComponentModel;
  33. using System.Security.Permissions;
  34. using System.Web;
  35. using System.Web.UI;
  36. namespace System.Web.UI.WebControls
  37. {
  38. [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  39. [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  40. public class DataPagerFieldCollection : StateManagedCollection
  41. {
  42. enum KnownTypeIndexes
  43. {
  44. NextPreviousPagerField = 0,
  45. NumericPagerField = 1,
  46. TemplatePagerField = 2
  47. }
  48. static readonly Type[] knownTypes = {
  49. typeof (NextPreviousPagerField),
  50. typeof (NumericPagerField),
  51. typeof (TemplatePagerField)
  52. };
  53. static readonly object FieldsChangedEvent = new object ();
  54. IList list;
  55. DataPager owner;
  56. EventHandlerList events;
  57. public event EventHandler FieldsChanged {
  58. add { AddEventHandler (FieldsChangedEvent, value); }
  59. remove { RemoveEventHandler (FieldsChangedEvent, value); }
  60. }
  61. public DataPagerFieldCollection (DataPager dataPager)
  62. {
  63. list = (IList)this;
  64. owner = dataPager;
  65. }
  66. public void Add (DataPagerField field)
  67. {
  68. list.Add (field);
  69. }
  70. public DataPagerFieldCollection CloneFields (DataPager pager)
  71. {
  72. throw new NotImplementedException ();
  73. }
  74. public bool Contains (DataPagerField field)
  75. {
  76. return list.Contains (field);
  77. }
  78. public void CopyTo (DataPagerField[] array, int index)
  79. {
  80. }
  81. protected override object CreateKnownType (int index)
  82. {
  83. if (!Enum.IsDefined (typeof (KnownTypeIndexes), index))
  84. throw new ArgumentOutOfRangeException ("index");
  85. return Activator.CreateInstance (knownTypes [index]);
  86. }
  87. protected override Type[] GetKnownTypes ()
  88. {
  89. return knownTypes;
  90. }
  91. public int IndexOf (DataPagerField field)
  92. {
  93. return list.IndexOf (field);
  94. }
  95. public void Insert (int index, DataPagerField field)
  96. {
  97. list.Insert (index, field);
  98. }
  99. protected override void OnClearComplete ()
  100. {
  101. base.OnClearComplete ();
  102. InvokeEvent (FieldsChangedEvent, EventArgs.Empty);
  103. }
  104. protected override void OnInsertComplete (int index, object value)
  105. {
  106. base.OnInsertComplete (index, value);
  107. DataPagerField field = value as DataPagerField;
  108. if (field == null)
  109. return;
  110. field.SetDataPager (owner);
  111. field.FieldChanged += new EventHandler (FieldHasChanged);
  112. InvokeEvent (FieldsChangedEvent, EventArgs.Empty);
  113. }
  114. protected override void OnRemoveComplete (int index, object value)
  115. {
  116. base.OnRemoveComplete (index, value);
  117. DataPagerField field = value as DataPagerField;
  118. if (field == null)
  119. return;
  120. field.SetDataPager (null);
  121. field.FieldChanged -= new EventHandler (FieldHasChanged);
  122. InvokeEvent (FieldsChangedEvent, EventArgs.Empty);
  123. }
  124. protected override void OnValidate (object o)
  125. {
  126. base.OnValidate (o);
  127. DataPagerField field = o as DataPagerField;
  128. if (field == null)
  129. throw new ArgumentException ("is not an instance of the DataPagerField class or of one of its derived classes.", "o");
  130. }
  131. public void Remove (DataPagerField field)
  132. {
  133. list.Remove (field);
  134. }
  135. public void RemoveAt (int index)
  136. {
  137. list.RemoveAt (index);
  138. }
  139. protected override void SetDirtyObject (object o)
  140. {
  141. }
  142. [BrowsableAttribute(false)]
  143. public DataPagerField this [int index] {
  144. get { return list [index] as DataPagerField; }
  145. }
  146. void FieldHasChanged (object sender, EventArgs args)
  147. {
  148. InvokeEvent (FieldsChangedEvent, EventArgs.Empty);
  149. }
  150. void AddEventHandler (object key, EventHandler handler)
  151. {
  152. if (events == null)
  153. events = new EventHandlerList ();
  154. events.AddHandler (key, handler);
  155. }
  156. void RemoveEventHandler (object key, EventHandler handler)
  157. {
  158. if (events == null)
  159. return;
  160. events.RemoveHandler (key, handler);
  161. }
  162. void InvokeEvent (object key, EventArgs args)
  163. {
  164. if (events == null)
  165. return;
  166. EventHandler eh = events [key] as EventHandler;
  167. if (eh == null)
  168. return;
  169. eh (this, args);
  170. }
  171. }
  172. }
  173. #endif