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.roda.wui.client.browse.BitstreamPreview.java

private void notSupportedPreview() {
    HTML html = new HTML();
    SafeHtmlBuilder b = new SafeHtmlBuilder();

    b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-picture-o fa-5'></i>"));
    b.append(SafeHtmlUtils.fromSafeConstant("<h4 class='errormessage'>"));
    b.append(SafeHtmlUtils.fromString(messages.viewRepresentationNotSupportedPreview()));
    b.append(SafeHtmlUtils.fromSafeConstant("</h4>"));

    Button downloadButton = new Button(messages.viewRepresentationDownloadFileButton());
    downloadButton.addClickHandler(new ClickHandler() {

        @Override//from   w w w.j ava  2  s .c o  m
        public void onClick(ClickEvent event) {
            downloadFile();
        }
    });

    html.setHTML(b.toSafeHtml());
    panel.add(html);
    panel.add(downloadButton);
    html.setStyleName("viewRepresentationNotSupportedPreview");
    downloadButton.setStyleName("btn btn-download viewRepresentationNotSupportedDownloadButton");

    onPreviewFailure.execute();

}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

protected Widget directoryPreview() {
    HTML html = new HTML();
    SafeHtmlBuilder b = new SafeHtmlBuilder();

    b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-folder-open fa-5'></i>"));
    b.append(SafeHtmlUtils.fromSafeConstant("<h4 class='emptymessage'>"));
    b.append(SafeHtmlUtils.fromString(filename + " /"));
    b.append(SafeHtmlUtils.fromSafeConstant("</h4>"));

    html.setHTML(b.toSafeHtml());
    html.setStyleName("viewRepresentationEmptyPreview");
    return html;//from  w w w.  ja va  2  s . c o m
}

From source file:org.roda.wui.client.browse.BrowseAIP.java

private void getDescriptiveMetadataHTML(final String aipId, final String descId,
        final DescriptiveMetadataViewBundle bundle, final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {/*  w  w  w.  j av a  2  s  .c  o  m*/
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                String escapedDescId = SafeHtmlUtils.htmlEscape(descId);

                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, escapedDescId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.BrowseRepresentation.java

private void getDescriptiveMetadataHTML(final String descId, final DescriptiveMetadataViewBundle bundle,
        final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, repId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {//from   w w  w . j a  v  a  2 s  .  c o  m
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }
                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId,
                            repId, descId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.CreateDescriptiveMetadata.java

protected void updateErrors(ValidationException e) {
    SafeHtmlBuilder b = new SafeHtmlBuilder();
    for (ValidationIssue issue : e.getReport().getIssues()) {
        b.append(SafeHtmlUtils.fromSafeConstant("<span class='error'>"));
        b.append(messages.metadataParseError(issue.getLineNumber(), issue.getColumnNumber(),
                issue.getMessage()));/*from   w ww  .j  ava  2 s .c o m*/
        b.append(SafeHtmlUtils.fromSafeConstant("</span>"));

    }

    errors.setHTML(b.toSafeHtml());
    errors.setVisible(true);
}

From source file:org.roda.wui.client.browse.DescriptiveMetadataHistory.java

private void getDescriptiveMetadata(final String aipId, final String representationId, final String descId,
        final String versionKey, final boolean inHTML, final AsyncCallback<SafeHtml> callback) {

    SafeUri uri;/*from   w  w w  . j  a  va  2s  .c o  m*/
    if (inHTML) {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId, versionKey);
        }
    } else {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, descId, versionKey);
        }
    }
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String text = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    if (inHTML) {
                        b.append(SafeHtmlUtils.fromTrustedString(text));
                    } else {
                        b.append(SafeHtmlUtils.fromString(text));
                    }
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (

    RequestException e)

    {
        callback.onFailure(e);
    }

}

From source file:org.roda.wui.client.browse.ShowPreservationEvent.java

