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:gwt.material.design.client.base.helper.CodeHelper.java

License:Apache License

public static SafeHtml parseCode(String code) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    String[] splitted = code.replaceAll("\\\\s", " ").split("\\\\n\\s?");
    String[] arr$ = splitted;//from  w w w.j  a v a 2s  .  c  om
    int len$ = splitted.length;

    for (int i$ = 0; i$ < len$; ++i$) {
        String s = arr$[i$];
        builder.append(SafeHtmlUtils.fromTrustedString(SafeHtmlUtils.htmlEscapeAllowEntities(s)));
        builder.appendHtmlConstant("<br>");
    }

    return builder.toSafeHtml();
}

From source file:gwt.material.design.client.data.BaseRenderer.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public TableData drawColumn(TableRow row, Context context, T rowValue, Column<T, ?> column, int beforeIndex,
        boolean visible) {
    TableData data = null;/*from w w w.  j  a  v a  2 s .c o  m*/
    if (row != null && rowValue != null) {
        data = row.getColumn(beforeIndex);
        if (data == null) {
            data = new TableData();
            row.insert(data, beforeIndex);
        } else {
            data.clear();
        }

        Div wrapper = new Div();

        // Render the column cell
        if (column instanceof WidgetColumn) {
            wrapper.setStyleName(TableCssName.WIDGET_CELL);
            wrapper.add(((WidgetColumn) column).render(context, rowValue));
        } else {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            column.render(context, rowValue, sb);
            wrapper.getElement().setInnerHTML(sb.toSafeHtml().asString());
            wrapper.setStyleName(TableCssName.CELL);
        }

        data.add(wrapper);

        data.setId("col" + beforeIndex);
        data.setDataTitle(column.getName());
        HideOn hideOn = column.getHideOn();
        if (hideOn != null) {
            data.setHideOn(hideOn);
        }
        TextAlign textAlign = column.getTextAlign();
        if (textAlign != null) {
            data.setTextAlign(textAlign);
        }
        if (column.isNumeric()) {
            data.addStyleName(TableCssName.NUMERIC);
        }

        // Apply the style properties
        Style style = data.getElement().getStyle();
        Map<StyleName, String> styleProps = column.getStyleProperties();
        if (styleProps != null) {
            styleProps.forEach((s, v) -> style.setProperty(s.styleName(), v));
        }

        // Hide if defined as not visible
        // This can be the case when a header is toggled off.
        if (!visible) {
            data.$this().hide();
        }
    }
    return data;
}

From source file:gwtquery.plugins.droppable.client.celltablesample.CellTableSample.java

License:Apache License

/**
 * This method create the CellTable for the contacts
 */// www .j a  v  a2  s.  c  o m
private void createDragAndDropCellTable() {

    // Create a DragAndDropCellTable.
    cellTable = new DragAndDropCellTable<ContactInfo>(ContactDatabase.ContactInfo.KEY_PROVIDER);
    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    // Add a selection model so we can select cells.
    final MultiSelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>(
            ContactDatabase.ContactInfo.KEY_PROVIDER);
    cellTable.setSelectionModel(selectionModel);

    // Attach a column sort handler to the ListDataProvider to sort the list.
    ListHandler<ContactInfo> sortHandler = new ListHandler<ContactInfo>(
            ContactDatabase.get().getDataProvider().getList());
    cellTable.addColumnSortHandler(sortHandler);

    // Initialize the columns.
    initTableColumns(selectionModel, sortHandler);

    // Add the CellList to the adapter in the database.
    ContactDatabase.get().addDataDisplay(cellTable);

    // fill the helper when the drag operation start
    cellTable.addDragStartHandler(new DragStartEventHandler() {

        public void onDragStart(DragStartEvent event) {
            ContactInfo contact = event.getDraggableData();
            Element helper = event.getHelper();
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            // reuse the contact cell to render the inner html of the drag helper.
            new ContactCell(Resource.INSTANCE.contact()).render(null, contact, sb);
            helper.setInnerHTML(sb.toSafeHtml().asString());

        }
    });

}

From source file:gwtquery.plugins.droppable.client.datagridsample.DataGridSample.java

License:Apache License

/**
 * This method create the DataGrid for the contacts
 *//*w w  w  .j av  a  2  s. co m*/
private void createDragAndDropDataGrid() {

    // Create a DragAndDropDataGrid.
    dataGrid = new DragAndDropDataGrid<ContactInfo>(20, ContactDatabase.ContactInfo.KEY_PROVIDER);
    // Create a Pager to control the table.
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(dataGrid);

    // Add a selection model so we can select cells.
    final MultiSelectionModel<ContactInfo> selectionModel = new MultiSelectionModel<ContactInfo>(
            ContactDatabase.ContactInfo.KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    // Attach a column sort handler to the ListDataProvider to sort the list.
    ListHandler<ContactInfo> sortHandler = new ListHandler<ContactInfo>(
            ContactDatabase.get().getDataProvider().getList());
    dataGrid.addColumnSortHandler(sortHandler);

    // Initialize the columns.
    initTableColumns(selectionModel, sortHandler);

    // Add the CellList to the adapter in the database.
    ContactDatabase.get().addDataDisplay(dataGrid);

    // fill the helper when the drag operation start
    dataGrid.addDragStartHandler(new DragStartEventHandler() {

        public void onDragStart(DragStartEvent event) {
            ContactInfo contact = event.getDraggableData();
            Element helper = event.getHelper();
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            // reuse the contact cell to render the inner html of the drag helper.
            new ContactCell(Resource.INSTANCE.contact()).render(null, contact, sb);
            helper.setInnerHTML(sb.toSafeHtml().asString());

        }
    });

}

From source file:io.pelle.mango.client.gwt.modules.dictionary.controls.SuggestionWrapper.java

License:Open Source License

@Override
public String getDisplayString() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    HtmlUtils.highlightTexts(text, suggestion.getLabel(), sb);
    return sb.toSafeHtml().asString();
}

