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

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

Introduction

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

Prototype

public SafeHtmlBuilder appendHtmlConstant(String html) 

Source Link

Document

Appends a compile-time-constant string, which will not be escaped.

Usage

From source file:cz.filmtit.client.pages.UserPage.java

License:Open Source License

/**
 * Shows the page and loads the list of user's documents.
 *//*from   w  w  w.j  a v a2s  .c  o  m*/
public UserPage() {
    initWidget(uiBinder.createAndBindUi(this));

    /**
     * A column consisting of EdiTextCells with a title (aka a tool-tip)
     *
     * @author rur
     *
     */
    abstract class EditableTitledColumn extends Column<Document, String> {

        private String title;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public EditableTitledColumn(String title) {
            super(new EditTextCell());
            this.title = title;
        }

        @Override
        public void render(Context context, Document object, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div title=\"" + title + "\">");
            super.render(context, object, sb);
            sb.appendHtmlConstant("</div>");
        }
    }

    // column with Document title
    Column<Document, String> nameClm = new EditableTitledColumn("click to change document title") {
        @Override
        public String getValue(Document doc) {
            return doc.getTitle();
        }
    };
    // use ChangeDocumentTitle() to change the title
    nameClm.setFieldUpdater(new FieldUpdater<Document, String>() {
        @Override
        public void update(int index, Document doc, String newTitle) {
            if (newTitle == null || newTitle.isEmpty()) {
                // we don't accept the new title
                // refresh to show the original one
                Gui.getPageHandler().refresh();
            } else if (newTitle.equals(doc.getTitle())) {
                // not changed, ignore
            } else {
                new ChangeDocumentTitle(doc.getId(), newTitle);
                doc.setTitle(newTitle);
            }
        }
    });

    // column with Movie title
    Column<Document, String> mSourceClm = new EditableTitledColumn("click to change movie title") {
        @Override
        public String getValue(Document doc) {
            if (doc.getMovie() == null) {
                return "(none)";
            } else {
                return doc.getMovie().toString();
            }
        }

    };
    // use ChangeMovieTitle() to change the title
    mSourceClm.setFieldUpdater(new FieldUpdater<Document, String>() {
        @Override
        public void update(int index, Document doc, String newTitle) {
            if (newTitle == null || newTitle.isEmpty()) {
                // we don't accept the new title
                // refresh to show the original one
                Gui.getPageHandler().refresh();
            } else if (doc.getMovie() != null && doc.getMovie().toString().equals(newTitle)) {
                // not changed, ignore
            } else {
                // TODO: should lock the page while waiting for media sources
                new ChangeMovieTitle(doc.getId(), newTitle);
            }
        }
    });

    // column with translation direction
    TextColumn<Document> languageClm = new TextColumn<Document>() {
        @Override
        public String getValue(Document doc) {
            // TODO: do you prefer names or codes?
            return doc.getLanguage().getTranslationDirectionNames();
        }
    };

    // percentage of translated chunks
    TextColumn<Document> doneClm = new TextColumn<Document>() {
        @Override
        public String getValue(Document doc) {
            return Double.toString(
                    Math.round(10000 * doc.getTranslatedChunksCount() / doc.getTotalChunksCount()) / 100) + "%";
        }
    };

    // date and time of last edit of the document (table is sorted by this column)
    TextColumn<Document> lastEditedClm = new TextColumn<Document>() {
        @Override
        public String getValue(Document doc) {
            Date lastChange = new Date(doc.getLastChange());
            return DateTimeFormat.getFormat("dd/MM/yyy HH:mm").format(lastChange);
        }
    };

    com.github.gwtbootstrap.client.ui.ButtonCell buttonCell = new com.github.gwtbootstrap.client.ui.ButtonCell();

    // edit button
    com.google.gwt.user.cellview.client.Column<Document, String> buttonClm = new com.google.gwt.user.cellview.client.Column<Document, String>(
            buttonCell) {
        @Override
        public String getValue(Document doc) {
            return "Edit";
        }
    };

    buttonClm.setFieldUpdater(new FieldUpdater<Document, String>() {
        public void update(int index, Document doc, String value) {
            editDocument(doc);
        }
    });

    // export button
    com.google.gwt.user.cellview.client.Column<Document, String> exportSubtitlesButton = new com.google.gwt.user.cellview.client.Column<Document, String>(
            buttonCell) {
        @Override
        public String getValue(Document doc) {
            return "Export";
        }
    };

    exportSubtitlesButton.setFieldUpdater(new FieldUpdater<Document, String>() {
        public void update(int index, Document doc, String value) {
            new DownloadDialog(doc);
        }
    });

    // share button
    com.google.gwt.user.cellview.client.Column<Document, String> settingsButton = new com.google.gwt.user.cellview.client.Column<Document, String>(
            buttonCell) {
        @Override
        public String getValue(Document doc) {
            return "Settings";
        }
    };

    settingsButton.setFieldUpdater(new FieldUpdater<Document, String>() {
        public void update(int index, Document doc, String value) {
            new SettingsDialog(Gui.getUser(), doc);
        }
    });

    // delete button
    com.google.gwt.user.cellview.client.Column<Document, String> deleteButton = new com.google.gwt.user.cellview.client.Column<Document, String>(
            buttonCell) {
        @Override
        public String getValue(Document doc) {
            return "Remove";
        }
    };

    deleteButton.setFieldUpdater(new FieldUpdater<Document, String>() {
        public void update(int index, Document doc, String value) {
            if (Window.confirm("Do you really want to remove the document " + doc.getTitle()
                    + " from your list of documents?"
                    + "\nNote: Document will still be available to users who have access to this document.")) {
                new DeleteDocument(doc.getId());
            }
        }
    });

    docTable.addColumn(nameClm, "Document");
    docTable.addColumn(mSourceClm, "Movie/TV Show");
    docTable.addColumn(languageClm, "Language");
    docTable.addColumn(doneClm, "Translated");
    docTable.addColumn(lastEditedClm, "Last edited");
    docTable.addColumn(buttonClm, "Edit");
    docTable.addColumn(settingsButton, "Settings");
    docTable.addColumn(exportSubtitlesButton, "Export");
    docTable.addColumn(deleteButton, "Remove");

    // load documents
    new GetListOfDocuments(this);

    Gui.getGuiStructure().contentPanel.setStyleName("users_page");
    Gui.getGuiStructure().contentPanel.setWidget(this);
}

