Example usage for com.google.gwt.xml.client Node removeChild

List of usage examples for com.google.gwt.xml.client Node removeChild

Introduction

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

Prototype

Node removeChild(Node oldChild);

Source Link

Document

This method removes child oldChild.

Usage

From source file:client.net.sf.saxon.ce.xmldom.XMLParser.java

License:Mozilla Public License

private static void removeWhitespaceInner(Node n, Node parent) {
    // This n is removed from the parent if n is a whitespace node
    if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) {
        Text t = (Text) n;
        if (t.getData().matches("[ \t\n]*")) {
            parent.removeChild(t);
        }//from   w  w w .  ja v a  2 s . c o m
    }
    if (n.hasChildNodes()) {
        int length = n.getChildNodes().getLength();
        List<Node> toBeProcessed = new ArrayList<Node>();
        // We collect all the nodes to iterate as the child nodes will change 
        // upon removal
        for (int i = 0; i < length; i++) {
            toBeProcessed.add(n.getChildNodes().item(i));
        }
        // This changes the child nodes, but the iterator of nodes never changes
        // meaning that this is safe
        for (Node childNode : toBeProcessed) {
            removeWhitespaceInner(childNode, n);
        }
    }
}

From source file:org.openxdata.designer.client.view.DynamicListsView.java

/**
 * Moves an option one position upwards.
 * //from w w w . j  a v  a2s .  c om
 * @param optionDef the option to move.
 */
public void moveOptionUp(OptionDef optionDef) {
    List<OptionDef> optns = optionList;
    int index = optns.indexOf(optionDef);

    optns.remove(optionDef);

    Node parentNode = null;
    if (optionDef.getControlNode() != null) {
        parentNode = optionDef.getControlNode().getParentNode();
        parentNode.removeChild(optionDef.getControlNode());
    }

    OptionDef currentOptionDef;
    List<OptionDef> list = new ArrayList<OptionDef>();

    //Remove all from index before selected all the way downwards
    while (optns.size() >= index) {
        currentOptionDef = (OptionDef) optns.get(index - 1);
        list.add(currentOptionDef);
        optns.remove(currentOptionDef);
    }

    optns.add(optionDef);
    for (int i = 0; i < list.size(); i++) {
        if (i == 0) {
            OptionDef optnDef = (OptionDef) list.get(i);
            if (parentNode != null && optnDef.getControlNode() != null && optionDef.getControlNode() != null)
                parentNode.insertBefore(optionDef.getControlNode(), optnDef.getControlNode());
        }
        optns.add(list.get(i));
    }
}

From source file:org.openxdata.designer.client.view.DynamicListsView.java

/**
 * Moves an option one position downwards.
 * /*from  ww w.jav  a 2  s  .c  o m*/
 * @param optionDef the option to move.
 */
public void moveOptionDown(OptionDef optionDef) {
    List<OptionDef> optns = optionList;
    int index = optns.indexOf(optionDef);

    optns.remove(optionDef);

    Node parentNode = null;
    if (optionDef.getControlNode() != null) {
        parentNode = optionDef.getControlNode().getParentNode();
        parentNode.removeChild(optionDef.getControlNode());
    }

    OptionDef currentItem;
    List<OptionDef> list = new ArrayList<OptionDef>();

    //Remove all otions below selected index
    while (optns.size() > 0 && optns.size() > index) {
        currentItem = (OptionDef) optns.get(index);
        list.add(currentItem);
        optns.remove(currentItem);
    }

    for (int i = 0; i < list.size(); i++) {
        if (i == 1) {
            optns.add(optionDef); //Add after the first item but before the current (second).

            OptionDef optnDef = getNextSavedOption(list, i);
            if (optnDef.getControlNode() != null && optionDef.getControlNode() != null)
                parentNode.insertBefore(optionDef.getControlNode(), optnDef.getControlNode());
            else if (parentNode != null)
                parentNode.appendChild(optionDef.getControlNode());
        }
        optns.add(list.get(i));
    }

    //If was second last and hence becoming last
    if (list.size() == 1) {
        optns.add(optionDef);

        if (optionDef.getControlNode() != null)
            parentNode.appendChild(optionDef.getControlNode());
    }
}

From source file:org.openxdata.sharedlib.client.model.PageDef.java

/**
 * Moves a question down by one position in a list of questions.
 * //from w  w w .  j a  v a 2s.co  m
 * @param questions the list of questions.
 * @param questionDef the question to move.
 */
