Java Code Examples for com.google.gwt.dom.client.Node#removeFromParent()

The following examples show how to use com.google.gwt.dom.client.Node#removeFromParent() . 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: Repairer.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private void reattachImplChildren(Node parentNodelet, Node nodeletBefore, Node nodeletAfter,
    ContentNode first, ContentNode last) {
  // TODO(danilatos): Replace this hairy code with pre-order traversal
  // getters, once they exist
  while (true) {
    Node nodelet = nodeletBefore == null
        ? strippingView.getFirstChild(parentNodelet)
        : strippingView.getNextSibling(nodeletBefore);

    if (nodelet == null || nodelet == nodeletAfter) {
      break;
    }

    if (nodelet.getParentElement() != null) {
      nodelet.removeFromParent();
    }
  }

  for (ContentNode node = first; node != last; node = renderedView.getNextSibling(node)) {
    parentNodelet.insertBefore(node.getImplNodelet(), nodeletAfter);
  }
}
 
Example 2
Source File: Repairer.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private void reattachImplChildren(Node parentNodelet, Node nodeletBefore, Node nodeletAfter,
    ContentNode first, ContentNode last) {
  // TODO(danilatos): Replace this hairy code with pre-order traversal
  // getters, once they exist
  while (true) {
    Node nodelet = nodeletBefore == null
        ? strippingView.getFirstChild(parentNodelet)
        : strippingView.getNextSibling(nodeletBefore);

    if (nodelet == null || nodelet == nodeletAfter) {
      break;
    }

    if (nodelet.getParentElement() != null) {
      nodelet.removeFromParent();
    }
  }

  for (ContentNode node = first; node != last; node = renderedView.getNextSibling(node)) {
    parentNodelet.insertBefore(node.getImplNodelet(), nodeletAfter);
  }
}
 
Example 3
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Remove nodes in the given range from the DOM
 * @param from
 * @param toExcl
 */
public static void removeNodes(Node from, Node toExcl) {
  if (from == null || !from.hasParentElement()) {
    return;
  }
  for (Node n = from; n != toExcl && n != null;) {
    Node r = n;
    n = n.getNextSibling();
    r.removeFromParent();
  }
}
 
Example 4
Source File: SelectionCoordinatesHelperW3C.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getPosition(Node focusNode, int focusOffset) {
  if (focusNode == null || focusNode.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(focusNode)) {
    // We don't want to split the existing child text node, so we just add
    // duplicate the string up to the offset.
    Node txt =
        Document.get().createTextNode(
            focusNode.getNodeValue().substring(0, focusOffset));
    try {
      mutationListener.startTransientMutations();
      focusNode.getParentNode().insertBefore(txt, focusNode);
      txt.getParentNode().insertAfter(SPAN, txt);
      OffsetPosition ret =
          new OffsetPosition(SPAN.getOffsetLeft(), SPAN.getOffsetTop(), SPAN.getOffsetParent());

      return ret;
    } finally {
      SPAN.removeFromParent();
      txt.removeFromParent();
      mutationListener.endTransientMutations();
    }
  } else {
    Element e = focusNode.cast();
    return new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
  }
}
 
Example 5
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Remove nodes in the given range from the DOM
 * @param from
 * @param toExcl
 */
public static void removeNodes(Node from, Node toExcl) {
  if (from == null || !from.hasParentElement()) {
    return;
  }
  for (Node n = from; n != toExcl && n != null;) {
    Node r = n;
    n = n.getNextSibling();
    r.removeFromParent();
  }
}
 
Example 6
Source File: SelectionCoordinatesHelperW3C.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private OffsetPosition getPosition(Node focusNode, int focusOffset) {
  if (focusNode == null || focusNode.getParentElement() == null) {
    // Return null if cannot get selection, or selection is inside an
    // "unattached" node.
    return null;
  }

  if (DomHelper.isTextNode(focusNode)) {
    // We don't want to split the existing child text node, so we just add
    // duplicate the string up to the offset.
    Node txt =
        Document.get().createTextNode(
            focusNode.getNodeValue().substring(0, focusOffset));
    try {
      mutationListener.startTransientMutations();
      focusNode.getParentNode().insertBefore(txt, focusNode);
      txt.getParentNode().insertAfter(SPAN, txt);
      OffsetPosition ret =
          new OffsetPosition(SPAN.getOffsetLeft(), SPAN.getOffsetTop(), SPAN.getOffsetParent());

      return ret;
    } finally {
      SPAN.removeFromParent();
      txt.removeFromParent();
      mutationListener.endTransientMutations();
    }
  } else {
    Element e = focusNode.cast();
    return new OffsetPosition(e.getOffsetLeft(), e.getOffsetTop(), e.getOffsetParent());
  }
}