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:com.appspot.hommkmessage.shared.MessageMetadata.java

License:Open Source License

public HTML getInfoLine(DateFormatter dateFormatter, LocalStorage localStorage) {
    String creationDatePart = "<span class=\"messageListEntryUploadDate\">"
            + dateFormatter.formatDateTime(creationDate) + "</span>";
    String iconHtml = getMessageType().getIconHtml();
    SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
    String subjectClass = "";
    if (localStorage.isMessageUnread(id)) {
        subjectClass = "messageListEntrySubjectUnread";
    }/*from   w w  w .  j  a  v a 2 s. co m*/
    safeHtmlBuilder.appendHtmlConstant("<span class=\"" + subjectClass + "\">");
    safeHtmlBuilder.appendEscaped(subjectText);
    safeHtmlBuilder.appendHtmlConstant("</span><br/><span class=\"messageListEntrySecondLine\">");
    safeHtmlBuilder.appendEscaped(messageDateText);
    safeHtmlBuilder.appendEscaped(receiverText);
    safeHtmlBuilder.appendHtmlConstant("</span>");
    return new HTML(creationDatePart + " -- " + iconHtml + safeHtmlBuilder.toSafeHtml().asString());
}

From source file:com.appspot.socialinquirer.client.view.ActivityViewImpl.java

License:Apache License

/**
 * Inits the table columns./*from  w w  w  .  j  a  v  a 2  s . co  m*/
 *
 * @param table the table
 * @param selectionModel the selection model
 */
private void initTableColumns(CellTable<NamedBean> table, final SelectionModel<NamedBean> selectionModel) {
    // Checkbox column. This table will uses a checkbox column for
    // selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable
    // mouse selection.
    Column<NamedBean, Boolean> checkColumn = new Column<NamedBean, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(NamedBean object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));

    // Name.
    Column<NamedBean, String> nameColumn = new Column<NamedBean, String>(new ClickableTextCell()) {
        @Override
        public String getValue(NamedBean object) {
            return object.getName();
        }
    };
    table.addColumn(nameColumn, constants.templatesTableColumnName());
    // Headline.
    //       Column<NamedBean, String> tagsColumn = new Column<NamedBean, String>(
    //           new ClickableTextCell()) {
    //         @Override
    //         public String getValue(NamedBean object) {
    //            StringBuilder builder = new StringBuilder();
    //            for (String tag : object.getTags()) {
    //               builder.append(tag).append(" ");
    //            }
    //           return builder.toString();
    //           
    //         }
    //       };
    //       table.addColumn(tagsColumn, constants.templatesTableColumnTags());

    // Description
    Column<NamedBean, SafeHtml> descColumn = new Column<NamedBean, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(NamedBean object) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendHtmlConstant(object.getDescription());
            return builder.toSafeHtml();
        }
    };
    table.addColumn(descColumn, constants.templatesTableColumnSummary());
}

From source file:com.appspot.socialinquirer.client.view.HomeViewImpl.java

License:Apache License

/**
 * Inits the table columns./* w  ww .  ja  v  a  2s. c  om*/
 *
 * @param table the table
 */
private void initTableColumns(CellTable<Message> table) {
    // Checkbox column. This table will uses a checkbox column for
    // selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable
    // mouse selection.
    //       Column<Message, Boolean> checkColumn = new Column<Message, Boolean>(
    //           new CheckboxCell(true, false)) {
    //         @Override
    //         public Boolean getValue(Message object) {
    //           // Get the value from the selection model.
    //           return selectionModel.isSelected(object);
    //         }
    //       };
    //       table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));

    // Name.
    Column<Message, String> nameColumn = new Column<Message, String>(new TextCell()) {
        @Override
        public String getValue(Message object) {
            return object.getName();
        }
    };
    table.addColumn(nameColumn, constants.templatesTableColumnName());
    // Headline.
    Column<Message, String> tagsColumn = new Column<Message, String>(new TextCell()) {
        @Override
        public String getValue(Message object) {
            StringBuilder builder = new StringBuilder();
            builder.append(object.getRecipient().getDisplayName());
            return builder.toString();

        }
    };
    table.addColumn(tagsColumn, constants.templatesTableColumnTags());
    // Description
    Column<Message, SafeHtml> descColumn = new Column<Message, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Message object) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendHtmlConstant(object.getDescription());
            return builder.toSafeHtml();
        }
    };
    table.addColumn(descColumn, constants.templatesTableColumnSummary());
}

From source file:com.appspot.socialinquirer.client.view.PagesViewImpl.java

License:Apache License

/**
 * Inits the table columns./*from   www. j a v a2  s.c om*/
 *
 * @param table the table
 * @param selectionModel the selection model
 */