private void getEventDetailsHTML(final AsyncCallback<SafeHtml> callback) {
    IndexedPreservationEvent event = bundle.getEvent();
    SafeUri uri = RestUtils.createPreservationEventDetailsHTMLUri(eventId, event.getAipID(),
            event.getRepresentationUUID(), event.getFileUUID());
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {// www  .ja  v  a 2s  .  com
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='eventHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.preservationEventDetailsTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.common.lists.JobList.java

@Override
protected void configureDisplay(CellTable<Job> display) {

    nameColumn = new TooltipTextColumn<Job>() {

        @Override//  w w  w  .j  a va2s.  c  om
        public String getValue(Job job) {
            return job != null ? job.getName() : null;
        }
    };

    usernameColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            return job != null ? job.getUsername() : null;
        }
    };

    startDateColumn = new Column<Job, Date>(
            new DateCell(DateTimeFormat.getFormat(RodaConstants.DEFAULT_DATETIME_FORMAT))) {
        @Override
        public Date getValue(Job job) {
            return job != null ? job.getStartDate() : null;
        }
    };

    durationColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            if (job == null) {
                return null;
            }
            Date end = job.getEndDate() != null ? job.getEndDate() : getDate();
            return Humanize.durationInDHMS(job.getStartDate(), end, DHMSFormat.SHORT);
        }
    };

    statusColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Job job) {
            return HtmlSnippetUtils.getJobStateHtml(job);
        }
    };

    objectsTotalCountColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            String ret = "";
            if (job != null && job.getJobStats().getSourceObjectsCount() > 0) {
                ret = Integer.toString(job.getJobStats().getSourceObjectsCount());
            }
            return ret;
        }
    };

    objectsSuccessCountColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(Job job) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            if (job != null) {
                b.append(job.getJobStats().getSourceObjectsProcessedWithSuccess() > 0
                        ? SafeHtmlUtils.fromSafeConstant("<span>")
                        : SafeHtmlUtils.fromSafeConstant("<span class='ingest-process-counter-0'>"));
                b.append(job.getJobStats().getSourceObjectsProcessedWithSuccess());
                b.append(SafeHtmlUtils.fromSafeConstant("</span>"));
            }
            return b.toSafeHtml();
        }
    };

    objectsFailureCountColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Job job) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            if (job != null) {
                b.append(SafeHtmlUtils.fromSafeConstant("<span"));
                if (job.getJobStats().getSourceObjectsProcessedWithFailure() > 0) {
                    b.append(SafeHtmlUtils.fromSafeConstant(" class='ingest-process-failed-column'"));
                } else {
                    b.append(SafeHtmlUtils.fromSafeConstant(" class='ingest-process-counter-0'"));
                }
                b.append(SafeHtmlUtils.fromSafeConstant(">"));
                b.append(job.getJobStats().getSourceObjectsProcessedWithFailure());
                b.append(SafeHtmlUtils.fromSafeConstant("</span>"));
            }
            return b.toSafeHtml();
        }
    };

    progressColumn = new TextColumn<Job>() {
        @Override
        public String getValue(Job job) {
            return job != null ? job.getJobStats().getCompletionPercentage() + "%" : null;
        }
    };

    nameColumn.setSortable(true);
    usernameColumn.setSortable(true);
    startDateColumn.setSortable(true);
    statusColumn.setSortable(true);
    objectsTotalCountColumn.setSortable(true);
    objectsSuccessCountColumn.setSortable(true);
    objectsFailureCountColumn.setSortable(true);
    progressColumn.setSortable(true);

    addColumn(nameColumn, messages.jobName(), true, false);
    addColumn(usernameColumn, messages.jobCreator(), true, false);
    addColumn(startDateColumn, messages.jobStartDate(), true, false, 11);
    addColumn(durationColumn, messages.jobDuration(), true, true, 6);
    addColumn(statusColumn, messages.jobStatus(), true, false, 7);
    addColumn(progressColumn, messages.jobProgress(), true, true, 5);
    addColumn(objectsTotalCountColumn, messages.jobTotalCountMessage(), true, true, 5);
    addColumn(objectsSuccessCountColumn, messages.jobSuccessCountMessage(), true, true, 6);
    addColumn(objectsFailureCountColumn, messages.jobFailureCountMessage(), true, true, 5);

    // default sorting
    display.getColumnSortList().push(new ColumnSortInfo(startDateColumn, false));

}

