BindingManagerBase.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2005 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. // Jackson Harper [email protected]
  25. //
  26. // NOT COMPLETE
  27. using System.ComponentModel;
  28. using System.Collections;
  29. namespace System.Windows.Forms {
  30. public abstract class BindingManagerBase {
  31. private BindingsCollection bindings;
  32. internal bool transfering_data; /* true if we're pushing or pulling data */
  33. #region Public Constructors
  34. public BindingManagerBase()
  35. {
  36. }
  37. #endregion // Public Constructors
  38. #region Protected Instance Fields
  39. protected EventHandler onCurrentChangedHandler;
  40. protected EventHandler onPositionChangedHandler;
  41. #if NET_2_0
  42. internal EventHandler onCurrentItemChangedHandler;
  43. #endif
  44. #endregion // Protected Instance Fields
  45. #region Public Instance Properties
  46. public BindingsCollection Bindings {
  47. get {
  48. if (bindings == null) {
  49. bindings = new BindingsCollection ();
  50. }
  51. return bindings;
  52. }
  53. }
  54. public abstract int Count {
  55. get;
  56. }
  57. public abstract object Current {
  58. get;
  59. }
  60. public abstract int Position {
  61. get; set;
  62. }
  63. #endregion // Public Instance Properties
  64. #region Public Instance Methods
  65. public abstract void AddNew();
  66. public abstract void CancelCurrentEdit();
  67. public abstract void EndCurrentEdit();
  68. #if NET_2_0
  69. public virtual PropertyDescriptorCollection GetItemProperties()
  70. {
  71. throw new NotImplementedException ();
  72. }
  73. #else
  74. public abstract PropertyDescriptorCollection GetItemProperties();
  75. #endif
  76. public abstract void RemoveAt(int index);
  77. public abstract void ResumeBinding();
  78. public abstract void SuspendBinding();
  79. #endregion // Public Instance Methods
  80. internal abstract bool IsSuspended {
  81. get;
  82. }
  83. #region Protected Instance Methods
  84. [MonoTODO]
  85. protected internal virtual PropertyDescriptorCollection GetItemProperties(ArrayList dataSources, ArrayList listAccessors)
  86. {
  87. throw new NotImplementedException();
  88. }
  89. [MonoTODO]
  90. protected virtual PropertyDescriptorCollection GetItemProperties(Type lisType, int offset, ArrayList dataSources, ArrayList listAccessors)
  91. {
  92. throw new NotImplementedException();
  93. }
  94. protected internal abstract string GetListName (ArrayList listAccessors);
  95. protected internal abstract void OnCurrentChanged (EventArgs e);
  96. protected void PullData()
  97. {
  98. try {
  99. if (!transfering_data) {
  100. transfering_data = true;
  101. UpdateIsBinding ();
  102. }
  103. foreach (Binding binding in Bindings) {
  104. binding.PullData ();
  105. }
  106. } finally {
  107. transfering_data = false;
  108. }
  109. }
  110. protected void PushData()
  111. {
  112. try {
  113. if (!transfering_data) {
  114. transfering_data = true;
  115. UpdateIsBinding ();
  116. }
  117. foreach (Binding binding in Bindings) {
  118. binding.PushData ();
  119. }
  120. } finally {
  121. transfering_data = false;
  122. }
  123. }
  124. #if NET_2_0
  125. protected void OnBindingComplete (BindingCompleteEventArgs e)
  126. {
  127. if (BindingComplete != null)
  128. BindingComplete (this, e);
  129. }
  130. protected abstract void OnCurrentItemChanged (EventArgs e);
  131. protected void OnDataError (Exception e)
  132. {
  133. if (DataError != null)
  134. DataError (this, new BindingManagerDataErrorEventArgs (e));
  135. }
  136. #endif
  137. protected abstract void UpdateIsBinding();
  138. #endregion // Protected Instance Methods
  139. internal void AddBinding (Binding binding)
  140. {
  141. if (Bindings.Contains (binding))
  142. return;
  143. Bindings.Add (binding);
  144. }
  145. #region Events
  146. public event EventHandler CurrentChanged {
  147. add { onCurrentChangedHandler += value; }
  148. remove { onCurrentChangedHandler -= value; }
  149. }
  150. public event EventHandler PositionChanged {
  151. add { onPositionChangedHandler += value; }
  152. remove { onPositionChangedHandler -= value; }
  153. }
  154. #if NET_2_0
  155. public event EventHandler CurrentItemChanged {
  156. add { onCurrentItemChangedHandler += value; }
  157. remove { onCurrentItemChangedHandler -= value; }
  158. }
  159. public event BindingCompleteEventHandler BindingComplete;
  160. public event BindingManagerDataErrorEventHandler DataError;
  161. #endif
  162. #endregion // Events
  163. }
  164. }