Search in sources :

Example 6 with Element

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

the class SignatureHelpView method renderParameters.

private void renderParameters(Element parent, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    int end = signatureInfo.getLabel().length();
    int idx;
    Element element;
    for (int i = signatureInfo.getParameters().get().size() - 1; i >= 0; i--) {
        ParameterInfo parameterInfo = signatureInfo.getParameters().get().get(i);
        idx = signatureInfo.getLabel().lastIndexOf(parameterInfo.getLabel(), end);
        int signatureLabelOffset = 0;
        int signatureLabelEnd = 0;
        if (idx >= 0) {
            signatureLabelOffset = idx;
            signatureLabelEnd = idx + parameterInfo.getLabel().length();
        }
        element = Elements.createSpanElement();
        element.setTextContent(signatureInfo.getLabel().substring(signatureLabelEnd, end));
        parent.insertBefore(element, parent.getFirstElementChild());
        element = Elements.createSpanElement(resources.css().parameter());
        if (activeParameter.isPresent() && i == activeParameter.get()) {
            Elements.addClassName(resources.css().active(), element);
        }
        element.setTextContent(signatureInfo.getLabel().substring(signatureLabelOffset, signatureLabelEnd));
        parent.insertBefore(element, parent.getFirstElementChild());
        end = signatureLabelOffset;
    }
    element = Elements.createSpanElement();
    element.setTextContent(signatureInfo.getLabel().substring(0, end));
    parent.insertBefore(element, parent.getFirstElementChild());
}
Also used : Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) ParameterInfo(org.eclipse.che.ide.api.editor.signature.ParameterInfo)

Example 7 with Element

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

the class SignatureHelpView method render.

private void render() {
    if (signatureHelp.getSignatures().size() > 1) {
        Elements.addClassName(resources.css().multiple(), rootElement);
        overloads.getStyle().setDisplay("block");
    } else {
        Elements.removeClassName(resources.css().multiple(), rootElement);
        overloads.getStyle().setDisplay("none");
    }
    signatures.setInnerHTML("");
    signatureViews = new ArrayList<>();
    int height = 0;
    for (SignatureInfo signatureInfo : signatureHelp.getSignatures()) {
        Element signatureElement = renderSignature(signatures, signatureInfo, signatureHelp.getActiveParameter());
        renderDocumentation(signatureElement, signatureInfo, signatureHelp.getActiveParameter());
        int signatureHeight = signatureElement.getOffsetHeight();
        signatureViews.add(Pair.of(height, signatureHeight));
        height += signatureHeight;
    }
}
Also used : SignatureInfo(org.eclipse.che.ide.api.editor.signature.SignatureInfo) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement)

Example 8 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 9 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 10 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)

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