From source file:cz.metacentrum.perun.webgui.widgets.UnaccentMultiWordSuggestOracle.java

License:Apache License

/**
 * Returns real suggestions with the given query in <code>strong</code> html
 * font.//from w  w  w.  jav a  2  s.  com
 *
 * @param query query string
 * @param candidates candidates
 * @return real suggestions
 */
private List<MultiWordSuggestion> convertToFormattedSuggestions(String query, List<String> candidates) {
    List<MultiWordSuggestion> suggestions = new ArrayList<MultiWordSuggestion>();

    for (int i = 0; i < candidates.size(); i++) {
        String candidate = candidates.get(i);
        int cursor = 0;
        int index = 0;
        // Use real suggestion for assembly.
        String formattedSuggestion = toRealSuggestions.get(candidate);

        // Create strong search string.
        SafeHtmlBuilder accum = new SafeHtmlBuilder();

        String[] searchWords = query.split(WHITESPACE_STRING);
        while (true) {
            WordBounds wordBounds = findNextWord(candidate, searchWords, index);
            if (wordBounds == null) {
                break;
            }
            if (wordBounds.startIndex == 0 || WHITESPACE_CHAR == candidate.charAt(wordBounds.startIndex - 1)) {
                String part1 = formattedSuggestion.substring(cursor, wordBounds.startIndex);
                String part2 = formattedSuggestion.substring(wordBounds.startIndex, wordBounds.endIndex);
                cursor = wordBounds.endIndex;
                accum.appendEscaped(part1);
                accum.appendHtmlConstant("<strong>");
                accum.appendEscaped(part2);
                accum.appendHtmlConstant("</strong>");
            }
            index = wordBounds.endIndex;
        }

        // Check to make sure the search was found in the string.
        if (cursor == 0) {
            continue;
        }

        accum.appendEscaped(formattedSuggestion.substring(cursor));
        MultiWordSuggestion suggestion = createSuggestion(formattedSuggestion, accum.toSafeHtml().asString());
        suggestions.add(suggestion);
    }
    return suggestions;
}

From source file:de.knightsoftnet.validators.client.decorators.AbstractDecorator.java

License:Apache License

/**
 * The default implementation will display, but not consume, received errors whose
 * {@link EditorError#getEditor() getEditor()} method returns the Editor passed into
 * {@link #setEditor}./*from www . j  a  v a 2 s. com*/
 *
 * @param errors a List of {@link EditorError} instances
 */
