private Element getItemContainerElement() { if (vertical) { return body; } else { return DOM.getChild(body, 0); } }
/** * Removes all menu items from this menu bar. */ public void clearItems() { // Deselect the current item selectItem(null); Element container = getItemContainerElement(); while (DOM.getChildCount(container) > 0) { container.removeChild(DOM.getChild(container, 0)); } // Set the parent of all items to null for (UIObject item : allItems) { setItemColSpan(item, 1); if (item instanceof MenuItemSeparator) { ((MenuItemSeparator) item).setParentMenu(null); } else { ((MenuItem) item).setParentMenu(null); } } // Clear out all of the items and separators items.clear(); allItems.clear(); }
/** * <b>Affected Elements:</b> * <ul> * <li>-text# = The element around the header at the specified index.</li> * <li>-text-wrapper# = The element around the header at the specified index.</li> * <li>-content# = The element around the body at the specified index.</li> * </ul> * * @see UIObject#onEnsureDebugId(String) */ @Override protected void onEnsureDebugId(String baseID) { super.onEnsureDebugId(baseID); int numHeaders = DOM.getChildCount(body) >> 1; for (int i = 0; i < numHeaders; i++) { Element tdWrapper = DOM.getFirstChild(DOM.getChild(body, 2 * i)); Element headerElem = DOM.getFirstChild(tdWrapper); Element bodyElem = DOM.getFirstChild(DOM.getChild(body, 2 * i + 1)); ensureDebugId(tdWrapper, baseID, "text-wrapper" + i); ensureDebugId(bodyElem, baseID, "content" + i); ensureDebugId(getHeaderTextElem(headerElem), baseID, "text" + i); } }
/** * Get a specific Element from the panel. * * @param row the row index * @param cell the cell index * @return the Element at the given row and cell */ protected com.google.gwt.user.client.Element getCellElement(int row, int cell) { Element tr = DOM.getChild(tbody, row); Element td = DOM.getChild(tr, cell); return DOM.asOld(DOM.getFirstChild(td)); }
Element tr = DOM.getParent(selectedItem.getElement()); if (DOM.getChildCount(tr) == 2) { Element td = DOM.getChild(tr, 1); setStyleName(td, "subMenuIcon-selected", false); Element tr = DOM.getParent(item.getElement()); if (DOM.getChildCount(tr) == 2) { Element td = DOM.getChild(tr, 1); setStyleName(td, "subMenuIcon-selected", true);
/** * Removes the specified item from the {@link MenuBar} and the physical DOM * structure. * * @param item the item to be removed * @return true if the item was removed */ private boolean removeItemElement(UIObject item) { int idx = allItems.indexOf(item); if (idx == -1) { return false; } Element container = getItemContainerElement(); container.removeChild(DOM.getChild(container, idx)); allItems.remove(idx); return true; }
/** * Returns the element's last child. * * @return the last child */ public El lastChild() { Element e = DOM.getChild(dom, DOM.getChildCount(dom) - 1); return e == null ? null : new El(e); }
/** * Adds the {@code styleName} on the {@code <tr>} for the header specified by {@code index}. * * @param index the index of the header row to apply to the style to * @param styleName the name of the class to add */ public void addHeaderStyleName(int index, String styleName) { if (index >= getWidgetCount()) { return; } Element tr = DOM.getChild(body, index * 2); setStyleName(tr, styleName, true /* add */); }
Element bodyElem = getBody(); while (DOM.getChildCount(bodyElem) > 0) { bodyElem.removeChild(DOM.getChild(bodyElem, 0));
/** * Removes the {@code styleName} off the {@code <tr>} for the header specified by {@code index}. * * @param index the index of the header row to remove the style from * @param styleName the name of the class to remove */ public void removeHeaderStyleName(int index, String styleName) { if (index >= getWidgetCount()) { return; } Element tr = DOM.getChild(body, index * 2); setStyleName(tr, styleName, false /* remove */); }
private boolean remove(Widget child, int index) { // Make sure to call this before disconnecting the DOM. boolean removed = super.remove(child); if (removed) { // Calculate which internal table elements to remove. int rowIndex = 2 * index; Element tr = DOM.getChild(body, rowIndex); body.removeChild(tr); tr = DOM.getChild(body, rowIndex); body.removeChild(tr); // Correct visible stack for new location. if (visibleStack == index) { visibleStack = -1; } else if (visibleStack > index) { --visibleStack; } // Update indices of all elements to the right. updateIndicesFrom(index); } return removed; }
private void setStackContentVisible(int index, boolean visible) { Element tr = DOM.getChild(body, (index * 2) + 1); UIObject.setVisible(tr, visible); getWidget(index).setVisible(visible); }
private void setStackVisible(int index, boolean visible) { // Get the first table row containing the widget's selector item. Element tr = DOM.getChild(body, (index * 2)); if (tr == null) { return; } // Style the stack selector item. Element td = DOM.getFirstChild(tr); setStyleName(td, DEFAULT_ITEM_STYLENAME + "-selected", visible); // Show/hide the contained widget. setStackContentVisible(index, visible); // Set the style of the next header Element trNext = DOM.getChild(body, ((index + 1) * 2)); if (trNext != null) { Element tdNext = DOM.getFirstChild(trNext); setStyleName(tdNext, DEFAULT_ITEM_STYLENAME + "-below-selected", visible); } }
/** * Sets the text associated with a child by its index. * * @param index the index of the child whose text is to be set * @param text the text to be associated with it * @param asHTML <code>true</code> to treat the specified text as HTML */ public void setStackText(int index, @IsSafeHtml String text, boolean asHTML) { if (index >= getWidgetCount()) { return; } Element tdWrapper = DOM.getChild(DOM.getChild(body, index * 2), 0); Element headerElem = DOM.getFirstChild(tdWrapper); if (asHTML) { getHeaderTextElem(headerElem).setInnerHTML(text); } else { getHeaderTextElem(headerElem).setInnerText(text); } }
/** * Physically add the td element of a {@link MenuItem} or * {@link MenuItemSeparator} to this {@link MenuBar}. * * @param beforeIndex the index where the separator should be inserted * @param tdElem the td element to be added */ private void addItemElement(int beforeIndex, Element tdElem) { if (vertical) { Element tr = DOM.createTR(); DOM.insertChild(body, tr, beforeIndex); DOM.appendChild(tr, tdElem); } else { Element tr = DOM.getChild(body, 0); DOM.insertChild(tr, tdElem, beforeIndex); } }
private void updateIndicesFrom(int beforeIndex) { for (int i = beforeIndex, c = getWidgetCount(); i < c; ++i) { Element childTR = DOM.getChild(body, i * 2); Element childTD = DOM.getFirstChild(childTR); childTD.setPropertyInt("__index", i); // Update the special style on the first element if (beforeIndex == 0) { setStyleName(childTD, DEFAULT_ITEM_STYLENAME + "-first", true); } else { setStyleName(childTD, DEFAULT_ITEM_STYLENAME + "-first", false); } } }
/** * Creates a new panel using the specified style names to apply to each row. * Each row will contain three cells (Left, Center, and Right). The Center * cell in the containerIndex row will contain the {@link Widget}. * * @param rowStyles an array of style names to apply to each row * @param containerIndex the index of the container row */ DecoratorPanel(String[] rowStyles, int containerIndex) { super(DOM.createTable()); // Add a tbody Element table = getElement(); tbody = DOM.createTBody(); DOM.appendChild(table, tbody); table.setPropertyInt("cellSpacing", 0); table.setPropertyInt("cellPadding", 0); // Add each row for (int i = 0; i < rowStyles.length; i++) { Element row = createTR(rowStyles[i]); DOM.appendChild(tbody, row); if (i == containerIndex) { containerElem = DOM.getFirstChild(DOM.getChild(row, 1)); } } // Set the overall style name setStyleName(DEFAULT_STYLENAME); }
/** * Returns the element's child. * * @param index the index of the child element * @return the child element */ public El childNode(int index) { Element e = DOM.getChild(dom, index); return e == null ? null : new El(e); }