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

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

Introduction

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

Prototype

public SafeHtmlBuilder() 

Source Link

Document

Constructs an empty SafeHtmlBuilder.

Usage

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 w  w. j  ava 2 s  .  co  m
    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 w w.  j  av a 2  s  .c o  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.editor.client.entry.SuggestionEditor.java

License:Apache License

private void export() {
    AsyncLemmaDescriptionLoader.afterLemmaDescriptionLoaded(new AsyncCallback<LemmaDescription>() {

        @Override/*from   w w w  .  j a  v  a  2 s .  c o  m*/
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(final LemmaDescription description) {
            final ArrayList<String> fields = new ArrayList<String>(description.getEditorFields(true));
            fields.addAll(description.getEditorFields(false));
            fields.add(LemmaVersion.COMMENT);
            LocalizedStrings.afterLoad(new AsyncCallback<TranslationMap>() {

                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(TranslationMap translation) {
                    showExportDialog(fields, translation);
                }
            });

        }

        private void showExportDialog(final ArrayList<String> fields, TranslationMap translation) {
            final Modal dialog = new Modal();
            final FlowPanel panel = new FlowPanel();
            final Set<String> selected = new HashSet<String>();
            final List<CheckBox> boxes = new ArrayList<CheckBox>();
            for (final String field : fields) {
                String label = translation.get(field);
                if (label == null)
                    label = field;
                final CheckBox box = new CheckBox(label);
                box.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        if (box.getValue()) {
                            selected.add(field);
                        } else {
                            selected.remove(field);
                        }
                    };
                });
                boxes.add(box);
                panel.add(box);
            }
            Button exportAll = new Button(constants.selectAll());
            exportAll.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    for (CheckBox box : boxes) {
                        box.setValue(true);
                    }
                    selected.addAll(fields);
                }
            });
            Button exportNone = new Button(constants.deselectAll());
            exportNone.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    for (CheckBox box : boxes) {
                        box.setValue(false);
                    }
                    selected.clear();
                }
            });
            ButtonGroup group = new ButtonGroup();
            group.add(exportAll);
            group.add(exportNone);
            panel.add(group);
            dialog.add(panel);
            Button cancel = new Button(constants.cancel());
            cancel.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    dialog.hide();
                }
            });
            final Button ok = new Button(constants.export());
            ok.setType(ButtonType.PRIMARY);
            dialog.setTitle(constants.selectedFieldsExport());

            ok.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    panel.clear();
                    dialog.setTitle(constants.exporting());
                    ok.setVisible(false);
                    Label busyLabel = new Label(constants.exportingData());
                    panel.add(busyLabel);
                    EditorQuery query = listFilter.getQuery();
                    query.setCurrent(0);
                    service.export(selected, query, new AsyncCallback<String>() {

                        @Override
                        public void onFailure(Throwable caught) {
                        }

                        @Override
                        public void onSuccess(String result) {
                            dialog.setTitle(constants.exportCompleted());
                            panel.clear();
                            result = GWT.getHostPageBaseURL() + "download/" + result + ".html";
                            Label label = new Label(constants.exportDownload());
                            panel.add(label);
                            Anchor anchor = new Anchor(
                                    new SafeHtmlBuilder().appendEscaped(constants.download()).toSafeHtml(),
                                    result);
                            anchor.addClickHandler(new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent event) {
                                    dialog.hide();
                                }
                            });
                            panel.add(anchor);
                        }
                    });
                }
            });
            ModalFooter footer = new ModalFooter(cancel, ok);
            dialog.add(footer);
            dialog.setAnimation(true);
            dialog.setBackdrop(BackdropType.STATIC);
            int customWidth = 850;
            dialog.setWidth(customWidth + "px");
            dialog.show();
            double customMargin = -1 * (customWidth / 2);
            dialog.getElement().getStyle().setMarginLeft(customMargin, Unit.PX);
            dialog.getElement().getStyle().setMarginRight(customMargin, Unit.PX);
            dialog.getElement().getStyle().setMarginTop(70, Unit.PX);
        }
    });
}

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 w  w  w .ja v a  2s .com
    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/*from   w w  w. j  a  v  a2s.  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/*ww w .j  a v  a 2 s  . c om*/
        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());
}

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

License:Apache License

private void addColumnB(String langB, final boolean b) {
    columnB = new Column<LemmaVersion, SafeHtml>(new SafeHtmlCell()) {

        @Override//from   w w  w. ja  v a2 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);
                // toDisplay = "<a href=\"" + mq.toURL() + "\">" + redir[1]
                // + "</a>";
            }
            if (!object.isApproved()) {
                toDisplay = "<span class=\"unverified\">" + toDisplay + "</span>";
            }
            // if (!b)
            // sb.appendHtmlConstant(refereTo(toDisplay));
            // else
            sb.appendHtmlConstant(toDisplay);
            return sb.toSafeHtml();
        }

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

