Search in sources :

Example 11 with Element

use of elemental.dom.Element in project che by eclipse.

the class ContentAssistWidget method show.

/**
     * Displays assist popup relative to the current cursor position.
     *
     * @param proposals
     *         proposals to display
     */
public void show(final List<CompletionProposal> proposals) {
    this.proposals = proposals;
    OrionTextViewOverlay textView = textEditor.getTextView();
    OrionPixelPositionOverlay caretLocation = textView.getLocationAtOffset(textView.getCaretOffset());
    caretLocation.setY(caretLocation.getY() + textView.getLineHeight());
    caretLocation = textView.convert(caretLocation, "document", "page");
    /** The fastest way to remove element children. Clear and add items. */
    listElement.setInnerHTML("");
    /* Display an empty popup when it is nothing to show. */
    if (getTotalItems() == 0) {
        final Element emptyElement = Elements.createLiElement(popupResources.popupStyle().item());
        emptyElement.setTextContent("No proposals");
        listElement.appendChild(emptyElement);
        return;
    }
    /* Automatically apply the completion proposal if it only one. */
    if (getTotalItems() == 1) {
        applyProposal(proposals.get(0));
        return;
    }
    /* Reset popup dimensions and show. */
    popupElement.getStyle().setLeft(caretLocation.getX(), PX);
    popupElement.getStyle().setTop(caretLocation.getY(), PX);
    popupElement.getStyle().setWidth("400px");
    popupElement.getStyle().setHeight("200px");
    popupElement.getStyle().setOpacity(1);
    Elements.getDocument().getBody().appendChild(this.popupElement);
    /* Add the top extra row. */
    setExtraRowHeight(appendExtraRow(), 0);
    /* Add the popup items. */
    for (int i = 0; i < Math.min(DOM_ITEMS_SIZE, getTotalItems()); i++) {
        listElement.appendChild(createProposalPopupItem(i));
    }
    /* Add the bottom extra row. */
    setExtraRowHeight(appendExtraRow(), Math.max(0, getTotalItems() - DOM_ITEMS_SIZE));
    /* Correct popup position (wants to be refactored) */
    final Window window = Elements.getWindow();
    final int viewportWidth = window.getInnerWidth();
    final int viewportHeight = window.getInnerHeight();
    int spaceBelow = viewportHeight - caretLocation.getY();
    if (this.popupElement.getOffsetHeight() > spaceBelow) {
        // Check if div is too large to fit above
        int spaceAbove = caretLocation.getY() - textView.getLineHeight();
        if (this.popupElement.getOffsetHeight() > spaceAbove) {
            // Squeeze the div into the larger area
            if (spaceBelow > spaceAbove) {
                this.popupElement.getStyle().setProperty("maxHeight", spaceBelow + "px");
            } else {
                this.popupElement.getStyle().setProperty("maxHeight", spaceAbove + "px");
                this.popupElement.getStyle().setTop("0");
            }
        } else {
            // Put the div above the line
            this.popupElement.getStyle().setTop((caretLocation.getY() - this.popupElement.getOffsetHeight() - textView.getLineHeight()) + "px");
            this.popupElement.getStyle().setProperty("maxHeight", spaceAbove + "px");
        }
    } else {
        this.popupElement.getStyle().setProperty("maxHeight", spaceBelow + "px");
    }
    if (caretLocation.getX() + this.popupElement.getOffsetWidth() > viewportWidth) {
        int leftSide = viewportWidth - this.popupElement.getOffsetWidth();
        if (leftSide < 0) {
            leftSide = 0;
        }
        this.popupElement.getStyle().setLeft(leftSide + "px");
        this.popupElement.getStyle().setProperty("maxWidth", (viewportWidth - leftSide) + "px");
    } else {
        this.popupElement.getStyle().setProperty("maxWidth", viewportWidth + caretLocation.getX() + "px");
    }
    /* Don't attach handlers twice. Visible popup must already have their attached. */
    if (!visible) {
        addPopupEventListeners();
    }
    /* Indicates the codeassist is visible. */
    visible = true;
    focused = false;
    /* Update documentation popup position */
    docPopup.getElement().getStyle().setLeft(popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3, Style.Unit.PX);
    docPopup.getElement().getStyle().setTop(popupElement.getOffsetTop(), Style.Unit.PX);
    /* Select first row. */
    selectFirst();
}
Also used : Window(elemental.html.Window) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) OrionTextViewOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay) OrionPixelPositionOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionPixelPositionOverlay)

