Java Code Examples for com.google.gwt.dom.client.Element#getNextSiblingElement()

The following examples show how to use com.google.gwt.dom.client.Element#getNextSiblingElement() . 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: BlipMetaDomImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Scrapes the menu state from the DOM. The menu state describes what options
 * exist, and which, if any, are currently selected.
 *
 * @return a mapping from available options to their UI objects, and the
 *         subset of those options that are currently selected.
 */
private Pair<EnumMap<MenuOption, BlipMenuItemDomImpl>, EnumSet<MenuOption>> getMenuState() {
  EnumMap<MenuOption, BlipMenuItemDomImpl> options =
      new EnumMap<MenuOption, BlipMenuItemDomImpl>(MenuOption.class);
  EnumSet<MenuOption> selected = EnumSet.noneOf(MenuOption.class);
  Element e = getMenu().getFirstChildElement();
  while (e != null) {
    if (e.hasAttribute(KIND_ATTRIBUTE)
        && e.getAttribute(KIND_ATTRIBUTE).equals(TypeCodes.kind(Type.MENU_ITEM))) {
      BlipMenuItemDomImpl item = BlipMenuItemDomImpl.of(e, css);
      MenuOption option = item.getOption();
      options.put(option, item);
      if (item.isSelected()) {
        selected.add(option);
      }
    }
    e = e.getNextSiblingElement();
  }
  return Pair.of(options, selected);
}
 
Example 2
Source File: BlipMetaDomImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Scrapes the menu state from the DOM. The menu state describes what options
 * exist, and which, if any, are currently selected.
 *
 * @return a mapping from available options to their UI objects, and the
 *         subset of those options that are currently selected.
 */
private Pair<EnumMap<MenuOption, BlipMenuItemDomImpl>, EnumSet<MenuOption>> getMenuState() {
  EnumMap<MenuOption, BlipMenuItemDomImpl> options =
      new EnumMap<MenuOption, BlipMenuItemDomImpl>(MenuOption.class);
  EnumSet<MenuOption> selected = EnumSet.noneOf(MenuOption.class);
  Element e = getMenu().getFirstChildElement();
  while (e != null) {
    if (e.hasAttribute(KIND_ATTRIBUTE)
        && e.getAttribute(KIND_ATTRIBUTE).equals(TypeCodes.kind(Type.MENU_ITEM))) {
      BlipMenuItemDomImpl item = BlipMenuItemDomImpl.of(e, css);
      MenuOption option = item.getOption();
      options.put(option, item);
      if (item.isSelected()) {
        selected.add(option);
      }
    }
    e = e.getNextSiblingElement();
  }
  return Pair.of(options, selected);
}
 