From source file:org.roda.wui.client.common.lists.SearchFileList.java

@Override
protected void configureDisplay(CellTable<IndexedFile> display) {
    iconColumn = new Column<IndexedFile, SafeHtml>(new SafeHtmlCell()) {

        @Override/*  w  w w . ja v a2  s  . com*/
        public SafeHtml getValue(IndexedFile file) {
            if (file != null) {
                if (file.isDirectory()) {
                    return SafeHtmlUtils.fromSafeConstant("<i class='fa fa-folder-open'></i>");
                } else {
                    return SafeHtmlUtils.fromSafeConstant("<i class='fa fa-file-o'></i>");
                }
            } else {
                logger.error("Trying to display a NULL item");
            }
            return null;
        }
    };

    pathColumn = new Column<IndexedFile, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(IndexedFile file) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            if (file != null) {
                List<String> filePath = file.getPath();
                String fileName = file.getOriginalName() != null ? file.getOriginalName() : file.getId();
                List<String> fullpath = new ArrayList<>(filePath);
                fullpath.add(fileName);
                b.append(SafeHtmlUtils.fromSafeConstant("<div title='"));
                b.append(SafeHtmlUtils.fromString(StringUtils.join(fullpath, "/")));
                b.append(SafeHtmlUtils.fromSafeConstant("'>"));
                if (showFilePath && filePath != null && !filePath.isEmpty()) {
                    String path = StringUtils.join(filePath, "/");
                    b.append(SafeHtmlUtils.fromSafeConstant("<span class='file-path'>"));
                    b.append(SafeHtmlUtils.fromString(path));
                    b.append(SafeHtmlUtils.fromSafeConstant("/"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</span>"));
                }

                b.append(SafeHtmlUtils.fromString(fileName));
                b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
            }

            return b.toSafeHtml();
        }
    };

    formatColumn = new TextColumn<IndexedFile>() {

        @Override
        public String getValue(IndexedFile file) {
            if (file != null && file.getFileFormat() != null) {
                FileFormat format = file.getFileFormat();
                String ret;
                if (StringUtils.isNotBlank(format.getFormatDesignationName())) {
                    ret = format.getFormatDesignationName();
                    if (StringUtils.isNotBlank(format.getFormatDesignationVersion())) {
                        ret = ret + " " + format.getFormatDesignationVersion();
                    }
                } else if (StringUtils.isNotBlank(format.getPronom())) {
                    ret = format.getPronom();
                } else if (StringUtils.isNotBlank(format.getMimeType())) {
                    ret = format.getMimeType();
                } else {
                    ret = null;
                }
                return ret;

            } else {
                return null;
            }
        }
    };

    sizeColumn = new TextColumn<IndexedFile>() {

        @Override
        public String getValue(IndexedFile file) {
            return (file != null && file.getSize() > 0) ? Humanize.readableFileSize(file.getSize()) : "";
        }
    };

    /* add sortable */
    iconColumn.setSortable(true);
    pathColumn.setSortable(true);
    formatColumn.setSortable(true);
    sizeColumn.setSortable(true);

    addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<i class='fa fa-files-o'></i>"), false, false, 3);
    addColumn(pathColumn, messages.filePath(), true, false);
    addColumn(formatColumn, messages.fileFormat(), true, false);
    addColumn(sizeColumn, messages.fileSize(), true, false, 7);

    // define column width priority
    display.setColumnWidth(iconColumn, 3.0, Unit.EM);
    display.setColumnWidth(sizeColumn, 6.0, Unit.EM);

    pathColumn.setCellStyleNames("text-align-left");
    formatColumn.setCellStyleNames("text-align-left");
    sizeColumn.setCellStyleNames("text-align-right");

    // define default sorting
    display.getColumnSortList().push(new ColumnSortInfo(pathColumn, true));
    addStyleName("my-files-table");
}

