List of usage examples for com.google.gwt.dom.client Node removeChild
@Override
public Node removeChild(Node oldChild)
From source file:client.net.sf.saxon.ce.trans.update.DeleteAction.java
License:Mozilla Public License
/** * Apply the pending update action to the affected node * * @param context the XPath evaluation context *//* ww w. j av a2 s .co m*/ public void apply(XPathContext context) throws XPathException { Node parent = targetNode.getParentElement(); if (parent != null) { parent.removeChild(targetNode); } }
From source file:com.bfr.client.selection.HtmlBBox.java
License:Apache License
/** * Create a bounding box the size of the text between the two offsets of * the given textNode. Note that this temporarily modifies the document * to excise the sub-text into its own span element, which is then used * to generate the bounding box.//from ww w .j ava2 s . c o m * * @param textNode Text to create bounding box around * @param offset1 Starting offset to get bounding box from * @param offset2 Ending offset to get bounding box from * @return a new bounding box */ public static HtmlBBox getBoundingBox(Text textNode, int offset1, int offset2) { HtmlBBox res; String text = textNode.getData(); int len = text.length(); if ((offset1 == 0) && (offset2 == len)) { // Shortcut return getBoundingBox(textNode); } if ((offset2 > len) || (offset1 > offset2)) { return null; } // If this is a cursor, we still need to outline one character boolean isCursor = (offset1 == offset2); boolean posRight = false; if (isCursor) { if (offset1 == len) { offset1--; posRight = true; } else { offset2++; } } // Create 2 or 3 spans of this text, so we can measure List<Element> nodes = new ArrayList<Element>(3); Element tmpSpan, measureSpan; if (offset1 > 0) { // First tmpSpan = DOM.createSpan(); tmpSpan.setInnerHTML(text.substring(0, offset1)); nodes.add(tmpSpan); } // Middle, the one we measure measureSpan = DOM.createSpan(); measureSpan.setInnerHTML(text.substring(offset1, offset2)); nodes.add(measureSpan); if (offset2 < (len - 1)) { // Last tmpSpan = DOM.createSpan(); tmpSpan.setInnerHTML(text.substring(offset2 + 1)); nodes.add(tmpSpan); } Node parent = textNode.getParentNode(); for (Node node : nodes) { parent.insertBefore(node, textNode); } parent.removeChild(textNode); if (isCursor) { // Just make a 0-width version, depending on left or right res = new HtmlBBox(measureSpan.getAbsoluteLeft() + (posRight ? measureSpan.getOffsetWidth() : 0), measureSpan.getAbsoluteTop(), 0, measureSpan.getOffsetHeight()); } else { res = new HtmlBBox(measureSpan); } parent.insertBefore(textNode, nodes.get(0)); for (Node node : nodes) { parent.removeChild(node); } return res; }
From source file:com.bfr.client.selection.HtmlBBox.java
License:Apache License
/** * Move all children of this element up into its place, and remove the * element./* w w w . java2 s .co m*/ * * @param parent element to replace with its children */ public static void unSurround(Element parent) { Node superParent = parent.getParentNode(); Node child; while ((child = parent.getFirstChild()) != null) { parent.removeChild(child); superParent.insertBefore(child, parent); } superParent.removeChild(parent); }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * Detaches and re-attaches the element from its parent. The element is * reattached at the same position in the DOM as it was before. * //from w w w.ja va 2s . c om * Does nothing if the element is not attached to the DOM. * * @param element * The element to detach and re-attach */ public static void detachAttach(Element element) { if (element == null) { return; } Node nextSibling = element.getNextSibling(); Node parent = element.getParentNode(); if (parent == null) { return; } parent.removeChild(element); if (nextSibling == null) { parent.appendChild(element); } else { parent.insertBefore(element, nextSibling); } }
From source file:de.catma.ui.client.ui.tagger.editor.TaggerEditor.java
License:Open Source License
private void addTagInstance(SpanFactory spanFactory, Node node, int originalStartOffset, int originalEndOffset) { // the whole text sequence is within one node int startOffset = Math.min(originalStartOffset, originalEndOffset); int endOffset = Math.max(originalStartOffset, originalEndOffset); String nodeText = node.getNodeValue(); Node nodeParent = node.getParentNode(); if (startOffset != 0) { // does the tagged sequence start at the beginning? // no, ok so we create a separate text node for the untagged part at the beginning Text t = Document.get().createTextNode(nodeText.substring(0, startOffset)); nodeParent.insertBefore(t, node); }/* w w w.ja v a 2 s . c om*/ // get a list of tagged spans for every non-whitespace-containing-character-sequence // and text node for the separating whitespace-sequences Element taggedSpan = spanFactory.createTaggedSpan(nodeText.substring(startOffset, endOffset)); // insert tagged spans and whitespace text nodes before the old node nodeParent.insertBefore(taggedSpan, node); // does the tagged sequence stretch until the end of the whole sequence? if (endOffset != nodeText.length()) { // no, so we create a separate text node for the untagged sequence at the end Text t = Document.get().createTextNode(nodeText.substring(endOffset, nodeText.length())); nodeParent.insertBefore(t, node); } // remove the old node which is no longer needed nodeParent.removeChild(node); }
From source file:de.catma.ui.client.ui.tagger.editor.TaggerEditor.java
License:Open Source License
private void addTagInstance(SpanFactory spanFactory, Node startNode, int startOffset, Node endNode, int endOffset) { AffectedNodesFinder tw = new AffectedNodesFinder(getElement(), startNode, endNode); String startNodeText = startNode.getNodeValue(); Node startNodeParent = startNode.getParentNode(); String endNodeText = endNode.getNodeValue(); Node endNodeParent = endNode.getParentNode(); if (endNodeText == null) { // node is a non text node like line breaks VConsole.log("Found no text within the following node:"); DebugUtil.printNode(endNode);/* ww w . j ava2s . co m*/ endNodeText = ""; } // the range of unmarked text at the beginning of the start node's text range int unmarkedStartSeqBeginIdx = 0; int unmarkedStartSeqEndIdx = startOffset; // the marked text range of the start node int markedStartSeqBeginIdx = startOffset; int markedStartSeqEndIdx = startNodeText.length(); // the range of umarked text at the end of the end node's text range int unmarkedEndSeqBeginIdx = endOffset; int unmarkedEndSeqEndIdx = endNodeText.length(); // the marked text range of the end node int markedEndSeqBeginIdx = 0; int markedEndSeqEndIdx = endOffset; // if start node and end node are in reverse order within the tree // we switch start/end of sequences accordingly if (!tw.isAfter()) { unmarkedStartSeqBeginIdx = startOffset; unmarkedStartSeqEndIdx = startNodeText.length(); markedStartSeqBeginIdx = 0; markedStartSeqEndIdx = startOffset; unmarkedEndSeqBeginIdx = 0; unmarkedEndSeqEndIdx = endOffset; markedEndSeqBeginIdx = endOffset; markedEndSeqEndIdx = endNodeText.length(); } // a text node for the unmarked start Text unmarkedStartSeq = Document.get() .createTextNode(startNodeText.substring(unmarkedStartSeqBeginIdx, unmarkedStartSeqEndIdx)); // get a tagged span for the tagged sequence of the starting node Element taggedSpan = spanFactory .createTaggedSpan(startNodeText.substring(markedStartSeqBeginIdx, markedStartSeqEndIdx)); if (tw.isAfter()) { // insert unmarked text seqence before the old node startNodeParent.insertBefore(unmarkedStartSeq, startNode); // insert tagged spans before the old node startNodeParent.insertBefore(taggedSpan, startNode); // remove the old node startNodeParent.removeChild(startNode); } else { // insert tagged sequences before the old node startNodeParent.insertBefore(taggedSpan, startNode); // replace the old node with a new node for the unmarked sequence startNodeParent.replaceChild(unmarkedStartSeq, startNode); } List<Node> affectedNodes = tw.getAffectedNodes(); DebugUtil.printNodes("affectedNodes", affectedNodes); // create and insert tagged sequences for all the affected text nodes for (int i = 1; i < affectedNodes.size() - 1; i++) { Node affectedNode = affectedNodes.get(i); // create the tagged span ... taggedSpan = spanFactory.createTaggedSpan(affectedNode.getNodeValue()); VConsole.log("affected Node and its taggedSpan:"); DebugUtil.printNode(affectedNode); DebugUtil.printNode(taggedSpan); // ... and insert it affectedNode.getParentNode().insertBefore(taggedSpan, affectedNode); // remove the old node affectedNode.getParentNode().removeChild(affectedNode); } // the unmarked text sequence of the last node Text unmarkedEndSeq = Document.get() .createTextNode(endNodeText.substring(unmarkedEndSeqBeginIdx, unmarkedEndSeqEndIdx)); // the tagged part of the last node taggedSpan = spanFactory.createTaggedSpan(endNodeText.substring(markedEndSeqBeginIdx, markedEndSeqEndIdx)); if (tw.isAfter()) { // insert tagged part endNodeParent.insertBefore(taggedSpan, endNode); // replace old node with a text node for the unmarked part endNodeParent.replaceChild(unmarkedEndSeq, endNode); } else { // insert unmarked part endNodeParent.insertBefore(unmarkedEndSeq, endNode); // insert tagged part endNodeParent.insertBefore(taggedSpan, endNode); // remove old node endNodeParent.removeChild(endNode); } }
From source file:de.swm.commons.mobile.client.widgets.CheckBox.java
License:Apache License
/** * Sets an image to be displayed as a label for the checkbox. * * @param imgRes ImageResource for the image to be displayed *//*from w w w.ja v a 2 s .c o m*/ public void setImage(ImageResource imgRes) { Node labelElem = findLabelElement(); if (labelElem == null) { return; } if (imageNode != null) { labelElem.removeChild(imageNode); } Image img = new Image(imgRes); imageNode = img.getElement(); labelElem.appendChild(imageNode); }
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//from ww w. java 2s.c om 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(); } }; }
From source file:org.freemedsoftware.gwt.client.widget.EncounterWidget.java
License:Open Source License
public void createBasicInfoPanel() { int row = 0;//from w ww.jav a 2 s.c o m int col = 0; templateWidget = new SupportModuleWidget("EncounterNotesTemplate"); eocList = new CustomListBox(); eocMap = new HashMap<String, String>(); FlexTable basicInfoTable = new FlexTable(); // basicInfoTable.setWidth("20%"); col = 0; Label lbType = new Label(_("Type")); radType = new CustomRadioButtonGroup("type"); radType.addItem(_("Encounter Note"), "Encounter Note", new Command() { @Override public void execute() { HashMap<String, String> map = new HashMap<String, String>(); map.put("pnotesttype", _("Encounter Note")); templateWidget.setAdditionalParameters(map); } }); radType.addItem(_("Progress Note"), "Progress Note", new Command() { @Override public void execute() { HashMap<String, String> map = new HashMap<String, String>(); map.put("pnotesttype", _("Progress Note")); templateWidget.setAdditionalParameters(map); } }); basicInfoTable.setWidget(row, col++, lbType); basicInfoTable.setWidget(row++, col++, radType); col = 0; Label lbEnTemplate = new Label(_("Notes Template")); templateWidget.addValueChangeHandler(new ValueChangeHandler<Integer>() { @Override public void onValueChange(ValueChangeEvent<Integer> arg0) { applyTemplate(templateWidget.getStoredValue()); } }); HTML addTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("Add") + "</a>"); addTemplateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { callback.jsonifiedData(EncounterCommandType.CREATE_TEMPLATE); // EncounterTemplateWidget enc=new EncounterTemplateWidget(); // mainTabPanel.add(enc, "Encounter Template"); // mainTabPanel.selectTab(mainTabPanel.getWidgetCount()-1); } }); HTML editTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("Edit") + "</a>"); editTemplateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { if (templateWidget.getStoredValue() == null || templateWidget.getStoredValue().equals("0")) Window.alert(_("No template selected.")); else callback.jsonifiedData(EncounterCommandType.EDIT_TEMPLATE); // EncounterTemplateWidget enc=new EncounterTemplateWidget(); // mainTabPanel.add(enc, "Encounter Template"); // mainTabPanel.selectTab(mainTabPanel.getWidgetCount()-1); } }); HTML listTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("List") + "</a>"); templateTable = new CustomTable(); templateTable.setIndexName("id"); // patientCustomTable.setSize("100%", "100%"); templateTable.setWidth("100%"); templateTable.addColumn(_("Template Name"), "tempname"); templateTable.addColumn(_("Template Type"), "notetype"); templateTable.setTableRowClickHandler(new TableRowClickHandler() { @Override public void handleRowClick(HashMap<String, String> data, int col) { templateWidget.setValue(new Integer(data.get("id"))); templatesPopup.hide(); applyTemplate(data.get("id")); } }); listTemplateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { templatesPopup = new Popup(); templatesPopup.setPixelSize(500, 20); VerticalPanel vp = new VerticalPanel(); ScrollPanel sp = new ScrollPanel(); vp.add(sp); templateTable.clearData(); loadTemplates(); sp.add(templateTable); //sp.setHeight("300px"); PopupView viewInfo = new PopupView(vp); templatesPopup.setNewWidget(viewInfo); templatesPopup.initialize(); } }); if (!CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.WRITE)) { addTemplateBtn.setVisible(false); } if (!CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.MODIFY)) { editTemplateBtn.setVisible(false); } basicInfoTable.setWidget(row, col++, lbEnTemplate); basicInfoTable.setWidget(row, col++, templateWidget); if (CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.WRITE)) basicInfoTable.setWidget(row, col++, addTemplateBtn); if (CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.MODIFY)) basicInfoTable.setWidget(row, col++, editTemplateBtn); basicInfoTable.setWidget(row, col++, listTemplateBtn); row++; col = 0; Label lbProvider = new Label(_("Provider")); provWidget = new SupportModuleWidget("ProviderModule"); basicInfoTable.setWidget(row, col++, lbProvider); basicInfoTable.setWidget(row++, col++, provWidget); col = 0; Label lbDescription = new Label(_("Description")); tbDesc = new TextBox(); basicInfoTable.setWidget(row, col++, lbDescription); basicInfoTable.setWidget(row++, col++, tbDesc); col = 0; Label lbEoc = new Label(_("Related Episode(s)")); VerticalPanel eocVPanel = new VerticalPanel(); loadEOC(); final FlexTable eocFlexTable = new FlexTable(); eocVPanel.add(eocFlexTable); HTML addAnother = new HTML( "<a href=\"javascript:undefined;\" style='color:blue'>" + _("Add Episode of Care") + "</a>"); addAnother.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { CustomListBox eoc = new CustomListBox(); eoc.addItem(_("NONE SELECTED")); if (eocMap != null && eocMap.size() > 0) { Set<String> keys = eocMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { final String key = (String) iter.next(); final String val = (String) eocMap.get(key); JsonUtil.debug(val); eoc.addItem(val, key); } } final CustomButton remove = new CustomButton("X"); remove.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Node parentTableBody = null; Node parentTR = null; Node tempNode = remove.getElement(); while (!tempNode.getNodeName().equals("TBODY")) { tempNode = tempNode.getParentNode(); } parentTableBody = tempNode; tempNode = remove.getElement(); while (!tempNode.getNodeName().equals("TR")) { tempNode = tempNode.getParentNode(); } parentTR = tempNode; parentTableBody.removeChild(parentTR); } }); int rc = eocFlexTable.getRowCount(); eocFlexTable.setWidget(rc, 0, eoc); eocFlexTable.setWidget(rc, 1, remove); } }); eocVPanel.add(addAnother); basicInfoTable.setWidget(row, col++, lbEoc); basicInfoTable.setWidget(row++, col++, eocVPanel); col = 0; Label lbDate = new Label(_("Date")); date = new CustomDatePicker(); basicInfoTable.setWidget(row, col++, lbDate); basicInfoTable.setWidget(row++, col++, date); basicInfoPanel.add(basicInfoTable); if (formmode == EncounterFormMode.EDIT) { if (templateValuesMap.containsKey("pnotestype")) { radType.setWidgetValue(templateValuesMap.get("pnotestype")); } if (templateValuesMap.containsKey("pnotesdt")) { date.setValue(templateValuesMap.get("pnotesdt")); } if (templateValuesMap.containsKey("pnotesdescrip")) { tbDesc.setText(templateValuesMap.get("pnotesdescrip")); } if (templateValuesMap.containsKey("pnotesdoc")) { provWidget.setValue(new Integer(templateValuesMap.get("pnotesdoc"))); } if (templateValuesMap.containsKey("pnotestemplate")) { templateWidget.setValue(new Integer(templateValuesMap.get("pnotestemplate"))); } } }
From source file:org.jboss.errai.common.client.dom.DOMUtil.java
License:Apache License
/** * Detaches all children from a node.//from w w w .ja v a 2 s . c om * * @param node * Must not be null. * @return True iff any children were detached by this call. */ public static boolean removeAllChildren(final Node node) { final boolean hadChildren = node.getLastChild() != null; while (node.getLastChild() != null) { node.removeChild(node.getLastChild()); } return hadChildren; }