From source file:io.pelle.mango.client.gwt.modules.dictionary.search.DictionarySearchResultModuleUI.java

License:Open Source License

public void showResults(List<SearchResultItem> result) {

    if (resultContainer != null) {
        resultContainer.removeFromParent();
    }/*from   ww w . j  a  v a  2s  .  c o m*/

    resultContainer = new Div();
    container.add(resultContainer);
    resultContainer.addStyleName(DICTIONARY_SEARCH_RESULT_PANEL_STYLE);

    if (result.size() == 0) {
        Div noSearchResults = new Div();
        noSearchResults.add(new HTML(MangoClientWeb.getInstance().getMessages().noSearchResults()));
        resultContainer.add(noSearchResults);
    } else {
        for (final SearchResultItem searchResultItem : result) {

            IDictionaryModel dictionaryModel = DictionaryModelProvider
                    .getDictionary(searchResultItem.getDictionaryId());

            Div resultItemContainer = new Div();
            resultItemContainer.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_PANEL_STYLE);

            Hyperlink title = new Hyperlink();
            title.setText(DictionaryUtil.getLabel(dictionaryModel) + ": " + searchResultItem.getLabel());

            title.addHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    DictionaryEditorModuleFactory.openEditorForId(searchResultItem.getDictionaryId(),
                            searchResultItem.getId());
                }
            }, ClickEvent.getType());

            title.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_TITLE_STYLE);
            resultItemContainer.add(title);

            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            boolean first = true;

            for (Map.Entry<String, String> attributeEntry : searchResultItem.getAttributes().entrySet()) {

                Optional<IBaseControlModel> baseControlModel = DictionaryModelQuery.create(dictionaryModel)
                        .getControls().getControlModelByAttributePath(attributeEntry.getKey());

                if (baseControlModel.isPresent()) {

                    if (!first) {
                        sb.appendHtmlConstant(", ");
                    }
                    first = false;

                    sb.appendHtmlConstant(DictionaryModelUtil.getColumnLabel(baseControlModel.get()));
                    sb.appendHtmlConstant(": ");
                    HtmlUtils.highlightTexts(getModule().getSearchText(), attributeEntry.getValue(), sb);
                }
            }

            HTML text = new HTML(sb.toSafeHtml());
            text.addStyleName(DICTIONARY_SEARCH_RESULT_ITEM_TEXT_STYLE);
            resultItemContainer.add(text);

            resultContainer.add(resultItemContainer);
        }
    }
}

From source file:net.cbtltd.client.field.table.ActionCell.java

License:Apache License

/**
 * Construct a new {@link ActionCell}.//from   w ww .ja  va2 s .com
 *
 * @param message the message to display on the button
 * @param delegate the delegate that will handle events
 */
public ActionCell(SafeHtml message, String style, Delegate<C> delegate) {
    super("click", "keydown");
    this.delegate = delegate;
    this.html = new SafeHtmlBuilder()
            .appendHtmlConstant("<button class='" + style + "' type=\"button\" tabindex=\"-1\">")
            .append(message).appendHtmlConstant("</button>").toSafeHtml();
}

From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java

License:Open Source License

public void addText(String textString) {
    HTML html = new HTML(new SafeHtmlBuilder().appendEscapedLines(textString).toSafeHtml());
    getActivePanel().add(html);//from   w  w  w. j  a v a2 s  . c  om
}

From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java

License:Open Source License

public HTML addHtmlText(String textString, String styleName) {
    HTML html = new HTML(new SafeHtmlBuilder().appendHtmlConstant(textString).toSafeHtml());
    if (styleName != null && !styleName.isEmpty()) {
        html.addStyleName(styleName);// w w w. j a va2  s .c o m
    }
    getActivePanel().add(html);
    return html;
}

From source file:nl.mpi.tg.eg.experiment.client.view.ComplexView.java

License:Open Source License

public void addLink(String label, final String target) {
    final Anchor anchor = new Anchor(new SafeHtmlBuilder().appendEscapedLines(label).toSafeHtml());
    // this link relies on the org.apache.cordova.inappbrowser which offers secure viewing of external html pages and handles user navigation such as back navigation.
    // in this case the link will be opend in the system browser rather than in the cordova application.
    getActivePanel().add(anchor);/* w w  w  .  jav  a  2 s .co m*/
    final SingleShotEventListner singleShotEventListner = new SingleShotEventListner() {

        @Override
        protected void singleShotFired() {
            Window.open(target, "_system", "");
        }
    };
    anchor.addClickHandler(singleShotEventListner);
    anchor.addTouchStartHandler(singleShotEventListner);
    anchor.addTouchMoveHandler(singleShotEventListner);
    anchor.addTouchEndHandler(singleShotEventListner);
    anchor.addStyleName("pageLink");
}