@Override
public void showErrors(final List<EditorError> errors) {
    final Set<String> messages = new HashSet<String>();
    for (final EditorError error : errors) {
        if (this.editorErrorMatches(error)) {
            messages.add(error.getMessage());
        }
    }
    if (messages.isEmpty()) {
        this.errorLabel.setText(StringUtils.EMPTY);
        this.errorLabel.getElement().getStyle().setDisplay(Display.NONE);
        if (this.contents.getWidget() != null) {
            this.contents.getWidget().removeStyleName(this.decoratorStyle.errorInputStyle());
            this.contents.getWidget().addStyleName(this.decoratorStyle.validInputStyle());
        }
    } else {
        if (this.contents.getWidget() != null) {
            this.contents.getWidget().removeStyleName(this.decoratorStyle.validInputStyle());
            this.contents.getWidget().addStyleName(this.decoratorStyle.errorInputStyle());
            if (this.focusOnError) {
                this.setFocus(true);
            }
        }
        final SafeHtmlBuilder sb = new SafeHtmlBuilder();
        for (final String message : messages) {
            sb.appendEscaped(message);
            sb.appendHtmlConstant("<br />");
        }
        this.errorLabel.setHTML(sb.toSafeHtml());
        this.errorLabel.getElement().getStyle().setDisplay(Display.TABLE);
    }
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.column.LemmaVersionColumnHighlightable.java

License:Apache License

@Override
public SafeHtml getValue(LemmaVersion object) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    LemmaDescription description = AsyncLemmaDescriptionLoader.getDescription();
    String toDisplay = description.toString(object, UseCase.RESULT_LIST, true) + "  "
            + description.toString(object, UseCase.RESULT_LIST, false);
    if (query != null && query.isHighlight()) {
        toDisplay = Highlighter.highlight(toDisplay, query.getValue("searchPhrase"));
    }//from   w w  w . j  av a 2s  .c  o  m
    sb.appendHtmlConstant(toDisplay);
    return sb.toSafeHtml();
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.wrapper.LemmaVersionCellWrapper.java

License:Apache License

@Override
public SafeHtml getLemma() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendHtmlConstant(lemmaDescription.toString(lemma, UseCase.RESULT_LIST, true));
    builder.appendHtmlConstant("  ");
    builder.appendHtmlConstant(lemmaDescription.toString(lemma, UseCase.RESULT_LIST, false));
    return builder.toSafeHtml();
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.wrapper.LemmaVersionCellWrapper.java

License:Apache License

@Override
public SafeHtml getShortLemma() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    String first = lemmaDescription.toString(lemma, UseCase.RESULT_LIST, true).trim();
    if (first.length() > 85) {
        first = escaper.escape(first.substring(0, 40) + "..." + first.substring(first.length() - 40));
    }/*from  w  ww .ja v a  2  s  .com*/
    String second = lemmaDescription.toString(lemma, UseCase.RESULT_LIST, false).trim();
    if (second.length() > 85) {
        second = escaper.escape(second.substring(0, 40) + "..." + first.substring(first.length() - 40));
    }
    builder.appendHtmlConstant(first);
    builder.appendHtmlConstant("  ");
    builder.appendHtmlConstant(second);
    return builder.toSafeHtml();
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.order.OrderWidget.java

License:Apache License

private void initialize() {
    selectionModel = new SingleSelectionModel<LemmaVersion>(new ProvidesKey<LemmaVersion>() {

        @Override/* w  ww. j  a va  2  s .co m*/
        public Object getKey(LemmaVersion item) {
            return item;
        }
    });
    provider = new ListDataProvider<LemmaVersion>();
    initWidget(uiBinder.createAndBindUi(OrderWidget.this));
    //      header.setText("Modify Order");
    list.setPageSize(100);
    list.setSelectionModel(selectionModel);
    list.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    Column<LemmaVersion, SafeHtml> column = new Column<LemmaVersion, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(LemmaVersion object) {

            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            LemmaDescription description = AsyncLemmaDescriptionLoader.getDescription();
            String toDisplay = description.toString(object, UseCase.RESULT_LIST, true) + "  "
                    + description.toString(object, UseCase.RESULT_LIST, false);
            sb.appendHtmlConstant(toDisplay);
            return sb.toSafeHtml();
        }
    };
    RowStyles<LemmaVersion> wrapper = new RowStyles<LemmaVersion>() {

        @Override
        public String getStyleNames(LemmaVersion row, int rowIndex) {
            return "user-row";
        }
    };
    list.setRowStyles(wrapper);
    list.addColumn(column);
    provider.addDataDisplay(list);
    up.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            LemmaVersion obj = selectionModel.getSelectedObject();
            if (obj == null)
                return;
            int index = provider.getList().indexOf(obj);
            if (index == -1)
                return;
            if (index == 0)
                return;
            LemmaVersion other = provider.getList().get(index - 1);
            provider.getList().set(index - 1, obj);
            provider.getList().set(index, other);
            provider.refresh();

        }
    });
    down.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            LemmaVersion obj = selectionModel.getSelectedObject();
            if (obj == null)
                return;
            int index = provider.getList().indexOf(obj);
            if (index == -1)
                return;
            if (index == provider.getList().size() - 1)
                return;
            LemmaVersion other = provider.getList().get(index + 1);
            provider.getList().set(index, other);
            provider.getList().set(index + 1, obj);
            provider.refresh();
        }
    });
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.entry.OverlayPopup.java

License:Apache License