From source file:de.voot.encfsanywhere.client.widget.AlertWidgetImpl.java

License:Open Source License

@Override
public void show(String caption, String text) {
    this.caption.setInnerText(caption);
    this.text.setHTML(new SafeHtmlBuilder().appendEscapedLines(text).toSafeHtml());
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.button.Css3ButtonCellAppearance.java

License:sencha.com license

@Override
public void render(ButtonCell<M> cell, Context context, M value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    String text = hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "";

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String arrowClass = "";
    String scaleClass = "";
    String iconClass = "";

    int width = cell.getWidth();
    int height = cell.getHeight();
    boolean hasIcon = cell.getIcon() != null;
    boolean isSplitButton = cell instanceof SplitButtonCell;
    boolean hasMenu = cell.getMenu() != null;

    boolean hasWidth = width != -1;

    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.split();
                break;
            case BOTTOM:
                arrowClass = style.splitBottom();
                break;
            }/*from w  w  w  .  j  a v  a 2s. c o m*/

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.arrow();
                break;
            case BOTTOM:
                arrowClass = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        scaleClass = style.small();
        break;

    case MEDIUM:
        scaleClass = style.medium();
        break;

    case LARGE:
        scaleClass = style.large();
        break;
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            iconClass = style.iconTop();
            break;
        case BOTTOM:
            iconClass = style.iconBottom();
            break;
        case LEFT:
            iconClass = style.iconLeft();
            break;
        case RIGHT:
            iconClass = style.iconRight();
            break;
        }
    }

    String buttonClass = style.button();
    boolean hasText = text != null && !text.equals("");
    if (!hasText) {
        buttonClass += " " + style.noText();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        buttonClass += " " + style.pressed();
    }

    String innerClass = style.buttonInner() + " " + iconClass;

    innerClass += " " + arrowClass;
    innerClass += " " + scaleClass;

    SafeHtmlBuilder builder = new SafeHtmlBuilder();

    SafeStylesBuilder ss = new SafeStylesBuilder();

    if (height != -1) {
        ButtonDetails bd = resources.theme().button();
        EdgeDetails padding = bd.padding();
        EdgeDetails paddingInner = bd.radiusMinusBorderWidth();
        int ah = height;
        ah -= padding.top();
        ah -= padding.bottom();
        ah -= paddingInner.top();
        ah -= paddingInner.bottom();

        ss.appendTrustedString("line-height: " + ah + "px;");
    }

    builder.appendHtmlConstant("<div class='" + buttonClass + "'>");

    // get iconbuilder ready
    SafeHtmlBuilder iconBuilder = new SafeHtmlBuilder();
    if (icon != null) {
        int iconWidth = icon != null ? icon.getWidth() : 0;
        int iconHeight = icon != null ? icon.getHeight() : 0;
        String styles = "width: " + iconWidth + "px; height: " + iconHeight + "px;";

        iconBuilder.appendHtmlConstant("<div class='" + iconClass + "' style='" + styles + "'>");
        iconBuilder.append(AbstractImagePrototype.create(icon).getSafeHtml());
        iconBuilder.appendHtmlConstant("</div>");
    }

    // for left / right aligned icons with a fixed button width we render the icon outside of the inner div
    if (hasWidth && hasIcon && iconAlign == IconAlign.LEFT) {
        builder.append(iconBuilder.toSafeHtml());
    }

    if (hasWidth && hasIcon && (iconAlign == IconAlign.LEFT)) {
        int tw = width - (resources.theme().button().borderRadius() * 2);
        if (isSplitButton && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.split().getWidth() + 10;
        }

        if (!isSplitButton && iconAlign == IconAlign.LEFT && hasMenu
                && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.arrow().getWidth() + 10;
        }

        if (hasIcon && iconAlign == IconAlign.LEFT) {
            tw -= icon.getWidth();
        }

        ss.appendTrustedString("width: " + tw + "px;");
    }

    builder.appendHtmlConstant("<div class='" + innerClass + "' style='" + ss.toSafeStyles().asString() + "'>");

    if (icon != null) {
        if ((!hasWidth && iconAlign == IconAlign.LEFT) || iconAlign == IconAlign.TOP) {
            builder.append(iconBuilder.toSafeHtml());
        }
        builder.appendHtmlConstant(text);
        if (iconAlign == IconAlign.RIGHT || iconAlign == IconAlign.BOTTOM) {
            builder.append(iconBuilder.toSafeHtml());
        }
    } else {
        builder.appendHtmlConstant(text);
    }

    builder.appendHtmlConstant("</div></div>");
    sb.append(builder.toSafeHtml());
}