Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml.

Prototype

public SafeHtml toSafeHtml() 

Source Link

Document

Returns the safe HTML accumulated in the builder as a SafeHtml .

Usage

From source file:org.sagebionetworks.web.client.widget.licenseddownloader.LicensedDownloaderViewImpl.java

License:Open Source License

@Override
public void setDownloadLocations(List<LocationData> locations, String md5) {
    if (locations != null && locations.size() > 0) {
        // build a list of links in HTML
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        String displayString = "Download"; // TODO : add display to LocationData
        for (int i = 0; i < locations.size(); i++) {
            LocationData dl = locations.get(i);
            sb.appendHtmlConstant("<a href=\"" + dl.getPath() + "\" target=\"new\">")
                    .appendEscaped(displayString)
                    .appendHtmlConstant("</a> " + AbstractImagePrototype.create(icons.external16()).getHTML());
            if (md5 != null) {
                sb.appendHtmlConstant("&nbsp;<small>md5 checksum: ").appendEscaped(md5)
                        .appendHtmlConstant("</small>");
            }//w  w  w.j ava2  s.  c o  m
            sb.appendHtmlConstant("<br/>");
        }
        safeDownloadHtml = sb.toSafeHtml();

        // replace the view content if this is after initialization
        if (downloadContentContainer != null) {
            safeDownloadHtml = sb.toSafeHtml();
            fillDownloadContentContainer();
        }
    } else {
        setNoDownloads();
    }
}

From source file:org.sigmah.offline.sync.Synchronizer.java

License:Open Source License

/**
 * Display an error message built from the returned errors.
 * // w ww  . j ava 2 s  .  com
 * @param result 
 *          Result of a synchronization.
 */
private void displayErrorNotification(final SynchronizeResult result) {

    final SafeHtmlBuilder errorBuilder = new SafeHtmlBuilder();

    for (final Map.Entry<ContainerInformation, List<String>> entry : result.getErrors().entrySet()) {
        final ContainerInformation information = entry.getKey();

        if (information.isProject()) {
            errorBuilder.appendHtmlConstant(I18N.CONSTANTS.project());
        } else {
            errorBuilder.appendHtmlConstant(I18N.CONSTANTS.orgunit());
        }

        errorBuilder.appendHtmlConstant(" ").appendEscaped(information.getName()).appendHtmlConstant(" - ")
                .appendEscaped(information.getFullName())
                .appendHtmlConstant("<ul style=\"margin:0.5em 0 1em 1.5em;list-style:disc\">");

        for (final String error : entry.getValue()) {
            errorBuilder.appendHtmlConstant("<li>").appendEscapedLines(error).appendHtmlConstant("</li>");
        }
        errorBuilder.appendHtmlConstant("</ul>");
    }

    if (result.isErrorConcernFiles()) {
        errorBuilder.appendHtmlConstant(I18N.MESSAGES.conflictFiles());
    }

    errorBuilder.appendHtmlConstant(I18N.MESSAGES.conflictSentByMail());

    N10N.error(errorBuilder.toSafeHtml().asString());
}

From source file:org.sigmah.offline.view.OfflineMenuPanel.java

License:Open Source License

private InlineHTML createHeader(String header, String statusLabel) {
    final SafeHtmlBuilder htmlBuilder = new SafeHtmlBuilder().appendHtmlConstant("<h1>").appendEscaped(header)
            .appendHtmlConstant("</h1>");

    if (statusLabel != null) {
        htmlBuilder.appendHtmlConstant("<span style=\"margin-left: 2em; font-style: italic\">")
                .appendEscaped(statusLabel).appendHtmlConstant("</span>");
    }// ww w.j  a  v a  2s  .com

    return new InlineHTML(htmlBuilder.toSafeHtml());
}

From source file:org.sigmah.shared.dispatch.FunctionalException.java

License:Open Source License

/**
 * Returns the functional exception message.
 * Method {@link FunctionalException#getParameter(int)} can be used to populate message dynamic parameters.
 * /*from  w w  w  . j  a  v a  2s .  c  o  m*/
 * @param exception
 *          The functional exception that may embed message parameter(s).
 * @param errorCode
 *          Functional error code (cannot be {@code null}).
 * @return the functional exception message.
 */