private void initTableColumns(CellTable<Page> table, final SelectionModel<Page> selectionModel) {
    // Checkbox column. This table will uses a checkbox column for
    // selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable
    // mouse selection.
    Column<Page, Boolean> checkColumn = new Column<Page, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(Page object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));

    // Name.
    Column<Page, String> nameColumn = new Column<Page, String>(new TextCell()) {
        @Override
        public String getValue(Page object) {
            return object.getName();
        }
    };
    table.addColumn(nameColumn, constants.templatesTableColumnName());
    // Headline.
    Column<Page, String> tagsColumn = new Column<Page, String>(new TextCell()) {
        @Override
        public String getValue(Page object) {
            StringBuilder builder = new StringBuilder();
            for (String tag : object.getTags()) {
                builder.append(tag).append(" ");
            }
            return builder.toString();

        }
    };
    table.addColumn(tagsColumn, constants.templatesTableColumnTags());
    // Description
    Column<Page, SafeHtml> descColumn = new Column<Page, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Page object) {
            SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendHtmlConstant(object.getDescription());
            return builder.toSafeHtml();
        }
    };
    table.addColumn(descColumn, constants.templatesTableColumnSummary());
}

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private SafeHtml createEmptyOption() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(fromTrustedString("<option value=''></option>"));

    return builder.toSafeHtml();
}

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private SafeHtml createOption(OptionItem item) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(fromTrustedString("<option value='")).appendEscaped(item.getValue())
            .append(fromTrustedString("'"));

    if (item.isSelected()) {
        builder.append(fromTrustedString(" selected"));
    }//w w w  .  j a v a 2 s.co  m

    if (item.isDisabled()) {
        builder.append(fromTrustedString(" disabled"));
    }

    builder.append(fromTrustedString(">")).appendEscaped(item.getText());
    builder.append(fromTrustedString("</option>"));

    return builder.toSafeHtml();
}

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private void rebuildResultItems(boolean init) {
    if (selectedItem != null) {
        selectedItem.toggleClass(css.chznDefault(), selectedValues.isEmpty());
    }/*from   w  w  w .j  a  va 2  s .  c  o m*/

    SafeHtmlBuilder content = new SafeHtmlBuilder();
    SafeHtmlBuilder optionsHtml = new SafeHtmlBuilder();

    selectedValues = new ArrayList<String>();

    for (SelectItem item : selectItems) {
        if (item.isGroup()) {
            SafeHtml result = resultAddGroup((GroupItem) item);
            if (result != null) {
                content.append(result);
            }
        } else {
            OptionItem optionItem = (OptionItem) item;

            if (optionItem.isEmpty()) {
                optionsHtml.append(createEmptyOption());
                continue;
            }

            if (customFilter) {
                optionsHtml.append(createOption(optionItem));
            }

            SafeHtml optionHtml = resultAddOption(optionItem);
            if (optionHtml != null) {
                content.append(optionHtml);
            }

            if (optionItem.isSelected()) {
                addChoice(optionItem);

                selectedValues.add(optionItem.getValue());
            }
        }
    }

    isDisabled = selectElement.isDisabled();
    if (isDisabled) {
        setupDisabledSearchField();
    } else {
        setupEnabledSearchField();
    }

    if (init) {
        showSearchFieldDefault(defaultText);
        searchFieldScale(fWidth);
    }
    if (customFilter) {
        // keep the html select element synchronized with the new result.
        $selectElement.html(optionsHtml.toSafeHtml().asString());
    }
    searchResults.html(content.toSafeHtml().asString());

    if (resultsShowing) {
        positionDropdownResult();
    }
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.DivDecoratorCell.java

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
    cell.render(context, value, cellBuilder);
    sb.append(template.outerDiv(outerDivClasses(context), outerDivPadding(context), cellBuilder.toSafeHtml()));
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.RenderedEditorCell.java

@Override
public void render(final Context context, final T value, SafeHtmlBuilder sb) {
    CellsResources.INSTANCE.tablecell().ensureInjected();
    String viewDataId = "";
    if (isEditing(context, null, value)) {
        final ViewData<T> viewData = getViewData(context.getKey());
        viewDataId = viewData.id;//from  w ww . j ava  2  s . c  o m
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (isEditing(context, null, value)) {
                    Element parent = Document.get().getElementById(viewData.id);
                    if (parent != null) {
                        parent.blur();
                        Element table = parent;
                        while (table != null && !"table".equalsIgnoreCase(table.getTagName())) {
                            table = table.getParentElement();
                        }
                        final Element table1 = table;
                        if (parent.getOwnerDocument() == Document.get()) {
                            startEditing(context, parent, table1.getParentElement(), value, viewData.updater,
                                    new Runnable() {

                                        public void run() {
                                            if (onEditorClose != null && table1 != null) {
                                                onEditorClose.closed(table1);
                                            }
                                        }

                                    });
                        }
                    }
                }
            }

        });
    }
    if (renderer == null || !renderer.render(context, viewDataId, value, sb)) {
        SafeHtmlBuilder content = new SafeHtmlBuilder();
        renderCell(context, value, content);
        sb.append(PaddedCell.INSTANCE.generate(viewDataId, CellsResources.INSTANCE.tablecell().padded(),
                new SafeStylesBuilder().padding(CELL_PADDING, Style.Unit.PX).toSafeStyles(),
                content.toSafeHtml()));
    }
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.TreeExpandableCell.java

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    if (treeProvider != null) {
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        cell.render(context, value, cellBuilder);
        int deepness = getDeepness(context);
        int outerDivPadding = indent * (deepness + 1);
        SafeStyles styles = new SafeStylesBuilder()
                .trustedNameAndValue("background-position", indent * deepness, Style.Unit.PX)
                .paddingLeft(outerDivPadding, Style.Unit.PX).position(Style.Position.RELATIVE)
                .height(100, Style.Unit.PCT).toSafeStyles();
        sb.append(template.outerDiv(outerDivClasses(context), styles, cellBuilder.toSafeHtml()));
    } else {/*from ww w  .  j  a  v a  2  s . co  m*/
        cell.render(context, value, sb);
    }
}