Search in sources :

Example 11 with SpanElement

use of elemental.html.SpanElement in project flow by vaadin.

the class ResourceLoader method inlineHtml.

/**
 * Inlines an HTML import and notify a listener when the HTML import is
 * loaded. Calling this method when the HTML import is currently loading or
 * already loaded doesn't cause the HTML import to be loaded again, but the
 * listener will still be notified when appropriate.
 *
 * @param htmlContents
 *            the html contents to inline
 * @param resourceLoadListener
 *            listener to notify when the HTML import is loaded
 */
public void inlineHtml(String htmlContents, final ResourceLoadListener resourceLoadListener) {
    ResourceLoadEvent event = new ResourceLoadEvent(this, htmlContents);
    if (loadedResources.has(htmlContents)) {
        if (resourceLoadListener != null) {
            resourceLoadListener.onLoad(event);
        }
        return;
    }
    if (addListener(htmlContents, resourceLoadListener, loadListeners)) {
        SpanElement spanElement = getDocument().createSpanElement();
        spanElement.setInnerHTML(htmlContents);
        spanElement.setAttribute("hidden", "true");
        HtmlLoadListener listener = new HtmlLoadListener(event);
        getDocument().appendChild(spanElement);
        addOnloadHandler(spanElement, listener, event);
        if (supportsHtmlWhenReady) {
            addHtmlImportsReadyHandler(listener);
        }
    }
}
Also used : SpanElement(elemental.html.SpanElement)

Example 12 with SpanElement

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

the class ContentAssistWidget method createProposalPopupItem.

/**
     * Creates a new proposal item.
     *
     * @param index
     *         of proposal
     */
private Element createProposalPopupItem(int index) {
    final CompletionProposal proposal = proposals.get(index);
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    element.setId(Integer.toString(index));
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    element.setTabIndex(1);
    final EventListener validateListener = evt -> applyProposal(proposal);
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    element.addEventListener(Event.CLICK, event -> select(element), false);
    element.addEventListener(Event.FOCUS, this, false);
    element.addEventListener(DOCUMENTATION, new EventListener() {

        @Override
        public void handleEvent(Event event) {
            proposal.getAdditionalProposalInfo(new AsyncCallback<Widget>() {

                @Override
                public void onSuccess(Widget info) {
                    if (info != null) {
                        docPopup.clear();
                        docPopup.add(info);
                        docPopup.getElement().getStyle().setOpacity(1);
                        if (!docPopup.isAttached()) {
                            final int x = popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3;
                            final int y = popupElement.getOffsetTop();
                            RootPanel.get().add(docPopup);
                            updateMenuPosition(docPopup, x, y);
                        }
                    } else {
                        docPopup.getElement().getStyle().setOpacity(0);
                    }
                }

                @Override
                public void onFailure(Throwable e) {
                    Log.error(getClass(), e);
                    docPopup.getElement().getStyle().setOpacity(0);
                }
            });
        }
    }, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) OrionKeyModeOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionKeyModeOverlay) CustomEvent(elemental.events.CustomEvent) HTMLCollection(elemental.html.HTMLCollection) Elements(org.eclipse.che.ide.util.dom.Elements) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) OrionTextViewOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay) Assisted(com.google.inject.assistedinject.Assisted) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Style(com.google.gwt.dom.client.Style) Node(elemental.dom.Node) Element(elemental.dom.Element) AssistedInject(com.google.inject.assistedinject.AssistedInject) EventListener(elemental.events.EventListener) Window(elemental.html.Window) PopupResources(org.eclipse.che.ide.ui.popup.PopupResources) Event(elemental.events.Event) PX(elemental.css.CSSStyleDeclaration.Unit.PX) KeyboardEvent(elemental.events.KeyboardEvent) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) CompletionRequestEvent(org.eclipse.che.ide.api.editor.events.CompletionRequestEvent) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) RootPanel(com.google.gwt.user.client.ui.RootPanel) Log(org.eclipse.che.ide.util.loging.Log) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Scheduler(com.google.gwt.core.client.Scheduler) Widget(com.google.gwt.user.client.ui.Widget) CompletionProposalExtension(org.eclipse.che.ide.api.editor.codeassist.CompletionProposalExtension) List(java.util.List) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) OrionPixelPositionOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionPixelPositionOverlay) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) SpanElement(elemental.html.SpanElement) OrionModelChangedEventOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionModelChangedEventOverlay) Timer(com.google.gwt.user.client.Timer) EventTarget(elemental.events.EventTarget) MouseEvent(elemental.events.MouseEvent) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Widget(com.google.gwt.user.client.ui.Widget) CustomEvent(elemental.events.CustomEvent) Event(elemental.events.Event) KeyboardEvent(elemental.events.KeyboardEvent) CompletionRequestEvent(org.eclipse.che.ide.api.editor.events.CompletionRequestEvent) MouseEvent(elemental.events.MouseEvent) EventListener(elemental.events.EventListener)