Example 3
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the index of an element in its parent's list of child elements.
 * This is not the same as {@link #findChildIndex(Node)}, since it ignores
 * non-element nodes. It is in line with the element-only view of a collection
 * of children exposed by {@link Element#getFirstChildElement()} and
 * {@link Element#getNextSiblingElement()}.
 *
 * @param child  an element
 * @return the index of {@code child}, or -1 if {@code child} is not a child
 *   of its parent.
 * @see #findChildIndex(Node)
 */
public static final int findChildElementIndex(Element child) {
  Element parent = child.getParentElement();
  Element e = parent.getFirstChildElement();
  int i = 0;
  while (e != null) {
    if (e.equals(child)) {
      return i;
    } else {
      e = e.getNextSiblingElement();
      i++;
    }
  }
  return -1;
}
 
Example 4
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 5
Source File: DomViewHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
public static Element getAfter(Element container, Element ref) {
  Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container));
  if (ref == null) {
    return container.getFirstChildElement();
  } else {
    return ref.getNextSiblingElement();
  }
}
 
Example 6
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the index of an element in its parent's list of child elements.
 * This is not the same as {@link #findChildIndex(Node)}, since it ignores
 * non-element nodes. It is in line with the element-only view of a collection
 * of children exposed by {@link Element#getFirstChildElement()} and
 * {@link Element#getNextSiblingElement()}.
 *
 * @param child  an element
 * @return the index of {@code child}, or -1 if {@code child} is not a child
 *   of its parent.
 * @see #findChildIndex(Node)
 */
public static final int findChildElementIndex(Element child) {
  Element parent = child.getParentElement();
  Element e = parent.getFirstChildElement();
  int i = 0;
  while (e != null) {
    if (e.equals(child)) {
      return i;
    } else {
      e = e.getNextSiblingElement();
      i++;
    }
  }
  return -1;
}
 
Example 7
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 8
Source File: DomViewHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
public static Element getAfter(Element container, Element ref) {
  Preconditions.checkArgument(ref == null || ref.getParentElement().equals(container));
  if (ref == null) {
    return container.getFirstChildElement();
  } else {
    return ref.getNextSiblingElement();
  }
}
 
Example 9
Source File: CellTreeNodeView.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Reload the open children after rendering new items in this node.
 *
 * @param values     the values being replaced
 * @param start      the start index
 * @param savedViews the open nodes
 */
private void loadChildState(List<C> values, int start, Map<Object, CellTreeNodeView<?>> savedViews) {
  int len = values.size();
  int end = start + len;
  int childCount = nodeView.getChildCount();
  int setSize = (childCount > len) ? childCount : end;
  ProvidesKey<C> keyProvider = nodeInfo.getProvidesKey();

  Element container = nodeView.ensureChildContainer();
  Element childElem = (values.size() == 0) ? null : Element.as(container.getChild(start));
  CellTreeNodeView<?> keyboardSelected = nodeView.tree.getKeyboardSelectedNode();
  for (int i = start; i < end; i++) {
    C childValue = values.get(i - start);
    CellTreeNodeView<C> child = nodeView.createTreeNodeView(nodeInfo, childElem, childValue, null);
    CellTreeNodeView<?> savedChild = savedViews.remove(keyProvider.getKey(childValue));
    // Copy the saved child's state into the new child
    if (savedChild != null) {
      child.animationFrame = savedChild.animationFrame;
      child.contentContainer = savedChild.contentContainer;
      child.childContainer = savedChild.childContainer;
      child.children = savedChild.children;
      child.emptyMessageElem = savedChild.emptyMessageElem;
      child.nodeInfo = savedChild.nodeInfo;
      child.nodeInfoLoaded = savedChild.nodeInfoLoaded;
      child.open = savedChild.open;
      child.showMoreElem = savedChild.showMoreElem;

      // Transfer the tree node so that if the user has a handle to it, it
      // won't be destroyed.
      child.treeNode = savedChild.treeNode;
      if (child.treeNode != null) {
        child.treeNode.nodeView = child;
      }

      // Swap the node view in the child. We reuse the same NodeListView
      // so that we don't have to unset and register a new view with the
      // NodeInfo, which would inevitably cause the NodeInfo to push
      // new data.
      child.listView = savedChild.listView;
      if (child.listView != null) {
        child.listView.nodeView = child;
      }

      // Set the new parent of the grandchildren.
      if (child.children != null) {
        for (CellTreeNodeView<?> grandchild : child.children) {
          grandchild.parentNode = child;
        }
      }

      // Transfer the keyboard selected node.
      if (keyboardSelected == savedChild) {
        keyboardSelected = child;
      }

      // Copy the child container element to the new child
      child.getElement().appendChild(savedChild.ensureAnimationFrame());

      // Mark the old child as destroy without actually destroying it.
      savedChild.isDestroyed = true;
    }

    if (childCount > i) {
      nodeView.children.set(i, child);
    }
    else {
      nodeView.children.add(child);
    }
    child.updateAriaAttributes(setSize);
    childElem = childElem.getNextSiblingElement();
  }

  // Move the keyboard selected node if it is this node or a child of this
  // node.
  CellTreeNodeView<?> curNode = keyboardSelected;
  while (curNode != null) {
    if (curNode == nodeView) {
      nodeView.tree.keyboardSelect(keyboardSelected, false);
      break;
    }
    curNode = curNode.parentNode;
  }
}