Java Code Examples for com.google.gwt.dom.client.Element#insertBefore()
The following examples show how to use
com.google.gwt.dom.client.Element#insertBefore() .
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: DomViewHelper.java From swellrt with Apache License 2.0 | 5 votes |
public static void attachBefore(Element container, Element ref, Element target) { Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container)); Preconditions.checkArgument(target.getParentElement() == null); if (ref == null) { container.appendChild(target); } else { container.insertBefore(target, ref); } }
Example 2
Source File: DomViewHelper.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
public static void attachBefore(Element container, Element ref, Element target) { Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container)); Preconditions.checkArgument(target.getParentElement() == null); if (ref == null) { container.appendChild(target); } else { container.insertBefore(target, ref); } }
Example 3
Source File: ImplPanel.java From swellrt with Apache License 2.0 | 4 votes |
/** * Inserts a widget into this panel, attaching its HTML to a specified * location within this panel's HTML. * <p> * Note that in order for this panel to have arbitrary HTML decorations, * rather than none at all, this panel must not care about the logical order * of its child widgets (an inherited restriction from ComplexPanel, which * assumes logical child index == physical DOM index). * <p> * Assumes (but does not check) that {@code container} is a descendant of this * widget's element, and that {@code reference} is a direct child of {@code * container}. * * @param child * @param container * @param reference */ public void insertBefore(Widget child, Element container, Element reference) { // The implementation below is identical to add(), except the physical DOM // insertion is positional. // Detach new child. child.removeFromParent(); // Logical attach. getChildren().add(child); // Physical attach. container.insertBefore(child.getElement(), reference); // Adopt. adopt(child); }
Example 4
Source File: GroupedListBox.java From swcv with MIT License | 4 votes |
@Override public void insertItem(String item, String value, int index) { // find the delimiter if there is one int pipe = (item != null) ? item.indexOf('|') : -1; while (pipe != -1 && pipe + 1 != item.length() && item.charAt(pipe + 1) == '|') { pipe = item.indexOf('|', pipe + 2); } // extract the group if we found a delimiter String group = null; if (pipe != -1) { group = item.substring(0, pipe).trim(); item = item.substring(pipe + 1).trim(); // make sure we convert || -> | in the group name group = group.replace("||", "|"); } Element parent = getSelectElement(); Node before = null; if (group != null) { OptGroupElement optgroup = findOptGroupElement(group); if (optgroup != null) { // add it to this optgroup parent = optgroup; // adjust the index to inside the group int adjusted = getIndexInGroup(group, index); // we had a real index (wasn't negative which means // add to the end), but it was too low for this group. // put it at the beginning of the group. if (adjusted < 0 && index >= 0) { adjusted = 0; } // check the range and if it's out of range, we'll // just add it to the end // of the group (before == null) if (0 <= adjusted && adjusted < optgroup.getChildCount()) { before = optgroup.getChild(adjusted); } } else { // add a new group and add the item to it optgroup = Document.get().createOptGroupElement(); optgroup.setLabel(group); parent.appendChild(optgroup); parent = optgroup; before = null; } } else { // make sure we're not past the initial "group" of // ungrouped options int max = getIndexOfFirstGroup(); if (index < 0 || index > max) { before = (max < parent.getChildCount()) ? parent.getChild(max) : null; } else if (0 <= index && index < parent.getChildCount()) { before = parent.getChild(index); } } OptionElement option = createOption(item, value); parent.insertBefore(option, before); }
Example 5
Source File: GroupedListBox.java From gwt-traction with Apache License 2.0 | 4 votes |
@Override public void insertItem(String item, String value, int index) { // find the delimiter if there is one int pipe = (item != null) ? item.indexOf('|') : -1; while (pipe != -1 && pipe + 1 != item.length() && item.charAt(pipe + 1) == '|') { pipe = item.indexOf('|', pipe + 2); } // extract the group if we found a delimiter String group = null; if (pipe != -1) { group = item.substring(0, pipe).trim(); item = item.substring(pipe + 1).trim(); // make sure we convert || -> | in the group name group = group.replace("||", "|"); } // convert || -> | in the item name if (item != null) { item = item.replace("||", "|"); } // make sure we always have a group if (group == null) { group = ""; } Element parent; Node before; OptGroup optgroup = findOptGroup(group); if (optgroup != null) { parent = optgroup.getInsertParent(); before = optgroup.getInsertBeforeElement(index); } else { optgroup = createOptGroup(group); parent = optgroup.getInsertParent(); before = null; } optgroup.increment(); OptionElement option = createOption(item, value); parent.insertBefore(option, before); }
Example 6
Source File: ImplPanel.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
/** * Inserts a widget into this panel, attaching its HTML to a specified * location within this panel's HTML. * <p> * Note that in order for this panel to have arbitrary HTML decorations, * rather than none at all, this panel must not care about the logical order * of its child widgets (an inherited restriction from ComplexPanel, which * assumes logical child index == physical DOM index). * <p> * Assumes (but does not check) that {@code container} is a descendant of this * widget's element, and that {@code reference} is a direct child of {@code * container}. * * @param child * @param container * @param reference */ public void insertBefore(Widget child, Element container, Element reference) { // The implementation below is identical to add(), except the physical DOM // insertion is positional. // Detach new child. child.removeFromParent(); // Logical attach. getChildren().add(child); // Physical attach. container.insertBefore(child.getElement(), reference); // Adopt. adopt(child); }
Example 7
Source File: DomHelper.java From swellrt with Apache License 2.0 | 3 votes |
/** * Insert before, but for a range of adjacent siblings * * TODO(danilatos): Apparently safari and firefox let you do this in one * go using ranges, which could be a lot faster than iterating manually. * Create a deferred binding implementation. * @param parent * @param from * @param toExcl * @param refChild */ public static void moveNodes(Element parent, Node from, Node toExcl, Node refChild) { for (Node n = from; n != toExcl; ) { Node m = n; n = n.getNextSibling(); parent.insertBefore(m, refChild); } }
Example 8
Source File: DomHelper.java From incubator-retired-wave with Apache License 2.0 | 3 votes |
/** * Insert before, but for a range of adjacent siblings * * TODO(danilatos): Apparently safari and firefox let you do this in one * go using ranges, which could be a lot faster than iterating manually. * Create a deferred binding implementation. * @param parent * @param from * @param toExcl * @param refChild */ public static void moveNodes(Element parent, Node from, Node toExcl, Node refChild) { for (Node n = from; n != toExcl; ) { Node m = n; n = n.getNextSibling(); parent.insertBefore(m, refChild); } }