Example usage for com.google.gwt.dom.client Node insertAfter

List of usage examples for com.google.gwt.dom.client Node insertAfter

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Node insertAfter.

Prototype

@Override
    public Node insertAfter(Node newChild, Node refChild) 

Source Link

Usage

From source file:jetbrains.jetpad.mapper.gwt.DomUtil.java

License:Apache License

public static List<Node> nodeChildren(final Node n) {
    return new AbstractList<Node>() {
        @Override//  w  w  w .  j  a  v a 2s  . c  o m
        public Node get(int index) {
            return n.getChild(index);
        }

        @Override
        public Node set(int index, Node element) {
            if (element.getParentElement() != null) {
                throw new IllegalStateException();
            }

            Node child = get(index);
            n.replaceChild(child, element);
            return child;
        }

        @Override
        public void add(int index, Node element) {
            if (element.getParentElement() != null) {
                throw new IllegalStateException();
            }

            if (index == 0) {
                n.insertFirst(element);
            } else {
                Node prev = n.getChild(index - 1);
                n.insertAfter(element, prev);
            }
        }

        @Override
        public Node remove(int index) {
            Node child = n.getChild(index);
            n.removeChild(child);
            return child;
        }

        @Override
        public int size() {
            return n.getChildCount();
        }
    };
}