Esempio n. 1
0
        /// <summary>
        /// MaxLevel
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        protected virtual int MaxLevel(SitemapItems list)
        {
            int level = 0;

            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].NestLevel > level)
                {
                    level = list[i].NestLevel;
                }
            }

            return(level);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns true if node is last node for the current branch on that level
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        protected virtual bool LastItemAtLevel(int index, SitemapItems list)
        {
            int level = list[index].NestLevel;

            for (int i = index + 1; i < list.Count; ++i)
            {
                if (list[i].NestLevel < level)
                {
                    return(true);
                }

                if (list[i].NestLevel == level)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Render
        /// This function creates a treeview in a table from the SitemapItems list
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public virtual WebControl Render(SitemapItems list)
        {
            //init table with a width of 98%
            Table t = new Table();

            t.Width       = TableWidth;
            t.BorderWidth = 0;
            t.CellSpacing = 0;
            t.CellPadding = 0;

            int cols = MaxLevel(list) + 2;

            // an array of chars is used to determine what images to show on each row
            // the chars have the following meaning:
            // + --> crossed line
            // | --> straight line
            // \ --> line for last node on branch
            // N --> node
            // R --> root node
            // S --> space
            char[] strRow = new char[cols];

            //init row to spaces
            for (int i = 0; i < cols; ++i)
            {
                strRow[i] = 'S';
            }

            for (int i = 0; i < list.Count; ++i)
            {
                // replace the cross of the previous row in a straight line on the current row
                // do the same for last_node_line and Spaces
                for (int j = 0; j < cols; ++j)
                {
                    if (strRow[j] == '+')
                    {
                        strRow[j] = '|';
                    }
                    if (strRow[j] == '\\')
                    {
                        strRow[j] = 'S';
                    }
                }

                // show a root node image if nestlevel = 0
                if (list[i].NestLevel == 0)
                {
                    strRow[list[i].NestLevel] = 'R';
                }
                else
                {
                    strRow[list[i].NestLevel] = 'N';
                }

                //everything after the node can be replaces by spaces
                for (int j = list[i].NestLevel + 1; j < cols; ++j)
                {
                    strRow[j] = ' ';
                }

                // show no lines before the node when it's a root node
                if (list[i].NestLevel > 0)
                {
                    if (LastItemAtLevel(i, list))
                    {
                        //if it's the last node at that level of the current branch,
                        //show a last node line
                        strRow[list[i].NestLevel - 1] = '\\';
                    }
                    else
                    {
                        //else show a crossed line
                        strRow[list[i].NestLevel - 1] = '+';
                    }
                }

                // the images are determined in the char array, now make a TableRow from it
                TableRow  r = new TableRow();
                TableCell c;

                //only use the char array till the node
                for (int j = 0; j <= list[i].NestLevel; ++j)
                {
                    c = new TableCell();
                    Image img = new Image();
                    img.BorderWidth = 0;

                    img.Width  = ImagesWidth;
                    img.Height = ImagesHeight;
                    c.Width    = ImagesWidth;

                    //what image to use
                    switch (strRow[j])
                    {
                    case '+':
                        img.ImageUrl = ImageCrossedLineUrl;
                        break;

                    case '\\':
                        img.ImageUrl = ImageLastNodeLineUrl;
                        break;

                    case '|':
                        img.ImageUrl = ImageStraightLineUrl;
                        break;

                    case 'S':
                        img.ImageUrl = ImageSpacerUrl;
                        break;

                    case 'N':
                        img.ImageUrl = ImageNodeUrl;
                        break;

                    case 'R':
                        img.ImageUrl = ImageRootNodeUrl;
                        break;
                    }

                    c.Controls.Add(img);
                    r.Cells.Add(c);
                }

                // the images are done for this row, now make the hyperlink
                c = new TableCell();
                //make sure it fills the all the space left
                c.Width      = new Unit(100, UnitType.Percentage);
                c.ColumnSpan = cols - 1 - list[i].NestLevel;
                Literal lit = new Literal();
                lit.Text = "&nbsp;";
                c.Controls.Add(lit);
                HyperLink l = new HyperLink();
                l.Text        = list[i].Name;
                l.NavigateUrl = list[i].Url;
                l.CssClass    = CssStyle;

                //row is done and add everything to the table
                c.Controls.Add(l);
                r.Cells.Add(c);
                t.Rows.Add(r);
            }

            return(t);
        }