Example #1
0
        /// <summary>
        /// Overrides {@link goog.ui.Control#setContentInternal} by also updating the
        /// grid size and the selection model.  Considered protected.
        /// </summary>
        /// <param name="content">Array of DOM nodes to be displayed
        /// as items in the palette grid (one item per cell).</param>
        public override void setContentInternal(goog.ui.ControlContent content)
        {
            var items = content.As <JsArray <Node> >();

            base.setContentInternal(new ControlContent(items));

            // Adjust the palette size.
            this.adjustSize_();

            // Add the items to the selection model, replacing previous items (if any).
            if (this.selectionModel_ != null)
            {
                // We already have a selection model; just replace the items.
                this.selectionModel_.clear();
                this.selectionModel_.addItems(items);
            }
            else
            {
                // Create a selection model, initialize the items, and hook up handlers.
                this.selectionModel_ = new goog.ui.SelectionModel(items);
                this.selectionModel_.setSelectionHandler(new Action <Node, bool>(this.selectItem_));
                this.getHandler().listen(
                    this.selectionModel_, goog.events.EventType.SELECT,
                    new Action <events.Event>(this.handleSelectionChange));
            }

            // In all cases, clear the highlight.
            this.highlightedIndex_ = -1;
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>
        /// </summary>
        /// Takes a control's root element, and sets its content to the given text
        /// caption or DOM structure.  The default implementation replaces the children
        /// of the given element.  Renderers that create more complex DOM structures
        /// must override this method accordingly.
        /// <param name="element">The control's root element.</param>
        /// <param name="content">Text caption or DOM structure to be</param>
        ///     set as the control's content. The DOM nodes will not be cloned, they
        ///     will only moved under the content element of the control.
        public virtual void setContent(HTMLElement element, goog.ui.ControlContent content)
        {
            var contentElem = this.getContentElement(element);

            if (contentElem != null)
            {
                goog.dom.removeChildren(contentElem);
                if (content != null)
                {
                    if (content.IsString())
                    {
                        goog.dom.setTextContent(contentElem, content.AsString());
                    }
                    else
                    {
                        var childHandler = new Action <Union <string, Node> >((child) => {
                            if (child != null)
                            {
                                var doc = goog.dom.getOwnerDocument(contentElem);
                                contentElem.AppendChild(
                                    child.Is <string>() ? doc.CreateTextNode(child.As <string>()) : child.As <Node>());
                            }
                        });
                        if (content.IsArray())
                        {
                            // Array of nodes.
                            foreach (var node in content.AsArray())
                            {
                                childHandler(node);
                            }
                        }
                        else if (content.Is <NodeList>())
                        {
                            // NodeList. The second condition filters out TextNode which also has
                            // length attribute but is not array like. The nodes have to be cloned
                            // because childHandler removes them from the list during iteration.
                            foreach (var node in content.As <NodeList>())
                            {
                                childHandler(node);
                            }
                        }
                        else
                        {
                            // Node or string.
                            childHandler(content.AsNodeOrString());
                        }
                    }
                }
            }
        }