Example 12 with Element

use of elemental.dom.Element 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 13 with Element

use of elemental.dom.Element in project che by eclipse.

the class TreeNodeElement method openNode.

/**
     * Expands the current node. Must have children if you call this!
     *
     * @param css
     *         The {@link Tree.Css} instance that contains relevant selector
     *         names.
     * @param shouldAnimate
     *         whether to do the animation or not
     */
final void openNode(NodeDataAdapter<D> dataAdapter, Tree.Css css, AnimationController opener, boolean shouldAnimate) {
    ensureChildrenContainer(dataAdapter, css);
    Element expandControl = getExpandControl();
    assert (hasChildrenContainer() && CssUtils.containsClassName(expandControl, css.expandControl())) : "Tried to open a node that didn't have an expand control";
    setOpen(css, true);
    Element childrenContainer = getChildrenContainer();
    if (shouldAnimate) {
        opener.show(childrenContainer);
    } else {
        opener.showWithoutAnimating(childrenContainer);
    }
}
Also used : DivElement(elemental.html.DivElement) Element(elemental.dom.Element) JsLIElement(elemental.js.html.JsLIElement) SpanElement(elemental.html.SpanElement) JsUListElement(elemental.js.html.JsUListElement)

Example 14 with Element

use of elemental.dom.Element in project che by eclipse.

the class TreeNodeElement method closeNode.

/**
     * Closes the current node. Must have children if you call this!
     *
     * @param css
     *         The {@link Tree.Css} instance that contains relevant selector
     *         names.
     * @param shouldAnimate
     *         whether to do the animation or not
     */
final void closeNode(NodeDataAdapter<D> dataAdapter, Tree.Css css, AnimationController closer, boolean shouldAnimate) {
    ensureChildrenContainer(dataAdapter, css);
    Element expandControl = getExpandControl();
    assert (hasChildrenContainer() && CssUtils.containsClassName(expandControl, css.expandControl())) : "Tried to close a node that didn't have an expand control";
    setOpen(css, false);
    Element childrenContainer = getChildrenContainer();
    if (shouldAnimate) {
        closer.hide(childrenContainer);
    } else {
        closer.hideWithoutAnimating(childrenContainer);
    }
}
Also used : DivElement(elemental.html.DivElement) Element(elemental.dom.Element) JsLIElement(elemental.js.html.JsLIElement) SpanElement(elemental.html.SpanElement) JsUListElement(elemental.js.html.JsUListElement)

Example 15 with Element

use of elemental.dom.Element in project che by eclipse.

the class TreeNodeLabelRenamer method mutateNodeKey.

/**
     * Updates the name value for the model object for a node, and then replaces
     * the label's contents with the new value.
     */
public void mutateNodeKey(TreeNodeElement<D> node, String newName) {
    getDataAdapter().setNodeName(node.getData(), newName);
    Element elem = getRenderer().getNodeKeyTextContainer(node.getNodeLabel());
    elem.setTextContent(newName);
}
Also used : Element(elemental.dom.Element)

Aggregations

Element (elemental.dom.Element)48 SpanElement (elemental.html.SpanElement)23 DivElement (elemental.html.DivElement)15 JsElement (elemental.js.dom.JsElement)11 Event (elemental.events.Event)8 EventListener (elemental.events.EventListener)8 Node (elemental.dom.Node)7 HTMLCollection (elemental.html.HTMLCollection)5 LIElement (elemental.html.LIElement)5 TableCellElement (elemental.html.TableCellElement)5 TableElement (elemental.html.TableElement)5 InputElement (elemental.html.InputElement)4 JsLIElement (elemental.js.html.JsLIElement)4 JsUListElement (elemental.js.html.JsUListElement)4 TreeNodeElement (org.eclipse.che.ide.ui.tree.TreeNodeElement)4 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)4 Scheduler (com.google.gwt.core.client.Scheduler)3 CustomEvent (elemental.events.CustomEvent)3 AnchorElement (elemental.html.AnchorElement)3 BRElement (elemental.html.BRElement)3