Пример #1
0
        /// <summary>
        /// Overrides {@link goog.ui.ControlRenderer#setContent} for palettes.  Locates
        /// the HTML table representing the palette grid, and replaces the contents of
        /// each cell with a new element from the array of nodes passed as the second
        /// argument.  If the new content has too many items the table will have more
        /// rows added to fit, if there are less items than the table has cells, then the
        /// left over cells will be empty.
        /// </summary>
        /// <param name="element"> Root element of the palette control.</param>
        /// <param name="content">Array of items to replace existing
        /// palette items.</param>
        public override void setContent(HTMLElement element, goog.ui.ControlContent content)
        {
            var items = content.As <JsArray <Node> >();

            if (element != null)
            {
                var tbody = (HTMLTableSectionElement)goog.dom.getElementsByTagNameAndClass(
                    goog.dom.TagName.TBODY, le.getCssName(this.getCssClass(), "body"),
                    element)[0];
                if (tbody != null)
                {
                    var index = 0;
                    foreach (HTMLTableRowElement row in tbody.Rows)
                    {
                        foreach (var cell in row.Cells)
                        {
                            goog.dom.removeChildren(cell);
                            if (items != null)
                            {
                                var item = items[index++];
                                if (item != null)
                                {
                                    goog.dom.appendChild(cell, item);
                                }
                            }
                        }
                    }

                    // Make space for any additional items.
                    if (index < items.Length)
                    {
                        var cells = new JsArray <Node>();
                        var dom   = goog.dom.getDomHelper(element);
                        var width = ((HTMLTableRowElement)tbody.Rows[0]).Cells.Length;
                        while (index < items.Length)
                        {
                            var item = items[index++];
                            cells.Push(this.createCell(item, dom));
                            if (cells.Length == width)
                            {
                                var row = this.createRow(cells, dom);
                                goog.dom.appendChild(tbody, row);
                                cells.Clear();
                            }
                        }
                        if (cells.Length > 0)
                        {
                            while (cells.Length < width)
                            {
                                cells.Push(this.createCell("", dom));
                            }
                            var row = this.createRow(cells, dom);
                            goog.dom.appendChild(tbody, row);
                        }
                    }
                }
                // Make sure the new contents are still unselectable.
                goog.style.setUnselectable(element, true, goog.userAgent.GECKO);
            }
        }