public static void moveQuestionDown(Vector<QuestionDef> questions, QuestionDef questionDef) {
    int index = questions.indexOf(questionDef);

    //Not relying on group node because some forms have no groups
    Element controlNode = questionDef.getControlNode();
    Element parentNode = controlNode != null ? (Element) controlNode.getParentNode() : null;
    if (questionDef.getDataType() == QuestionType.REPEAT && controlNode != null) {
        controlNode = (Element) controlNode.getParentNode();
        parentNode = (Element) parentNode.getParentNode();
    }

    questions.remove(questionDef);

    Node parentDataNode = questionDef.getDataNode() != null ? questionDef.getDataNode().getParentNode() : null;
    Node parentBindNode = questionDef.getBindNode() != null ? questionDef.getBindNode().getParentNode() : null;

    QuestionDef currentItem;
    List<QuestionDef> list = new ArrayList<QuestionDef>();

    while (questions.size() > 0 && questions.size() > index) {
        currentItem = (QuestionDef) questions.elementAt(index);
        list.add(currentItem);
        questions.remove(currentItem);
    }

    for (int i = 0; i < list.size(); i++) {
        if (i == 1) {
            questions.add(questionDef); //Add after the first item.

            if (controlNode != null) {
                if (controlNode != null && parentNode != null)
                    parentNode.removeChild(controlNode);

                QuestionDef qtnDef = getNextSavedQuestion(list, i);
                if (qtnDef.getControlNode() != null) {
                    Node sibNode = qtnDef.getControlNode();
                    if (qtnDef.getDataType() == QuestionType.REPEAT)
                        sibNode = sibNode.getParentNode();
                    parentNode.insertBefore(controlNode, sibNode);
                } else
                    parentNode.appendChild(controlNode);

                //move data node (We are not moving nested data nodes just to avoid complications
                if (!(questionDef.getBinding().indexOf('/') > -1 || qtnDef.getBinding().indexOf('/') > -1))
                    if (questionDef.getDataNode() != null
                            && questionDef.getDataNode().getParentNode() != null) {
                        parentDataNode.removeChild(questionDef.getDataNode());

                        if (qtnDef.getDataNode() != null) {
                            if (qtnDef.getDataType() == QuestionType.REPEAT
                                    && qtnDef.getBinding().contains("/"))
                                parentDataNode.insertBefore(questionDef.getDataNode(),
                                        qtnDef.getDataNode().getParentNode());
                            else
                                parentDataNode.insertBefore(questionDef.getDataNode(), qtnDef.getDataNode());
                        } else
                            parentDataNode.appendChild(questionDef.getDataNode());
                    }

                //move binding node
                if (parentBindNode != null) {
                    if (questionDef.getBindNode() != null && questionDef.getBindNode().getParentNode() != null)
                        parentBindNode.removeChild(questionDef.getBindNode());

                    if (qtnDef.getBindNode() != null)
                        parentBindNode.insertBefore(questionDef.getBindNode(), qtnDef.getBindNode());
                    else
                        parentBindNode.appendChild(questionDef.getBindNode());
                }
            }
        }
        questions.add(list.get(i));
    }

    if (list.size() == 1) {
        questions.add(questionDef);

        if (controlNode != null) {
            if (questionDef.getControlNode() != null && parentNode != null) {
                parentNode.removeChild(controlNode);
                parentNode.appendChild(controlNode);
            }

            if (!(questionDef.getBinding().indexOf('/') > -1)) {
                if (questionDef.getDataNode() != null && parentDataNode != null) {
                    parentDataNode.removeChild(questionDef.getDataNode());
                    parentDataNode.appendChild(questionDef.getDataNode());
                }
            }

            if (questionDef.getBindNode() != null && parentBindNode != null) {
                parentBindNode.removeChild(questionDef.getBindNode());
                parentBindNode.appendChild(questionDef.getBindNode());
            }
        }
    }
}

From source file:org.pentaho.ui.xul.gwt.util.AsyncXulLoader.java

License:Open Source License

public void processIncludes(final com.google.gwt.xml.client.Document gwtDoc) {

    for (int y = 0; y < gwtDoc.getChildNodes().getLength(); y++) {
        final com.google.gwt.xml.client.Node window = gwtDoc.getChildNodes().item(y);
        try {//from  w  w w .  j ava2 s .  c  om
            if (window.getNodeName().equals("window") == false) {
                continue;
            }
        } catch (Exception e) {
            continue;
        }

        for (int i = 0; i < window.getChildNodes().getLength(); i++) {
            final com.google.gwt.xml.client.Node ele = window.getChildNodes().item(i);
            if (ele.getNodeName() != null && ele.getNodeName().equals("pen:include")) {
                try {
                    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
                            ele.getAttributes().getNamedItem("src").getNodeValue());
                    builder.sendRequest(null, new RequestCallback() {
                        public void onError(Request request, Throwable exception) {
                            Window.alert("Error loading XUL: " + exception.getMessage()); //$NON-NLS-1$
                        }

                        public void onResponseReceived(Request request, Response response) {
                            com.google.gwt.xml.client.Document doc = XMLParser.parse(response.getText());
                            Node parent = ele.getParentNode();
                            parent.removeChild(ele);

                            for (int z = 0; z < doc.getChildNodes().getLength(); z++) {
                                if (doc.getChildNodes().item(z).getChildNodes().getLength() > 0) {
                                    parent.appendChild(doc.getChildNodes().item(z));
                                    break;
                                }
                            }
                            processIncludes(gwtDoc);
                            return;
                        }
                    });
                } catch (RequestException e) {
                    Window.alert("error loading bundle: " + e.getMessage()); //$NON-NLS-1$
                }

            }
        }
    }

    loadXulContainer(gwtDoc);
}