Example 13 with SpanElement

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

the class ProcessTreeRenderer method createMachineElement.

private SpanElement createMachineElement(final ProcessTreeNode node) {
    final MachineEntity machine = (MachineEntity) node.getData();
    final String machineId = machine.getId();
    final MachineConfig machineConfig = machine.getConfig();
    final String machineCategory = machineConfig.isDev() ? locale.devMachineCategory() : machineConfig.getType();
    SpanElement root = Elements.createSpanElement();
    root.appendChild(createMachineLabel(machineCategory));
    Element statusElement = Elements.createSpanElement(resources.getCss().machineStatus());
    root.appendChild(statusElement);
    if (node.isRunning()) {
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusRunning()));
    } else {
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedLeft()));
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedRight()));
    }
    Tooltip.create(statusElement, BOTTOM, MIDDLE, locale.viewMachineRunningTooltip());
    /***************************************************************************
         *
         * New terminal button
         *
         ***************************************************************************/
    if (node.isRunning() && node.hasTerminalAgent()) {
        SpanElement newTerminalButton = Elements.createSpanElement(resources.getCss().newTerminalButton());
        newTerminalButton.appendChild((Node) new SVGImage(resources.addTerminalIcon()).getElement());
        root.appendChild(newTerminalButton);
        Tooltip.create(newTerminalButton, BOTTOM, MIDDLE, locale.viewNewTerminalTooltip());
        newTerminalButton.addEventListener(Event.CLICK, new EventListener() {

            @Override
            public void handleEvent(Event event) {
                event.stopPropagation();
                event.preventDefault();
                if (addTerminalClickHandler != null) {
                    addTerminalClickHandler.onAddTerminalClick(machineId);
                }
            }
        }, true);
        /**
             * This listener cancels mouse events on '+' button and prevents the jitter of the selection in the tree.
             */
        EventListener blockMouseListener = new EventListener() {

            @Override
            public void handleEvent(Event event) {
                event.stopPropagation();
                event.preventDefault();
            }
        };
        /**
             * Prevent jitter when pressing mouse on '+' button.
             */
        newTerminalButton.addEventListener(Event.MOUSEDOWN, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.MOUSEUP, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.CLICK, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.DBLCLICK, blockMouseListener, true);
    }
    /***************************************************************************
         *
         * SSH button
         *
         ***************************************************************************/
    if (node.isRunning() && node.hasSSHAgent()) {
        SpanElement sshButton = Elements.createSpanElement(resources.getCss().sshButton());
        sshButton.setTextContent("SSH");
        root.appendChild(sshButton);
        sshButton.addEventListener(Event.CLICK, new EventListener() {

            @Override
            public void handleEvent(Event event) {
                if (previewSshClickHandler != null) {
                    previewSshClickHandler.onPreviewSshClick(machineId);
                }
            }
        }, true);
        Tooltip.create(sshButton, BOTTOM, MIDDLE, locale.connectViaSSH());
    }
    Element monitorsElement = Elements.createSpanElement(resources.getCss().machineMonitors());
    root.appendChild(monitorsElement);
    Node monitorNode = (Node) machineMonitors.getMonitorWidget(machineId, this).getElement();
    monitorsElement.appendChild(monitorNode);
    Element nameElement = Elements.createSpanElement(resources.getCss().nameLabel());
    nameElement.setTextContent(machineConfig.getName());
    Tooltip.create(nameElement, BOTTOM, MIDDLE, machineConfig.getName());
    root.appendChild(nameElement);
    return root;
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) SpanElement(elemental.html.SpanElement) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) DivElement(elemental.html.DivElement) TreeNodeElement(org.eclipse.che.ide.ui.tree.TreeNodeElement) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) Event(elemental.events.Event) EventListener(elemental.events.EventListener) SVGImage(org.vectomatic.dom.svg.ui.SVGImage)

