Search in sources :

Example 1 with ParagraphElement

use of elemental.html.ParagraphElement 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 2 with ParagraphElement

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

the class Elements method createParagraphElement.

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

Aggregations

ParagraphElement (elemental.html.ParagraphElement)2 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 AnchorElement (elemental.html.AnchorElement)1 SpanElement (elemental.html.SpanElement)1