Search in sources :

Example 1 with AnchorElement

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

the class ClassFileSourcesDownloader method onEditorOpened.

@Override
public void onEditorOpened(EditorOpenedEvent event) {
    EditorPartPresenter editor = event.getEditor();
    VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof JarFileNode) {
        final JarFileNode jarFileNode = (JarFileNode) file;
        if (jarFileNode.isContentGenerated()) {
            if (editor instanceof TextEditor) {
                final TextEditor presenter = (TextEditor) editor;
                TextEditorPartView view = presenter.getView();
                final DivElement divElement = Elements.createDivElement();
                divElement.setClassName(resources.css().editorInfoPanel());
                Text textNode = Elements.createTextNode(constant.mavenClassDecompiled());
                DivElement decompiledElement = Elements.createDivElement();
                decompiledElement.appendChild(textNode);
                decompiledElement.setClassName(resources.css().editorMessage());
                divElement.appendChild(decompiledElement);
                AnchorElement anchorElement = Elements.createAnchorElement();
                anchorElement.appendChild(Elements.createTextNode(constant.mavenDownloadSources()));
                anchorElement.setHref("#");
                anchorElement.setClassName(resources.css().downloadLink());
                divElement.appendChild(anchorElement);
                final HasNotificationPanel.NotificationRemover remover = view.addNotification((Element) divElement);
                anchorElement.setOnclick(new EventListener() {

                    @Override
                    public void handleEvent(Event evt) {
                        downloadSources(jarFileNode, remover);
                    }
                });
            }
        }
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) AnchorElement(elemental.html.AnchorElement) Text(elemental.dom.Text) HasNotificationPanel(org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) TextEditorPartView(org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView) DivElement(elemental.html.DivElement) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) Event(elemental.events.Event) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EventListener(elemental.events.EventListener)

Example 2 with AnchorElement

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

the class Elements method markupParagraph.

/** Creates a paragraph tag and fills it with spans and anchor tags internally. */
private static void markupParagraph(Element parent, String text, String linkCssClass) {
    if (StringUtils.isNullOrWhitespace(text)) {
        // don't add any dom here
        return;
    }
    ParagraphElement myParagraph = createParagraphElement();
    int index = 0;
    REGEXP_MARKUP.setLastIndex(0);
    SpanElement current = createSpanElement();
    for (MatchResult match = REGEXP_MARKUP.exec(text); match != null; match = REGEXP_MARKUP.exec(text)) {
        current.setTextContent(text.substring(index, match.getIndex()));
        myParagraph.appendChild(current);
        current = createSpanElement();
        /*
       * If our match is a \n we need to create a <br/> element to force a line break, otherwise we
       * matched an http/www link so let's make an anchor tag out of it.
       */
        if (match.getGroup(0).equals("\n")) {
            myParagraph.appendChild(createBRElement());
        } else {
            AnchorElement anchor = createAnchorElement(linkCssClass);
            anchor.setHref(match.getGroup(0));
            anchor.setTarget("_blank");
            anchor.setTextContent(match.getGroup(0));
            myParagraph.appendChild(anchor);
        }
        index = match.getIndex() + match.getGroup(0).length();
    }
    current.setTextContent(text.substring(index));
    myParagraph.appendChild(current);
    parent.appendChild(myParagraph);
}
Also used : SpanElement(elemental.html.SpanElement) ParagraphElement(elemental.html.ParagraphElement) AnchorElement(elemental.html.AnchorElement) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 3 with AnchorElement

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

the class Elements method createAnchorElement.

public static AnchorElement createAnchorElement(String... classNames) {
    AnchorElement elem = getDocument().createAnchorElement();
    addClassesToElement(elem, classNames);
    return elem;
}
Also used : AnchorElement(elemental.html.AnchorElement)

Aggregations

AnchorElement (elemental.html.AnchorElement)3 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 Text (elemental.dom.Text)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 DivElement (elemental.html.DivElement)1 ParagraphElement (elemental.html.ParagraphElement)1 SpanElement (elemental.html.SpanElement)1 EditorOpenedEvent (org.eclipse.che.ide.api.editor.EditorOpenedEvent)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 HasNotificationPanel (org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 TextEditorPartView (org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView)1 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)1