Example usage for com.vaadin.client WidgetUtil sinkOnloadForImages

List of usage examples for com.vaadin.client WidgetUtil sinkOnloadForImages

Introduction

In this page you can find the example usage for com.vaadin.client WidgetUtil sinkOnloadForImages.

Prototype

public static void sinkOnloadForImages(Element element) 

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.label.CubaLabelConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    // CAUTION copied from superclass
    super.onStateChanged(stateChangeEvent);
    boolean sinkOnloads = false;
    Profiler.enter("LabelConnector.onStateChanged update content");
    switch (getState().contentMode) {
    case PREFORMATTED:
        PreElement preElement = Document.get().createPreElement();
        preElement.setInnerText(getState().text);
        // clear existing content
        getWidget().setHTML("");
        // add preformatted text to dom
        getWidget().getElement().appendChild(preElement);
        break;//from w ww  . ja v  a2s  .c  o  m

    case TEXT:
        // clear existing content
        getWidget().setHTML("");
        // set multiline text if needed
        // Haulmont API
        String text = getState().text;
        if (text != null && text.contains("\n")) {
            text = WidgetUtil.escapeHTML(text).replace("\n", "<br/>");
            getWidget().setHTML(text);
        } else {
            getWidget().setText(text);
        }
        break;

    case HTML:
    case RAW:
        sinkOnloads = true;
    case XML:
        getWidget().setHTML(getState().text);
        break;
    default:
        getWidget().setText("");
        break;
    }

    // Haulmont API
    if ("".equals(getWidget().getText()) || getWidget().getText() == null) {
        getWidget().addStyleDependentName("empty");
    } else {
        getWidget().removeStyleDependentName("empty");
    }

    updateIcon();

    Profiler.leave("LabelConnector.onStateChanged update content");

    if (sinkOnloads) {
        Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
        WidgetUtil.sinkOnloadForImages(getWidget().getElement());
        Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
    }
}

From source file:com.haulmont.cuba.web.widgets.client.label.CubaLabelConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    // CAUTION copied from superclass
    // todo rework! extract extenstion points
    super.onStateChanged(stateChangeEvent);

    boolean sinkOnloads = false;
    Profiler.enter("LabelConnector.onStateChanged update content");
    VLabel widget = getWidget();/*from  ww w  .j  a  va  2s. co  m*/
    switch (getState().contentMode) {
    case PREFORMATTED:
        PreElement preElement = Document.get().createPreElement();
        preElement.setInnerText(getState().text);
        // clear existing content
        widget.setHTML("");
        // add preformatted text to dom
        widget.getElement().appendChild(preElement);
        break;

    case TEXT:
        // clear existing content
        widget.setHTML("");
        // set multiline text if needed
        // Haulmont API
        String text = getState().text;
        if (text != null && text.contains("\n")) {
            text = WidgetUtil.escapeHTML(text).replace("\n", "<br/>");
            widget.setHTML(text);
        } else {
            widget.setText(text);
        }
        break;

    case HTML:
        sinkOnloads = true;
        widget.setHTML(getState().text);
        break;
    }

    // Haulmont API
    if ("".equals(getWidget().getText()) || getWidget().getText() == null) {
        getWidget().addStyleDependentName("empty");
    } else {
        getWidget().removeStyleDependentName("empty");
    }

    updateIcon();

    Profiler.leave("LabelConnector.onStateChanged update content");

    if (sinkOnloads) {
        Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
        WidgetUtil.sinkOnloadForImages(widget.getElement());
        Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
    }
}

From source file:org.eclipse.hawkbit.ui.filtermanagement.client.SuggestionsSelectList.java

License:Open Source License

/**
 * Adds suggestions to the suggestion menu bar.
 * //from   w  ww .  j a  v a  2  s.  co m
 * @param suggestions
 *            the suggestions to be added
 * @param textFieldWidget
 *            the text field which the suggestion is attached to to bring
 *            back the focus after selection
 * @param popupPanel
 *            pop-up panel where the menu bar is shown to hide it after
 *            selection
 * @param suggestionServerRpc
 *            server RPC to ask for new suggestion after a selection
 */
public void addItems(final List<SuggestTokenDto> suggestions, final VTextField textFieldWidget,
        final PopupPanel popupPanel, final TextFieldSuggestionBoxServerRpc suggestionServerRpc) {
    for (int index = 0; index < suggestions.size(); index++) {
        final SuggestTokenDto suggestToken = suggestions.get(index);
        final MenuItem mi = new MenuItem(suggestToken.getSuggestion(), true, new ScheduledCommand() {
            @Override
            public void execute() {
                final String tmpSuggestion = suggestToken.getSuggestion();
                final TokenStartEnd tokenStartEnd = tokenMap.get(tmpSuggestion);
                final String text = textFieldWidget.getValue();
                final StringBuilder builder = new StringBuilder(text);
                builder.replace(tokenStartEnd.getStart(), tokenStartEnd.getEnd() + 1, tmpSuggestion);
                textFieldWidget.setValue(builder.toString(), true);
                popupPanel.hide();
                textFieldWidget.setFocus(true);
                suggestionServerRpc.suggest(builder.toString(), textFieldWidget.getCursorPos());
            }
        });
        tokenMap.put(suggestToken.getSuggestion(),
                new TokenStartEnd(suggestToken.getStart(), suggestToken.getEnd()));
        Roles.getListitemRole().set(mi.getElement());
        WidgetUtil.sinkOnloadForImages(mi.getElement());
        addItem(mi);
    }
}

From source file:org.jpos.client.ui.XLabelConnector.java

License:Open Source License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);
    boolean sinkOnloads = false;
    Profiler.enter("LabelConnector.onStateChanged update content");
    switch (getState().contentMode) {
    case PREFORMATTED:
        Document doc = Document.get();
        Element e = getWidget().getElement();
        PreElement preElement = doc.createPreElement();
        preElement.setInnerText(getState().text);
        // DO NOT clear existing content
        // getWidget().setHTML("");
        // add preformatted text to dom
        e.appendChild(preElement);/*from  w w  w  .j a va  2  s  .  c  o m*/
        // e.appendChild(doc.createHRElement());
        break;
    case TEXT:
        getWidget().setText(getState().text);
        break;
    case HTML:
    case RAW:
        sinkOnloads = true;
    case XML:
        getWidget().setHTML(getState().text);
        break;
    default:
        getWidget().setText("");
        break;

    }
    Profiler.leave("LabelConnector.onStateChanged update content");

    if (sinkOnloads) {
        Profiler.enter("LabelConnector.onStateChanged sinkOnloads");
        WidgetUtil.sinkOnloadForImages(getWidget().getElement());
        Profiler.leave("LabelConnector.onStateChanged sinkOnloads");
    }
}