using System; using System.Collections; using System.Data; using System.Data.SqlClient; using System.IO; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using UDDI; using UDDI.Diagnostics; namespace UDDI.Web { // // TODO: Move most of this code into a base class (HyarchicalBreadCrumbsControl) and inherit from that // public delegate void TaxonomyTreeControlEventHandler( object sender, TaxonomyTreeControlEventArgs e ); public class TaxonomyTreeControl : TaxonomyTreeItemControl { public TaxonomyTreeControl() : base() { // // wire up local event handlers // this.Init += new EventHandler( TaxonomyTreeControl_Init ); this.Load += new EventHandler( TaxonomyTreeControl_Load ); } private static string root = ( ( "/" == HttpContext.Current.Request.ApplicationPath )?"": HttpContext.Current.Request.ApplicationPath ); public static string SpacerImage { get{ return root+"/images/blank.gif"; } } public static string ItemImage { get{ return root+"/images/bluebox.gif"; } } public static string SelectedItemImage { get{ return root+"/images/bluearrow.gif"; } } private int selectedIndex = 0; /// ******************************************************************************************************* /// /// Gets the Selected Index of the Tree /// /// ******************************************************************************************************* public int SelectedIndex { get{ return selectedIndex; } } private string cssClass; /// ******************************************************************************************************* /// /// Gets or Sets the Style Sheet class to use. /// /// ******************************************************************************************************* public string CssClass { get{ return this.cssClass; } set{ this.cssClass = value; } } /// ******************************************************************************************************* /// /// Selects and Item in the Tree by the index of the item /// /// Index in the tree you want to be selected. Rendering will stop at this node /// ******************************************************************************************************* public void SelectItem( int index ) { TaxonomyTreeItemControl item = this; while( item.Index!=index ) { item.isSelected = false; item = item.Child; } item.isSelected = true; this.selectedIndex = item.Index; } /// /// /// /// protected override void Render( HtmlTextWriter output ) { //wrap all items in a parent div. output.Write( "
\r\n" ); base.Render( output ); output.Write( "
\r\n" ); } /// ******************************************************************************************************* /// /// /// /// object that triggered the event /// EventArguments for this Event. /// ******************************************************************************************************* private void TaxonomyTreeControl_Init( object sender, EventArgs e ) { } /// ******************************************************************************************************* /// /// /// /// object that triggered the event /// EventArguments for this Event. /// ******************************************************************************************************* private void TaxonomyTreeControl_Load( object sender, EventArgs e ) { } } /// *********************************************************************************************************** /// /// TaxonomyTreeItemControl /// Holds information about a selected Taxonomy Item. /// /// *********************************************************************************************************** public class TaxonomyTreeItemControl : UddiControl, IPostBackEventHandler { public event TaxonomyTreeControlEventHandler ChildClick; public event TaxonomyTreeControlEventHandler Click; public TaxonomyTreeItemControl() { this.ChildClick += new TaxonomyTreeControlEventHandler( TaxonomyTreeItemControl_ChildClick ); } protected internal bool isSelected; /// ******************************************************************************************************* /// /// Get if the node is the selected node. /// /// ******************************************************************************************************* public bool IsSelected { get{ return isSelected; } } private bool bubbleEvents = false; /// /// Gets or Sets if the TreeItem should bubble its ClickClick Events up. /// public bool BubbleEvents { get { if( null!=this.ParentTree ) return this.ParentTree.BubbleEvents; return bubbleEvents; } set{ bubbleEvents=value; } } private int indentBase=0; /// /// Gets or Sets the base number of pixels to indent each node in the tree. /// This number will be multiplied by the index to find the total indent space. /// public int IndentBase { get { if( 0==indentBase ) { if( null!=this.ParentTreeItem ) indentBase = this.ParentTreeItem.IndentBase; } return indentBase; } set{ indentBase=value; } } /// /// Gets the Total Indent space used for this Tree Item /// public int TotalIndentSpace { get{ return ( IndentBase * Index ); } } /// /// Gets the Total count of Children in the hyarchy of the tree including it self /// public int Count { get { int i = 1; TaxonomyTreeItemControl item = this; while( null!=item.Child ) { item = item.Child; i++; } return i; } } protected string keyValue; /// ******************************************************************************************************* /// /// Gets or Sets the KeyValue associated with the item /// /// ******************************************************************************************************* public string KeyValue { get{ return keyValue; } set{ keyValue = value; } } protected int taxonomyID; /// ******************************************************************************************************* /// /// Gets or Sets the TaxonomyID associated with this item /// /// ******************************************************************************************************* public int TaxonomyID { get{ return taxonomyID; } set{ taxonomyID = value; } } protected string keyName; /// ******************************************************************************************************* /// /// Gets or Sets the KeyName associated with this item /// /// ******************************************************************************************************* public string KeyName { get{ return keyName; } set{ keyName = value; } } protected TaxonomyTreeItemControl child; /// ******************************************************************************************************* /// /// Gets the Active child of the current Taxonomy Item /// /// ******************************************************************************************************* public TaxonomyTreeItemControl Child { get{ return child; } } /// ******************************************************************************************************* /// /// Gets the Active parent of the current Taxonomy Item /// /// ******************************************************************************************************* public TaxonomyTreeItemControl ParentTreeItem { get { if( null!=this.Parent && this.Parent is TaxonomyTreeItemControl ) { return (TaxonomyTreeItemControl)this.Parent; } else { return null; } } } /// ******************************************************************************************************* /// /// Gets the Tree that this item belong to /// /// ******************************************************************************************************* public TaxonomyTreeControl ParentTree { get { TaxonomyTreeItemControl item = this.ParentTreeItem; while( null!=item && !(item is TaxonomyTreeControl ) ) { item = item.ParentTreeItem; } return (TaxonomyTreeControl)item; } } /// ******************************************************************************************************* /// /// Gets the index of this Item in the Tree /// /// ******************************************************************************************************* public int Index { get { int i = 0; TaxonomyTreeItemControl item = this.ParentTreeItem; while( null!=item ) { item = item.ParentTreeItem; i++; } return i; } } /// ******************************************************************************************************* /// /// Sets the Active Child to this Taxonomy Item /// /// TreeItem you want to be the child /// ******************************************************************************************************* public void SetChild( TaxonomyTreeItemControl child ) { this.Controls.Clear(); this.Controls.Add( child ); this.child = child; this.Child.IndentBase = this.IndentBase; this.Child.BubbleEvents = this.BubbleEvents; this.Child.Click += new TaxonomyTreeControlEventHandler( TaxonomyTreeItemControl_ChildClick ); } /// ******************************************************************************************************* /// /// Renders this Tree Item /// /// HtmlTextWriter to use to write to the stream /// ******************************************************************************************************* protected override void Render( HtmlTextWriter output ) { //render the begin tag output.Write( "
" ); Image spacer = new Image(); Image item = new Image(); Control text; if( IsSelected ) { // // set the item Image // item.ImageUrl = TaxonomyTreeControl.SelectedItemImage; // //selected item, not clickable. // text = (Control)new Label(); ((Label)text).Text= ""+HttpUtility.HtmlEncode( KeyName )+""; } else { // //item is clickable. // text = (Control)new HyperLink(); ((HyperLink)text).Text= ""+HttpUtility.HtmlEncode( KeyName )+""; // //set up the postback event handler // ((HyperLink)text).NavigateUrl = Page.GetPostBackClientHyperlink( this, "" ); // // set the item Image // item.ImageUrl = TaxonomyTreeControl.ItemImage; } item.ImageAlign = ImageAlign.AbsBottom; // // setup the spacer Image // spacer.Width = new Unit( this.TotalIndentSpace ); spacer.ImageUrl = TaxonomyTreeControl.SpacerImage; spacer.Height = new Unit( 1 ); spacer.ImageAlign = ImageAlign.AbsBottom; //render the controls. spacer.RenderControl( output ); item.RenderControl( output ); text.RenderControl( output ); //render the end tag output.Write( "
\r\n" ); //if this item is selected, don't render any children. if( !IsSelected ) RenderChildren( output ); } protected override void RenderChildren( HtmlTextWriter output ) { if( null!=this.Child ) this.Child.RenderControl( output ); } /// ******************************************************************************************************* /// /// Catches the PostBack event from the server /// /// Required by interface, but ignored in this implentation /// ******************************************************************************************************* void IPostBackEventHandler.RaisePostBackEvent( string eventArgument ) { // // fire the Click event // this.OnClick( new TaxonomyTreeControlEventArgs( this ) ); } /// ******************************************************************************************************* /// /// Code to execute when a ChildClick event is Captured. /// /// object that triggered the event /// EventArguments for this Event. /// ******************************************************************************************************* private void TaxonomyTreeItemControl_ChildClick( object sender, TaxonomyTreeControlEventArgs e ) { if( BubbleEvents ) { this.OnClick( e ); } } /// ******************************************************************************************************* /// /// Fires the ChildClick event /// /// EventArguments to pass in the Event /// ******************************************************************************************************* protected void OnChildClick( TaxonomyTreeControlEventArgs e ) { if( null!=this.ChildClick ) this.ChildClick( this, e ); } /// ******************************************************************************************************* /// /// Fires the ChildClick event /// /// EventArguments to pass in the Event /// ******************************************************************************************************* protected void OnClick( TaxonomyTreeControlEventArgs e ) { if( null!=this.Click ) this.Click( this, e ); } } /// *********************************************************************************************************** /// /// EventArguments Class /// /// *********************************************************************************************************** public class TaxonomyTreeControlEventArgs : EventArgs { private TaxonomyTreeItemControl item; /// ******************************************************************************************************* /// /// Gets the TaxonomyTreeItemControl that triggered the event /// /// ******************************************************************************************************* public TaxonomyTreeItemControl Item { get{ return item; } } public TaxonomyTreeControlEventArgs( TaxonomyTreeItemControl item ) { this.item = item; } } }