Example 14 with SpanElement

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

the class MachineTreeRenderer method renderNodeContents.

@Override
public SpanElement renderNodeContents(MachineTreeNode data) {
    SpanElement root = Elements.createSpanElement();
    Element nodeName = Elements.createSpanElement();
    nodeName.setTextContent(data.getName());
    root.appendChild(nodeName);
    return root;
}
Also used : SpanElement(elemental.html.SpanElement) Element(elemental.dom.Element) TreeNodeElement(org.eclipse.che.ide.ui.tree.TreeNodeElement) SpanElement(elemental.html.SpanElement)

Example 15 with SpanElement

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

the class EmptyEditorsPanel method renderAction.

private Node renderAction(String title, final Action action) {
    final Presentation presentation = presentationFactory.getPresentation(action);
    Element divElement = Elements.createDivElement(style.listElement());
    divElement.addEventListener("click", new EventListener() {

        @Override
        public void handleEvent(Event evt) {
            ActionEvent event = new ActionEvent(presentation, actionManager, perspectiveManagerProvider.get());
            action.actionPerformed(event);
        }
    }, true);
    divElement.getStyle().setCursor("pointer");
    divElement.getStyle().setColor(Style.getOutputLinkColor());
    Element label = Elements.createDivElement(style.actionLabel());
    label.setInnerText(title);
    divElement.appendChild(label);
    String hotKey = KeyMapUtil.getShortcutText(keyBindingAgent.getKeyBinding(actionManager.getId(action)));
    if (hotKey == null) {
        hotKey = "&nbsp;";
    } else {
        hotKey = "<nobr>&nbsp;" + hotKey + "&nbsp;</nobr>";
    }
    SpanElement hotKeyElement = Elements.createSpanElement(style.hotKey());
    hotKeyElement.setInnerHTML(hotKey);
    divElement.appendChild(hotKeyElement);
    return divElement;
}
Also used : SpanElement(elemental.html.SpanElement) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent) Element(elemental.dom.Element) DivElement(com.google.gwt.dom.client.DivElement) LIElement(elemental.html.LIElement) SpanElement(elemental.html.SpanElement) ActionEvent(org.eclipse.che.ide.api.action.ActionEvent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) Event(elemental.events.Event) EventListener(elemental.events.EventListener) Presentation(org.eclipse.che.ide.api.action.Presentation)

Aggregations

SpanElement (elemental.html.SpanElement)21 Element (elemental.dom.Element)7 Event (elemental.events.Event)6 EventListener (elemental.events.EventListener)6 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)5 DivElement (elemental.html.DivElement)4 TreeNodeElement (org.eclipse.che.ide.ui.tree.TreeNodeElement)4 Node (elemental.dom.Node)3 CustomEvent (elemental.events.CustomEvent)2 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)2 CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)2 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)2 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)2 Scheduler (com.google.gwt.core.client.Scheduler)1 DivElement (com.google.gwt.dom.client.DivElement)1 Style (com.google.gwt.dom.client.Style)1 KeyCodes (com.google.gwt.event.dom.client.KeyCodes)1 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 Timer (com.google.gwt.user.client.Timer)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1