Java Code Examples for com.google.gwt.dom.client.Element#getFirstChildElement()

The following examples show how to use com.google.gwt.dom.client.Element#getFirstChildElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubaTreeTableWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void initCellWithText(String text, char align, String style, boolean textIsHTML,
                                boolean sorted, String description, TableCellElement td) {
    super.initCellWithText(text, align, style, textIsHTML, sorted, description, td);

    Element tdElement = td.cast();
    Tools.textSelectionEnable(tdElement, _delegate.textSelectionEnabled);

    if ((_delegate.clickableColumns != null && _delegate.clickableColumns.contains(currentColumnKey))
            || (_delegate.clickableTableColumns != null && _delegate.clickableTableColumns.contains(currentColumnKey))) {
        tdElement.addClassName(CUBA_TABLE_CLICKABLE_CELL_CONTENT);
        Element wrapperElement = tdElement.getFirstChildElement();
        final Element clickableSpan = DOM.createSpan().cast();
        clickableSpan.setClassName(CUBA_TABLE_CLICKABLE_CELL_STYLE);

        clickableSpan.setInnerText(wrapperElement.getInnerText());

        wrapperElement.removeAllChildren();
        DOM.appendChild(wrapperElement, clickableSpan);
    }

    if (_delegate.multiLineCells) {
        Style wrapperStyle = tdElement.getFirstChildElement().getStyle();
        wrapperStyle.setWhiteSpace(Style.WhiteSpace.PRE_LINE);
    }
}
 
Example 2
Source File: WavePanelImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a wave panel.
 *
 * @param views view bundle
 * @param panelDom element in the DOM on which to build the wave panel
 * @param container panel to adopt the wave panel's widget, or {@code null}
 *        for the wave panel to be a root widget
 */
public static WavePanelImpl create(
    DomAsViewProvider views, Element panelDom, LogicalPanel container) {
  Preconditions.checkArgument(panelDom != null);
  EventDispatcherPanel events =
      (container != null) ? EventDispatcherPanel.inGwtContext(panelDom, container)
          : EventDispatcherPanel.of(panelDom);
  WavePanelImpl panel = new WavePanelImpl(views, events);

  // Existing content?
  Element frameDom = panelDom.getFirstChildElement();
  if (frameDom != null) {
    panel.init(frameDom);
  }
  return panel;
}
 
Example 3
Source File: WavePanelImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a wave panel.
 *
 * @param views view bundle
 * @param panelDom element in the DOM on which to build the wave panel
 * @param container panel to adopt the wave panel's widget, or {@code null}
 *        for the wave panel to be a root widget
 */
public static WavePanelImpl create(
    DomAsViewProvider views, Element panelDom, LogicalPanel container) {
  Preconditions.checkArgument(panelDom != null);
  EventDispatcherPanel events =
      (container != null) ? EventDispatcherPanel.inGwtContext(panelDom, container)
          : EventDispatcherPanel.of(panelDom);
  WavePanelImpl panel = new WavePanelImpl(views, events);

  // Existing content?
  Element frameDom = panelDom.getFirstChildElement();
  if (frameDom != null) {
    panel.init(frameDom);
  }
  return panel;
}
 
