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.

504 lines
16 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using UDDI;
  10. using UDDI.Diagnostics;
  11. namespace UDDI.Web
  12. {
  13. //
  14. // TODO: Move most of this code into a base class (HyarchicalBreadCrumbsControl) and inherit from that
  15. //
  16. public delegate void TaxonomyTreeControlEventHandler( object sender, TaxonomyTreeControlEventArgs e );
  17. public class TaxonomyTreeControl : TaxonomyTreeItemControl
  18. {
  19. public TaxonomyTreeControl() : base()
  20. {
  21. //
  22. // wire up local event handlers
  23. //
  24. this.Init += new EventHandler( TaxonomyTreeControl_Init );
  25. this.Load += new EventHandler( TaxonomyTreeControl_Load );
  26. }
  27. private static string root = ( ( "/" == HttpContext.Current.Request.ApplicationPath )?"": HttpContext.Current.Request.ApplicationPath );
  28. public static string SpacerImage
  29. {
  30. get{ return root+"/images/blank.gif"; }
  31. }
  32. public static string ItemImage
  33. {
  34. get{ return root+"/images/bluebox.gif"; }
  35. }
  36. public static string SelectedItemImage
  37. {
  38. get{ return root+"/images/bluearrow.gif"; }
  39. }
  40. private int selectedIndex = 0;
  41. /// *******************************************************************************************************
  42. /// <summary>
  43. /// Gets the Selected Index of the Tree
  44. /// </summary>
  45. /// *******************************************************************************************************
  46. public int SelectedIndex
  47. {
  48. get{ return selectedIndex; }
  49. }
  50. private string cssClass;
  51. /// *******************************************************************************************************
  52. /// <summary>
  53. /// Gets or Sets the Style Sheet class to use.
  54. /// </summary>
  55. /// *******************************************************************************************************
  56. public string CssClass
  57. {
  58. get{ return this.cssClass; }
  59. set{ this.cssClass = value; }
  60. }
  61. /// *******************************************************************************************************
  62. /// <summary>
  63. /// Selects and Item in the Tree by the index of the item
  64. /// </summary>
  65. /// <param name="index">Index in the tree you want to be selected. Rendering will stop at this node</param>
  66. /// *******************************************************************************************************
  67. public void SelectItem( int index )
  68. {
  69. TaxonomyTreeItemControl item = this;
  70. while( item.Index!=index )
  71. {
  72. item.isSelected = false;
  73. item = item.Child;
  74. }
  75. item.isSelected = true;
  76. this.selectedIndex = item.Index;
  77. }
  78. /// <summary>
  79. ///
  80. /// </summary>
  81. /// <param name="output"></param>
  82. protected override void Render( HtmlTextWriter output )
  83. {
  84. //wrap all items in a parent div.
  85. output.Write( "<div class='"+this.CssClass+"'>\r\n" );
  86. base.Render( output );
  87. output.Write( "</div>\r\n" );
  88. }
  89. /// *******************************************************************************************************
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <param name="sender">object that triggered the event</param>
  94. /// <param name="e">EventArguments for this Event.</param>
  95. /// *******************************************************************************************************
  96. private void TaxonomyTreeControl_Init( object sender, EventArgs e )
  97. {
  98. }
  99. /// *******************************************************************************************************
  100. /// <summary>
  101. ///
  102. /// </summary>
  103. /// <param name="sender">object that triggered the event</param>
  104. /// <param name="e">EventArguments for this Event.</param>
  105. /// *******************************************************************************************************
  106. private void TaxonomyTreeControl_Load( object sender, EventArgs e )
  107. {
  108. }
  109. }
  110. /// ***********************************************************************************************************
  111. /// <summary>
  112. /// TaxonomyTreeItemControl
  113. /// Holds information about a selected Taxonomy Item.
  114. /// </summary>
  115. /// ***********************************************************************************************************
  116. public class TaxonomyTreeItemControl : UddiControl, IPostBackEventHandler
  117. {
  118. public event TaxonomyTreeControlEventHandler ChildClick;
  119. public event TaxonomyTreeControlEventHandler Click;
  120. public TaxonomyTreeItemControl()
  121. {
  122. this.ChildClick += new TaxonomyTreeControlEventHandler( TaxonomyTreeItemControl_ChildClick );
  123. }
  124. protected internal bool isSelected;
  125. /// *******************************************************************************************************
  126. /// <summary>
  127. /// Get if the node is the selected node.
  128. /// </summary>
  129. /// *******************************************************************************************************
  130. public bool IsSelected
  131. {
  132. get{ return isSelected; }
  133. }
  134. private bool bubbleEvents = false;
  135. /// <summary>
  136. /// Gets or Sets if the TreeItem should bubble its ClickClick Events up.
  137. /// </summary>
  138. public bool BubbleEvents
  139. {
  140. get
  141. {
  142. if( null!=this.ParentTree )
  143. return this.ParentTree.BubbleEvents;
  144. return bubbleEvents;
  145. }
  146. set{ bubbleEvents=value; }
  147. }
  148. private int indentBase=0;
  149. /// <summary>
  150. /// Gets or Sets the base number of pixels to indent each node in the tree.
  151. /// This number will be multiplied by the index to find the total indent space.
  152. /// </summary>
  153. public int IndentBase
  154. {
  155. get
  156. {
  157. if( 0==indentBase )
  158. {
  159. if( null!=this.ParentTreeItem )
  160. indentBase = this.ParentTreeItem.IndentBase;
  161. }
  162. return indentBase;
  163. }
  164. set{ indentBase=value; }
  165. }
  166. /// <summary>
  167. /// Gets the Total Indent space used for this Tree Item
  168. /// </summary>
  169. public int TotalIndentSpace
  170. {
  171. get{ return ( IndentBase * Index ); }
  172. }
  173. /// <summary>
  174. /// Gets the Total count of Children in the hyarchy of the tree including it self
  175. /// </summary>
  176. public int Count
  177. {
  178. get
  179. {
  180. int i = 1;
  181. TaxonomyTreeItemControl item = this;
  182. while( null!=item.Child )
  183. {
  184. item = item.Child;
  185. i++;
  186. }
  187. return i;
  188. }
  189. }
  190. protected string keyValue;
  191. /// *******************************************************************************************************
  192. /// <summary>
  193. /// Gets or Sets the KeyValue associated with the item
  194. /// </summary>
  195. /// *******************************************************************************************************
  196. public string KeyValue
  197. {
  198. get{ return keyValue; }
  199. set{ keyValue = value; }
  200. }
  201. protected int taxonomyID;
  202. /// *******************************************************************************************************
  203. /// <summary>
  204. /// Gets or Sets the TaxonomyID associated with this item
  205. /// </summary>
  206. /// *******************************************************************************************************
  207. public int TaxonomyID
  208. {
  209. get{ return taxonomyID; }
  210. set{ taxonomyID = value; }
  211. }
  212. protected string keyName;
  213. /// *******************************************************************************************************
  214. /// <summary>
  215. /// Gets or Sets the KeyName associated with this item
  216. /// </summary>
  217. /// *******************************************************************************************************
  218. public string KeyName
  219. {
  220. get{ return keyName; }
  221. set{ keyName = value; }
  222. }
  223. protected TaxonomyTreeItemControl child;
  224. /// *******************************************************************************************************
  225. /// <summary>
  226. /// Gets the Active child of the current Taxonomy Item
  227. /// </summary>
  228. /// *******************************************************************************************************
  229. public TaxonomyTreeItemControl Child
  230. {
  231. get{ return child; }
  232. }
  233. /// *******************************************************************************************************
  234. /// <summary>
  235. /// Gets the Active parent of the current Taxonomy Item
  236. /// </summary>
  237. /// *******************************************************************************************************
  238. public TaxonomyTreeItemControl ParentTreeItem
  239. {
  240. get
  241. {
  242. if( null!=this.Parent && this.Parent is TaxonomyTreeItemControl )
  243. {
  244. return (TaxonomyTreeItemControl)this.Parent;
  245. }
  246. else
  247. {
  248. return null;
  249. }
  250. }
  251. }
  252. /// *******************************************************************************************************
  253. /// <summary>
  254. /// Gets the Tree that this item belong to
  255. /// </summary>
  256. /// *******************************************************************************************************
  257. public TaxonomyTreeControl ParentTree
  258. {
  259. get
  260. {
  261. TaxonomyTreeItemControl item = this.ParentTreeItem;
  262. while( null!=item && !(item is TaxonomyTreeControl ) )
  263. {
  264. item = item.ParentTreeItem;
  265. }
  266. return (TaxonomyTreeControl)item;
  267. }
  268. }
  269. /// *******************************************************************************************************
  270. /// <summary>
  271. /// Gets the index of this Item in the Tree
  272. /// </summary>
  273. /// *******************************************************************************************************
  274. public int Index
  275. {
  276. get
  277. {
  278. int i = 0;
  279. TaxonomyTreeItemControl item = this.ParentTreeItem;
  280. while( null!=item )
  281. {
  282. item = item.ParentTreeItem;
  283. i++;
  284. }
  285. return i;
  286. }
  287. }
  288. /// *******************************************************************************************************
  289. /// <summary>
  290. /// Sets the Active Child to this Taxonomy Item
  291. /// </summary>
  292. /// <param name="child">TreeItem you want to be the child</param>
  293. /// *******************************************************************************************************
  294. public void SetChild( TaxonomyTreeItemControl child )
  295. {
  296. this.Controls.Clear();
  297. this.Controls.Add( child );
  298. this.child = child;
  299. this.Child.IndentBase = this.IndentBase;
  300. this.Child.BubbleEvents = this.BubbleEvents;
  301. this.Child.Click += new TaxonomyTreeControlEventHandler( TaxonomyTreeItemControl_ChildClick );
  302. }
  303. /// *******************************************************************************************************
  304. /// <summary>
  305. /// Renders this Tree Item
  306. /// </summary>
  307. /// <param name="output">HtmlTextWriter to use to write to the stream</param>
  308. /// *******************************************************************************************************
  309. protected override void Render( HtmlTextWriter output )
  310. {
  311. //render the begin tag
  312. output.Write( "<div>" );
  313. Image spacer = new Image();
  314. Image item = new Image();
  315. Control text;
  316. if( IsSelected )
  317. {
  318. //
  319. // set the item Image
  320. //
  321. item.ImageUrl = TaxonomyTreeControl.SelectedItemImage;
  322. //
  323. //selected item, not clickable.
  324. //
  325. text = (Control)new Label();
  326. ((Label)text).Text= "<nobr>"+HttpUtility.HtmlEncode( KeyName )+"</nobr>";
  327. }
  328. else
  329. {
  330. //
  331. //item is clickable.
  332. //
  333. text = (Control)new HyperLink();
  334. ((HyperLink)text).Text= "<nobr>"+HttpUtility.HtmlEncode( KeyName )+"</nobr>";
  335. //
  336. //set up the postback event handler
  337. //
  338. ((HyperLink)text).NavigateUrl = Page.GetPostBackClientHyperlink( this, "" );
  339. //
  340. // set the item Image
  341. //
  342. item.ImageUrl = TaxonomyTreeControl.ItemImage;
  343. }
  344. item.ImageAlign = ImageAlign.AbsBottom;
  345. //
  346. // setup the spacer Image
  347. //
  348. spacer.Width = new Unit( this.TotalIndentSpace );
  349. spacer.ImageUrl = TaxonomyTreeControl.SpacerImage;
  350. spacer.Height = new Unit( 1 );
  351. spacer.ImageAlign = ImageAlign.AbsBottom;
  352. //render the controls.
  353. spacer.RenderControl( output );
  354. item.RenderControl( output );
  355. text.RenderControl( output );
  356. //render the end tag
  357. output.Write( "</div>\r\n" );
  358. //if this item is selected, don't render any children.
  359. if( !IsSelected )
  360. RenderChildren( output );
  361. }
  362. protected override void RenderChildren( HtmlTextWriter output )
  363. {
  364. if( null!=this.Child )
  365. this.Child.RenderControl( output );
  366. }
  367. /// *******************************************************************************************************
  368. /// <summary>
  369. /// Catches the PostBack event from the server
  370. /// </summary>
  371. /// <param name="eventArgument">Required by interface, but ignored in this implentation</param>
  372. /// *******************************************************************************************************
  373. void IPostBackEventHandler.RaisePostBackEvent( string eventArgument )
  374. {
  375. //
  376. // fire the Click event
  377. //
  378. this.OnClick( new TaxonomyTreeControlEventArgs( this ) );
  379. }
  380. /// *******************************************************************************************************
  381. /// <summary>
  382. /// Code to execute when a ChildClick event is Captured.
  383. /// </summary>
  384. /// <param name="sender">object that triggered the event</param>
  385. /// <param name="e">EventArguments for this Event.</param>
  386. /// *******************************************************************************************************
  387. private void TaxonomyTreeItemControl_ChildClick( object sender, TaxonomyTreeControlEventArgs e )
  388. {
  389. if( BubbleEvents )
  390. {
  391. this.OnClick( e );
  392. }
  393. }
  394. /// *******************************************************************************************************
  395. /// <summary>
  396. /// Fires the ChildClick event
  397. /// </summary>
  398. /// <param name="e">EventArguments to pass in the Event</param>
  399. /// *******************************************************************************************************
  400. protected void OnChildClick( TaxonomyTreeControlEventArgs e )
  401. {
  402. if( null!=this.ChildClick )
  403. this.ChildClick( this, e );
  404. }
  405. /// *******************************************************************************************************
  406. /// <summary>
  407. /// Fires the ChildClick event
  408. /// </summary>
  409. /// <param name="e">EventArguments to pass in the Event</param>
  410. /// *******************************************************************************************************
  411. protected void OnClick( TaxonomyTreeControlEventArgs e )
  412. {
  413. if( null!=this.Click )
  414. this.Click( this, e );
  415. }
  416. }
  417. /// ***********************************************************************************************************
  418. /// <summary>
  419. /// EventArguments Class
  420. /// </summary>
  421. /// ***********************************************************************************************************
  422. public class TaxonomyTreeControlEventArgs : EventArgs
  423. {
  424. private TaxonomyTreeItemControl item;
  425. /// *******************************************************************************************************
  426. /// <summary>
  427. /// Gets the TaxonomyTreeItemControl that triggered the event
  428. /// </summary>
  429. /// *******************************************************************************************************
  430. public TaxonomyTreeItemControl Item
  431. {
  432. get{ return item; }
  433. }
  434. public TaxonomyTreeControlEventArgs( TaxonomyTreeItemControl item )
  435. {
  436. this.item = item;
  437. }
  438. }
  439. }