Search in sources :

Example 1 with HTMLCollection

use of elemental.html.HTMLCollection in project che by eclipse.

the class ContentAssistWidget method update.

private void update() {
    int topVisibleItem = popupBodyElement.getScrollTop() / getItemHeight();
    int topDOMItem = Math.max(0, topVisibleItem - (DOM_ITEMS_SIZE - getItemsPerPage()) / 2);
    int bottomDOMItem = Math.min(getTotalItems() - 1, topDOMItem + DOM_ITEMS_SIZE - 1);
    if (bottomDOMItem == getTotalItems() - 1) {
        topDOMItem = Math.max(0, bottomDOMItem - DOM_ITEMS_SIZE + 1);
    }
    // resize the extra top row
    setExtraRowHeight(getExtraTopRow(), topDOMItem);
    // replace the DOM items with new content based on the scroll position
    HTMLCollection nodes = listElement.getChildren();
    for (int i = 0; i <= (bottomDOMItem - topDOMItem); i++) {
        Element newNode = createProposalPopupItem(topDOMItem + i);
        listElement.replaceChild(newNode, nodes.item(i + 1));
        // check if the item is the selected
        if (newNode.getId().equals(selectedElement.getId())) {
            selectedElement = newNode;
            selectedElement.setAttribute("selected", "true");
        }
    }
    // resize the extra bottom row
    setExtraRowHeight(getExtraBottomRow(), getTotalItems() - (bottomDOMItem + 1));
    // ensure the keyboard focus is in the visible area
    if (focused) {
        getItem(topDOMItem + (bottomDOMItem - topDOMItem) / 2).focus();
    }
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement)

Example 2 with HTMLCollection

use of elemental.html.HTMLCollection in project che by eclipse.

the class AnnotationGroupImpl method getMessages.

@Override
public List<String> getMessages() {
    final List<String> result = new ArrayList<>();
    final HTMLCollection children = asElemental().getChildren();
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            final String message = getMessage(dataset);
            if (message != null) {
                result.add(message);
            }
        }
    }
    return result;
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Mappable(elemental.util.Mappable) Node(elemental.dom.Node) DivElement(elemental.html.DivElement) Element(elemental.dom.Element) ArrayList(java.util.ArrayList) Element(elemental.dom.Element)

Example 3 with HTMLCollection

use of elemental.html.HTMLCollection in project che by eclipse.

the class AnnotationGroupImpl method removeAnnotation.

@Override
public final void removeAnnotation(final Annotation annotation, int offset) {
    final HTMLCollection children = asElemental().getChildren();
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            if (compareStrings(getMessage(dataset), annotation.getText()) && getOffset(dataset) == offset && getLayer(dataset) == annotation.getLayer() && compareStrings(getType(dataset), annotation.getType())) {
                // we may not strictly be on the same annotation instance, but it is not discernible
                asElemental().removeChild(element);
                updateIconVisibility();
                break;
            }
        }
    }
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Mappable(elemental.util.Mappable) Node(elemental.dom.Node) DivElement(elemental.html.DivElement) Element(elemental.dom.Element) Element(elemental.dom.Element)

Example 4 with HTMLCollection

use of elemental.html.HTMLCollection in project che by eclipse.

the class AnnotationGroupImpl method updateIconVisibility.

private void updateIconVisibility() {
    int maxLayer = 0;
    final HTMLCollection children = asElemental().getChildren();
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            final int layer = getLayer(dataset);
            if (maxLayer < layer) {
                maxLayer = layer;
            }
        }
    }
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            final int layer = getLayer(dataset);
            if (layer >= maxLayer) {
                element.getStyle().removeProperty("display");
            } else {
                element.getStyle().setDisplay("none");
            }
        }
    }
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Mappable(elemental.util.Mappable) Node(elemental.dom.Node) DivElement(elemental.html.DivElement) Element(elemental.dom.Element) Element(elemental.dom.Element)

Aggregations

Element (elemental.dom.Element)4 HTMLCollection (elemental.html.HTMLCollection)4 Node (elemental.dom.Node)3 DivElement (elemental.html.DivElement)3 Mappable (elemental.util.Mappable)3 SpanElement (elemental.html.SpanElement)1 ArrayList (java.util.ArrayList)1