private static String getMessage(final FunctionalException exception, final ErrorCode errorCode) {
    switch (errorCode) {

    case AUTHENTICATION_FAILURE:
        return I18N.CONSTANTS.loginConnectErrorBadLogin();

    case ADMIN_MOVE_ORG_UNIT_ITSELF_AS_PARENT:
        return I18N.CONSTANTS.adminOrgUnitMoveErrorItself();

    case ADMIN_MOVE_ORG_UNIT_CYCLE_DETECTED:
        return I18N.CONSTANTS.adminOrgUnitMoveErrorCycle();

    case ADMIN_REMOVE_ORG_UNIT_HAS_CHILDREN:
        return I18N.CONSTANTS.adminOrgUnitRemoveHasChildren();

    case ADMIN_REMOVE_ORG_UNIT_HAS_PROJECTS:
        return I18N.CONSTANTS.adminOrgUnitRemoveHasProjects();

    case ADMIN_REMOVE_ORG_UNIT_IS_ROOT:
        return I18N.CONSTANTS.adminOrgUnitRemoveIsRoot();

    case ADMIN_USER_DUPLICATE_EMAIL:
        return I18N.MESSAGES.existingEmailAddress(exception.getParameter(0));

    case ADMIN_BACKUP_ARCHIVE_CREATION_FAILED:
        return I18N.MESSAGES.adminBackupArchiveCreationFailed(exception.getParameter(0));

    case UPDATE_CONFLICT:
        final SafeHtmlBuilder ulBuilder = new SafeHtmlBuilder();
        ulBuilder.appendHtmlConstant("<ul class=\"" + N10N.CSS_LIST + "\">");
        for (final String error : exception.parameters) {
            ulBuilder.appendHtmlConstant("<li>").appendEscapedLines(error).appendHtmlConstant("</li>");
        }
        ulBuilder.appendHtmlConstant("</ul>");
        return I18N.MESSAGES.conflictError(ulBuilder.toSafeHtml().asString());

    case IMPORTATION_SCHEME_IS_LINKED:
        return I18N.MESSAGES.adminImportationSchemesWarnModelsLinked(exception.getParameter(0));

    case IMPORT_INVALID_COLUMN_REFERENCE:
        return I18N.MESSAGES.importInvalidColumnReference(exception.getParameter(0));

    default:
        return errorCode.toString();
    }
}

From source file:org.wte4j.examples.showcase.client.generation.GenerateDocumentPanel.java

License:Apache License

private Column<OrderDataDto, SafeHtml> createAddressColumn() {
    return new Column<OrderDataDto, SafeHtml>(new SafeHtmlCell()) {

        @Override//from   w w w .  jav  a  2 s  . co m
        public SafeHtml getValue(OrderDataDto orderData) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendEscapedLines(orderData.getAddress());
            return builder.toSafeHtml();
        }
    };
}

From source file:org.zanata.webtrans.client.ui.ValidationMessagePanelView.java

License:Apache License

@Override
public void updateValidationMessages(Map<ValidationAction, List<String>> messages) {
    if (messages == null || messages.isEmpty()) {
        clear();//from w w w . ja v a2s.com
        return;
    }

    this.displayMessages = messages;

    contents.clear();
    int warningCount = 0;
    int errorCount = 0;

    for (Entry<ValidationAction, List<String>> entry : messages.entrySet()) {
        for (String message : entry.getValue()) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendEscaped(message);

            HTMLPanel liElement = new HTMLPanel("li", builder.toSafeHtml().asString());
            liElement.setTitle(entry.getKey().getId().getDisplayName());

            if (isErrorLocked(entry.getKey().getRules())) {
                liElement.addStyleName("txt--danger");
                errorCount++;
            } else {
                liElement.addStyleName("txt--warning");
                warningCount++;
            }

            contents.add(liElement);
        }
    }

    headerLabel.setText(this.messages.validationNotificationHeading(warningCount, errorCount));
    removeStyleName("is-hidden");
}

From source file:org.zanata.webtrans.client.ui.ValidationWarningPanel.java

License:Open Source License

private void refreshView(Map<ValidationAction, List<String>> errorMessages) {
    translations.clear();/*from  w  w w  . j a v  a2  s  . c om*/
    errorList.clear();
    saveAsFuzzyOpt = false;

    for (String target : targets) {
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.append(TextContentsDisplay.asSyntaxHighlight(Lists.newArrayList(target)).toSafeHtml());
        translations.add(new HTMLPanel("li", builder.toSafeHtml().asString()));
    }

    for (List<String> messages : errorMessages.values()) {
        for (String message : messages) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendEscaped(message);
            errorList.add(new HTMLPanel("li", builder.toSafeHtml().asString()));
        }
    }
}

From source file:py.edu.uca.intercajas.client.menumail.Mailboxes.java

License:Apache License

/**
 * Generates HTML for a tree item with an attached icon.
 * /*from   www  . ja  v  a 2 s.c o m*/
 * @param imageProto the image prototype to use
 * @param title the title of the item
 * @return the resultant HTML
 */
private SafeHtml imageItemHTML(ImageResource imageProto, String title) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(AbstractImagePrototype.create(imageProto).getSafeHtml());
    builder.appendHtmlConstant(" ");
    builder.appendEscaped(title);
    return builder.toSafeHtml();
}

From source file:stroom.alert.client.view.CommonAlertViewImpl.java

License:Apache License

@Override
public void setDetail(final SafeHtml html) {
    if (html != null && html.asString().length() > 0) {
        final SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant(//from w  w  w  .  ja va 2  s  .c  o  m
                "<div style=\"font-family: Courier New; font-size: 10px; white-space: pre;\">");
        builder.append(html);
        builder.appendHtmlConstant("</div>");
        detail.setHTML(builder.toSafeHtml());
        showDetail(false);
    } else {
        showHideDetail.setVisible(false);
        setDetailVisible(false);
    }
}

From source file:stroom.cell.dropdowntree.client.DropDownCell.java

License:Apache License

@Override
public void setValue(final Context context, final Element parent, final E value) {
    final SafeHtmlBuilder sb = new SafeHtmlBuilder();
    render(context, value, sb);/*w  w w.j a  va 2s.c  o  m*/
    if (parent != null) {
        parent.setInnerHTML(sb.toSafeHtml().asString());
    }
}