RuntimeControlsAdapter.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:3k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : RuntimeControlsAdapter.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.Web.UI;
  11. using System.Diagnostics;
  12. using Itenso.WebUserForms.Controls;
  13. namespace Itenso.WebUserForms.Runtime
  14. {
  15. // ------------------------------------------------------------------------
  16. public abstract class RuntimeControlsAdapter : UserFormVisitor
  17. {
  18. // ----------------------------------------------------------------------
  19. protected RuntimeControlsAdapter( Control startControl )
  20. : base( startControl )
  21. {
  22. } // RuntimeControlsAdapter
  23. // ----------------------------------------------------------------------
  24. public void Apply()
  25. {
  26. base.Start();
  27. } // Apply
  28. // ----------------------------------------------------------------------
  29. protected abstract Control GetRuntimeControl( Control placeholderControl );
  30. // ----------------------------------------------------------------------
  31. protected override void VisitFormField( Control control, IUserFormField formField, IUserFormHeader formHeader )
  32. {
  33. IPlaceholderControl placeholder = control as IPlaceholderControl;
  34. if ( placeholder == null )
  35. {
  36. return;
  37. }
  38. Control placeholderControl = placeholder.Control;
  39. if ( placeholderControl == null )
  40. {
  41. throw new InvalidOperationException( "placeholder control without control " + control.ToString() );
  42. }
  43. Control parentControl = placeholderControl.Parent;
  44. if ( parentControl == null )
  45. {
  46. return; // parent required
  47. }
  48. int parentIndex = parentControl.Controls.IndexOf( placeholderControl );
  49. if ( parentIndex < 0 )
  50. {
  51. return; // invalid position in parents collection
  52. }
  53. Control runtimeControl = GetRuntimeControl( placeholderControl );
  54. if ( runtimeControl == null )
  55. {
  56. throw new InvalidOperationException( "missing replacement control for " + placeholderControl.ToString() );
  57. }
  58. if ( runtimeControl is IPlaceholderControl )
  59. {
  60. throw new InvalidOperationException( "replacement control can't be a placeholder " + runtimeControl.ToString() );
  61. }
  62. parentControl.Controls.AddAt( parentIndex, runtimeControl );
  63. parentControl.Controls.Remove( placeholderControl );
  64. } // VisitFormField
  65. } // class RuntimeControlsAdapter
  66. } // namespace Itenso.WebUserForms.Runtime
  67. // -- EOF -------------------------------------------------------------------