Example 4
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the index of an element in its parent's list of child elements.
 * This is not the same as {@link #findChildIndex(Node)}, since it ignores
 * non-element nodes. It is in line with the element-only view of a collection
 * of children exposed by {@link Element#getFirstChildElement()} and
 * {@link Element#getNextSiblingElement()}.
 *
 * @param child  an element
 * @return the index of {@code child}, or -1 if {@code child} is not a child
 *   of its parent.
 * @see #findChildIndex(Node)
 */
public static final int findChildElementIndex(Element child) {
  Element parent = child.getParentElement();
  Element e = parent.getFirstChildElement();
  int i = 0;
  while (e != null) {
    if (e.equals(child)) {
      return i;
    } else {
      e = e.getNextSiblingElement();
      i++;
    }
  }
  return -1;
}
 
Example 5
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 6
Source File: DomViewHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static Element getAfter(Element container, Element ref) {
  Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container));
  if (ref == null) {
    return container.getFirstChildElement();
  } else {
    return ref.getNextSiblingElement();
  }
}
 
Example 7
Source File: HtmlDomRenderer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/** Turns a UiBuilder rendering into a DOM element. */
private Element parseHtml(UiBuilder ui) {
  if (ui == null) {
    return null;
  }
  SafeHtmlBuilder html = new SafeHtmlBuilder();
  ui.outputHtml(html);
  Element div = com.google.gwt.dom.client.Document.get().createDivElement();
  div.setInnerHTML(html.toSafeHtml().asString());
  Element ret = div.getFirstChildElement();
  // Detach, in order that this element looks free-floating (required by some
  // preconditions).
  ret.removeFromParent();
  return ret;
}
 
Example 8
Source File: EventDispatcherPanelGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/** Injects some HTML into the DOM. */
private static Element load(SafeHtml html) {
  Element container = Document.get().createDivElement();
  container.setInnerHTML(html.asString());
  Element content = container.getFirstChildElement();
  RootPanel.get().getElement().appendChild(content);
  return content;
}
 
Example 9
Source File: GroupedListBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
@Override
public void remove() {
    Element select = getElement();
    while (count-- > 0) {
        Element option = select.getFirstChildElement();
        if (option != null) {
            select.removeChild(option);
        }
    }
    count = 0;
}
 
Example 10
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the index of an element in its parent's list of child elements.
 * This is not the same as {@link #findChildIndex(Node)}, since it ignores
 * non-element nodes. It is in line with the element-only view of a collection
 * of children exposed by {@link Element#getFirstChildElement()} and
 * {@link Element#getNextSiblingElement()}.
 *
 * @param child  an element
 * @return the index of {@code child}, or -1 if {@code child} is not a child
 *   of its parent.
 * @see #findChildIndex(Node)
 */
public static final int findChildElementIndex(Element child) {
  Element parent = child.getParentElement();
  Element e = parent.getFirstChildElement();
  int i = 0;
  while (e != null) {
    if (e.equals(child)) {
      return i;
    } else {
      e = e.getNextSiblingElement();
      i++;
    }
  }
  return -1;
}
 
Example 11
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 12
Source File: DomViewHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public static Element getAfter(Element container, Element ref) {
  Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container));
  if (ref == null) {
    return container.getFirstChildElement();
  } else {
    return ref.getNextSiblingElement();
  }
}
 
Example 13
Source File: HtmlDomRenderer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** Turns a UiBuilder rendering into a DOM element. */
private Element parseHtml(UiBuilder ui) {
  if (ui == null) {
    return null;
  }
  SafeHtmlBuilder html = new SafeHtmlBuilder();
  ui.outputHtml(html);
  Element div = com.google.gwt.dom.client.Document.get().createDivElement();
  div.setInnerHTML(html.toSafeHtml().asString());
  Element ret = div.getFirstChildElement();
  // Detach, in order that this element looks free-floating (required by some
  // preconditions).
  ret.removeFromParent();
  return ret;
}
 
Example 14
Source File: EventDispatcherPanelGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** Injects some HTML into the DOM. */
private static Element load(SafeHtml html) {
  Element container = Document.get().createDivElement();
  container.setInnerHTML(html.asString());
  Element content = container.getFirstChildElement();
  RootPanel.get().getElement().appendChild(content);
  return content;
}
 
Example 15
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Update the image based on the current state.
 *
 * @param isLoading true if still loading data
 */
private void updateImage(boolean isLoading) {
  // Early out if this is a root node.
  if (isRootNode()) {
    return;
  }

  // Replace the image element with a new one.
  boolean isTopLevel = parentNode.isRootNode();
  SafeHtml html = tree.getClosedImageHtml(isTopLevel);
  if (open) {
    html = isLoading ? tree.getLoadingImageHtml() : tree.getOpenImageHtml(isTopLevel);
  }
  if (nodeInfoLoaded && nodeInfo == null) {
    html = LEAF_IMAGE;
  }
  Element tmp = Document.get().createDivElement();
  tmp.setInnerSafeHtml(html);
  Element imageElem = tmp.getFirstChildElement();

  Element oldImg = getImageElement();
  oldImg.getParentElement().replaceChild(imageElem, oldImg);

  // Set 'aria-expanded' state
  // don't set aria-expanded on the leaf nodes
  if (isLeaf()) {
    Roles.getTreeitemRole().removeAriaExpandedState(getElement());
  }
  else {
    Roles.getTreeitemRole().setAriaExpandedState(getElement(), ExpandedValue.of(open));
  }
}
 
Example 16
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the element that selection is applied to.
 *
 * @param nodeElem the element that represents the node
 * @return the cell parent within the node
 */
static Element getSelectionElement(Element nodeElem) {
  return nodeElem.getFirstChildElement();
}