public static void removeFromParent(Element item) { Element parent = item.getParentElement(); if (parent != null) { parent.removeChild(item); } }
/** * Returns current selected element when we have an item in focus or {@code null} otherwise * * @return current selected element or {@code null} when we have no any items in focus */ @Nullable private Element getSelectedElement() { Element selectedElement = Elements.getDocument().getActiveElement(); return selectedElement.getParentElement().isEqualNode(listElement) ? selectedElement : null; } }
/** Activates the currently selected item. */ private void validateItem() { final Element current = Elements.getDocument().getActiveElement(); if (current.getParentElement().isEqualNode(listElement)) { this.popupWidget.validateItem(current); } }
/** * Focus the next item in the list, or the first item if we are already at the last. In the case * the list doesn't currently have focus, focus the first element. */ private void focusNext() { final Element current = Elements.getDocument().getActiveElement(); if (current.getParentElement().isEqualNode(listElement)) { final Element next = current.getNextElementSibling(); if (next != null) { select(next); next.focus(); } else { focusFirst(); } } else { // we don't actually have focus, focus the first element focusFirst(); } }
/** * Focus the previous item in the list, or the last item if we are already at the first. In the * case the list doesn't currently have focus, focus the first element. */ private void focusPrevious() { final Element current = Elements.getDocument().getActiveElement(); if (current.getParentElement().isEqualNode(listElement)) { final Element prev = current.getPreviousElementSibling(); if (prev != null) { select(prev); prev.focus(); } else { focusLast(); } } else { // we don't actually have focus, focus the first element focusFirst(); } }