private static void createOverlay(Overlay overlay, LemmaVersion lemmaVersion, String closeButton) {
    String form = overlay.getForm();
    HashSet<String> values = new HashSet<String>();
    RegExp regExp = RegExp.compile("(\\$\\{(.*)\\})", "g");
    for (MatchResult matcher = regExp.exec(form); matcher != null; matcher = regExp.exec(form)) {
        values.add(matcher.getGroup(2));
    }/*from ww w  .  ja  va 2  s  . co  m*/
    for (String key : values) {
        String value = lemmaVersion.getEntryValue(key);
        if (value == null || value.trim().length() == 0) {
            form = form.replaceAll("\\$\\{" + key + "\\}", "");
        } else {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendEscaped(value);
            form = form.replaceAll("\\$\\{" + key + "\\}", builder.toSafeHtml().asString());
        }
    }
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendHtmlConstant(form);
    final Modal popup = new Modal(true);
    popup.add(new HTML(builder.toSafeHtml()));
    popup.setBackdrop(BackdropType.NORMAL);
    popup.setCloseVisible(true);
    popup.setWidth(1000);

    final Button close = new Button(closeButton);
    close.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });
    ModalFooter footer = new ModalFooter(close);
    popup.add(footer);
    popup.show();
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.search.celltable.ResultCellTable.java

License:Apache License

private void addOverlayColumn(final String overlayField, final TranslationMap translationMap) {
    final SafeHtmlCell overlayCell = new SafeHtmlCell() {
        final String closeButton = translationMap.get("maalr.verbOverlayPopup.closeButton");

        @Override/*w ww . ja va 2s  .  c o m*/
        public Set<String> getConsumedEvents() {
            Set<String> consumed = new HashSet<String>();
            consumed.add(BrowserEvents.CLICK);
            return consumed;
        }

        @Override
        public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent,
                SafeHtml value, NativeEvent event, ValueUpdater<SafeHtml> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if (event.getType().equals(BrowserEvents.CLICK)) {
                LemmaVersion selected = dataProvider.getList().get(hoveredRow);
                onButtonClicked(selected);
            }
        }

        private void onButtonClicked(LemmaVersion selected) {
            // Window.alert("Selected: " + selected.getEntryValues());
            OverlayPopup.show(selected, overlayField, closeButton);
            // final LemmaVersion lemma = new LemmaVersion();
            // lemma.setEntryValues(selected.getEntryValues());
            // lemma.setMaalrValues(selected.getMaalrValues());
            // openModifyEditor(lemma);
        }

    };
    popupColumn = new Column<LemmaVersion, SafeHtml>(overlayCell) {

        private final SafeHtml nothing = new SafeHtmlBuilder().toSafeHtml();

        @Override
        public SafeHtml getValue(LemmaVersion object) {
            String overlay = object.getEntryValue(overlayField);
            if (overlay != null) {
                SafeHtmlBuilder builder = new SafeHtmlBuilder();
                builder.appendHtmlConstant(
                        "<span class=\"maalr_overlay maalr_overlay_" + overlay + "\">" + overlay + "</span>");
                return builder.toSafeHtml();
            } else {
                return nothing;
            }
        }
    };
    cellTable.addColumn(popupColumn);
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.search.celltable.ResultCellTable.java

License:Apache License

private void addColumnA(String langA, final boolean b) {

    final SafeHtmlCell leftCell = new SafeHtmlCell();
    columnA = new Column<LemmaVersion, SafeHtml>(leftCell) {

        @Override//from   w  ww  .  j  a v a 2 s.  com
        public SafeHtml getValue(LemmaVersion object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            String toDisplay = description.toString(object, UseCase.RESULT_LIST, b);
            String redirect = b ? object.getEntryValue("redirect_a") : object.getEntryValue("redirect_b");
            if (maalrQuery.isHighlight() && redirect == null) {
                toDisplay = Highlighter.highlight(toDisplay, maalrQuery.getValue("searchPhrase"));
            }
            if (redirect != null) {
                MaalrQuery mq = new MaalrQuery();
                String[] redir = redirect.split("=");
                mq.setQueryValue(redir[0], redir[1]);
                String text = redir[1];
                if (maalrQuery.isHighlight()) {
                    text = Highlighter.highlight(text, maalrQuery.getValue("searchPhrase"));
                }
                String url = "<a href=\"" + Window.Location.getPath() + "#" + mq.toURL() + "\">" + text
                        + "</a>";
                toDisplay = toDisplay.replace(redir[1], url);
            }
            if (!object.isApproved()) {
                toDisplay = "<span class=\"unverified\">" + toDisplay + "</span>";
            }
            sb.appendHtmlConstant(toDisplay);
            return sb.toSafeHtml();
        }
    };

    cellTable.addColumn(columnA, new SafeHtmlBuilder()
            .appendHtmlConstant("<span class=\"maalr_result_title\">" + langA + "</span>").toSafeHtml());
}