Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.1 KiB

  1. using System;
  2. using System.Data;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using UDDI.API;
  6. using UDDI.API.Business;
  7. using UDDI.API.ServiceType;
  8. using UDDI;
  9. using UDDI.Diagnostics;
  10. namespace UDDI.Web
  11. {
  12. public class DiscoveryUrlControl : UddiControl
  13. {
  14. protected DiscoveryUrlCollection discoveryUrls;
  15. protected BusinessEntity parentEntity = null;
  16. protected string BusinessKey = "";
  17. protected DataGrid grid;
  18. public override void DataBind()
  19. {
  20. base.DataBind();
  21. grid.DataBind();
  22. }
  23. public void Initialize( DiscoveryUrlCollection discUrls)
  24. {
  25. this.discoveryUrls = ShuffleData( discUrls );
  26. grid.Columns[ 1 ].Visible = false;
  27. }
  28. public void Initialize( DiscoveryUrlCollection discUrls, BusinessEntity parentEntity )
  29. {
  30. //set the parenet entity
  31. this.parentEntity = parentEntity;
  32. //capture the be key
  33. this.BusinessKey = this.parentEntity.BusinessKey;
  34. //reorganize the discoveryUrls to mantian order.
  35. //we need the default to be the first in the collection.
  36. this.discoveryUrls = ShuffleData( discUrls );
  37. grid.Columns[ 1 ].Visible = true;
  38. }
  39. protected void Page_Init( object sender, EventArgs e )
  40. {
  41. grid.Columns[ 0 ].HeaderText = Localization.GetString( "HEADING_DISCOVERYURL" );
  42. grid.Columns[ 1 ].HeaderText = Localization.GetString( "HEADING_ACTIONS" );
  43. }
  44. protected void Page_Load( object sender, EventArgs e )
  45. {
  46. if( !Page.IsPostBack )
  47. PopulateDataGrid();
  48. }
  49. DiscoveryUrlCollection ShuffleData( DiscoveryUrlCollection discurls )
  50. {
  51. foreach( DiscoveryUrl d in discurls )
  52. {
  53. // move the default one to the begining of the list to
  54. // fix bug: 1229
  55. if( d.IsDefault( BusinessKey ) )
  56. {
  57. discurls.Remove( d );
  58. discurls.Insert( 0, d );
  59. break;
  60. }
  61. }
  62. return discurls;
  63. }
  64. void PopulateDataGrid()
  65. {
  66. grid.DataSource = discoveryUrls;
  67. grid.DataBind();
  68. }
  69. protected void DiscoveryUrl_Edit( object sender, DataGridCommandEventArgs e )
  70. {
  71. int index = e.Item.ItemIndex;
  72. grid.EditItemIndex = index;
  73. SetEditMode();
  74. grid.ShowFooter = false;
  75. PopulateDataGrid();
  76. }
  77. protected void OnEnterKeyPressed( object sender, EventArgs e )
  78. {
  79. DiscoveryUrl_Update( sender, null );
  80. }
  81. public string TruncateUrl( string input )
  82. {
  83. if( null!=input && input.Length>80 )
  84. return input.Substring( 0, 77 ) + "...";
  85. else
  86. return input;
  87. }
  88. protected void DiscoveryUrl_Update( object sender, DataGridCommandEventArgs e )
  89. {
  90. Page.Validate();
  91. if( Page.IsValid )
  92. {
  93. int index = grid.EditItemIndex;
  94. if( index == discoveryUrls.Count )
  95. discoveryUrls.Add();
  96. DiscoveryUrl discoveryUrl = discoveryUrls[ index ];
  97. DataGridItem item = grid.Items[ index ];
  98. discoveryUrl.Value = ((TextBox)item.FindControl( "discoveryUrl" )).Text;
  99. discoveryUrl.UseType = ((TextBox)item.FindControl( "useType" )).Text;
  100. parentEntity.Save();
  101. grid.EditItemIndex = -1;
  102. grid.ShowFooter = true;
  103. CancelEditMode();
  104. this.discoveryUrls = ShuffleData( parentEntity.DiscoveryUrls );
  105. PopulateDataGrid();
  106. }
  107. }
  108. protected void DiscoveryUrl_Cancel( object sender, DataGridCommandEventArgs e )
  109. {
  110. grid.EditItemIndex = -1;
  111. grid.ShowFooter = true;
  112. CancelEditMode();
  113. PopulateDataGrid();
  114. }
  115. protected void DiscoveryUrl_Delete( object sender, DataGridCommandEventArgs e )
  116. {
  117. int index = e.Item.ItemIndex;
  118. discoveryUrls.RemoveAt( index );
  119. parentEntity.Save();
  120. grid.EditItemIndex = -1;
  121. this.discoveryUrls = ShuffleData( parentEntity.DiscoveryUrls );
  122. PopulateDataGrid();
  123. }
  124. protected void DiscoveryUrl_Add( object sender, EventArgs e )
  125. {
  126. grid.EditItemIndex = discoveryUrls.Count;
  127. grid.ShowFooter = false;
  128. SetEditMode();
  129. discoveryUrls.Add();
  130. PopulateDataGrid();
  131. }
  132. }
  133. }