From source file:org.roda.wui.client.common.slider.InfoSliderHelper.java

private static void updateInfoSliderPanel(IndexedFile file, SliderPanel infoSliderPanel) {
    HashMap<String, SafeHtml> values = new HashMap<>();

    infoSliderPanel.clear();/*from   w  ww .  j ava 2  s .  com*/
    infoSliderPanel.addTitle(new Label(messages.viewRepresentationInfoTitle()));

    if (file != null) {
        String fileName = file.getOriginalName() != null ? file.getOriginalName() : file.getId();
        values.put(messages.viewRepresentationInfoFilename(), SafeHtmlUtils.fromString(fileName));

        if (file.getSize() > 0) {
            values.put(messages.viewRepresentationInfoSize(),
                    SafeHtmlUtils.fromString(Humanize.readableFileSize(file.getSize())));
        }

        if (file.getFileFormat() != null) {
            FileFormat fileFormat = file.getFileFormat();

            if (StringUtils.isNotBlank(fileFormat.getMimeType())) {
                values.put(messages.viewRepresentationInfoMimetype(),
                        SafeHtmlUtils.fromString(fileFormat.getMimeType()));
            }

            if (StringUtils.isNotBlank(fileFormat.getFormatDesignationName())) {
                values.put(messages.viewRepresentationInfoFormat(),
                        SafeHtmlUtils.fromString(fileFormat.getFormatDesignationName()));
            }

            if (StringUtils.isNotBlank(fileFormat.getFormatDesignationVersion())) {
                values.put(messages.viewRepresentationInfoFormatVersion(),
                        SafeHtmlUtils.fromString(fileFormat.getFormatDesignationVersion()));
            }

            if (StringUtils.isNotBlank(fileFormat.getPronom())) {
                values.put(messages.viewRepresentationInfoPronom(),
                        SafeHtmlUtils.fromString(fileFormat.getPronom()));
            }

        }

        if (StringUtils.isNotBlank(file.getCreatingApplicationName())) {
            values.put(messages.viewRepresentationInfoCreatingApplicationName(),
                    SafeHtmlUtils.fromString(file.getCreatingApplicationName()));
        }

        if (StringUtils.isNotBlank(file.getCreatingApplicationVersion())) {
            values.put(messages.viewRepresentationInfoCreatingApplicationVersion(),
                    SafeHtmlUtils.fromString(file.getCreatingApplicationVersion()));
        }

        if (StringUtils.isNotBlank(file.getDateCreatedByApplication())) {
            values.put(messages.viewRepresentationInfoDateCreatedByApplication(),
                    SafeHtmlUtils.fromString(file.getDateCreatedByApplication()));
        }

        if (file.getHash() != null && !file.getHash().isEmpty()) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            boolean first = true;
            for (String hash : file.getHash()) {
                if (first) {
                    first = false;
                } else {
                    b.append(SafeHtmlUtils.fromSafeConstant("<br/>"));
                }
                b.append(SafeHtmlUtils.fromSafeConstant("<small>"));
                b.append(SafeHtmlUtils.fromString(hash));
                b.append(SafeHtmlUtils.fromSafeConstant("</small>"));
            }
            values.put(messages.viewRepresentationInfoHash(), b.toSafeHtml());
        }

        if (file.getStoragePath() != null) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            b.append(SafeHtmlUtils.fromSafeConstant("<small>"));
            b.append(SafeHtmlUtils.fromString(file.getStoragePath()));
            b.append(SafeHtmlUtils.fromSafeConstant("</small>"));

            values.put(messages.viewRepresentationInfoStoragePath(), b.toSafeHtml());
        }
    }

    populate(infoSliderPanel, values);
}