Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString

Introduction

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

Prototype

public static SafeHtml fromTrustedString(String s) 

Source Link

Document

Returns a SafeHtml constructed from a trusted string, i.e., without escaping the string.

Usage

From source file:com.mvp4g.example.client.widgets.Mailboxes.java

License:Apache License

/**
 * Generates HTML for a tree item with an attached icon.
 *
 * @param imageProto the image prototype to use
 * @param title      the title of the item
 * @return the resultant HTML/*  w w  w . ja va 2 s  .  c om*/
 */
private SafeHtml imageItemHTML(ImageResource imageProto, String title) {
    return SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(imageProto).getHTML() + " " + title);
}

From source file:com.novartis.pcs.ontology.webapp.client.view.ActionIconCellDecorator.java

License:Apache License

private SafeHtml getImageHtml(ImageResource res, VerticalAlignmentConstant valign) {
    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());

    // Create the wrapper based on the vertical alignment.
    SafeStylesBuilder cssStyles = new SafeStylesBuilder().appendTrustedString(direction + ":0px;");
    if (HasVerticalAlignment.ALIGN_TOP == valign) {
        return templates.imageWrapperTop(cssStyles.toSafeStyles(), image);
    } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) {
        return templates.imageWrapperBottom(cssStyles.toSafeStyles(), image);
    } else {/*from  w  w w  . jav a 2 s .c o m*/
        int halfHeight = (int) Math.round(res.getHeight() / 2.0);
        cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;");
        return templates.imageWrapperMiddle(cssStyles.toSafeStyles(), image);
    }
}

From source file:com.novartis.pcs.ontology.webapp.client.view.HyperlinkCell.java

License:Apache License

@Override
public void render(Context context, InlineHyperlink h, SafeHtmlBuilder sb) {
    if (h != null) {
        sb.append(SafeHtmlUtils.fromTrustedString(h.toString()));
    }/*from  w w  w  .  j  a  va2 s.  c om*/
}

From source file:com.novartis.pcs.ontology.webapp.client.view.SearchResultsView.java

License:Apache License

@Override
public void onSearch(SearchEvent event) {
    final String pattern = event.getPattern();
    final Object source = event.getSource();
    lastPattern = pattern;/*from w  w w.j  a va2s . c  o  m*/

    if (source != null && busyIndicator == null && source instanceof Widget) {
        busyIndicator = new WidgetBusyIndicatorHandler((Widget) source, "busy-icon-left", "error-icon-left");
    }

    if (pattern != null && pattern.length() > 1) {
        if (busyIndicator != null) {
            busyIndicator.busy();
        }

        service.search(pattern, searchOptions.includeSynonyms(), new AsyncCallback<List<HTMLSearchResult>>() {
            public void onFailure(Throwable caught) {
                ul.clear();
                if (busyIndicator != null) {
                    busyIndicator.idle();
                }
                if (caught instanceof InvalidQuerySyntaxException) {
                    if (busyIndicator != null) {
                        busyIndicator.error();
                    }
                } else {
                    GWT.log("Failed to load search results", caught);
                    ErrorView.instance().onUncaughtException(caught);
                }
            }

            public void onSuccess(List<HTMLSearchResult> results) {
                if (pattern == lastPattern) {
                    String filterByOntology = searchOptions.filterByOntology();
                    ul.clear();
                    for (HTMLSearchResult result : results) {
                        if (filterByOntology == null || filterByOntology.equals(result.getOntology())) {
                            ListItem li = new ListItem();
                            InlineHyperlink hyperlink = new InlineHyperlink(
                                    SafeHtmlUtils.fromTrustedString(result.getHtml()), result.getReferenceId());
                            li.add(hyperlink);

                            if (filterByOntology == null) {
                                InlineLabel ontology = new InlineLabel(result.getOntology());
                                ontology.addStyleName("search-result-tag");
                                li.add(ontology);
                            }

                            if (result.isSynonym()) {
                                InlineLabel synonym = new InlineLabel("synonym");
                                synonym.addStyleName("search-result-tag");
                                li.add(synonym);
                            }

                            ul.add(li);
                        }
                    }
                } else {
                    GWT.log("Ignoring results from previous search: " + pattern);
                }
                if (busyIndicator != null) {
                    busyIndicator.idle();
                }
            }
        });
    } else {
        ul.clear();
    }
}

From source file:com.npisoft.officine.client.application.GridExample.java

License:sencha.com license

@Override
public Widget asWidget() {
    final NumberFormat number = NumberFormat.getFormat("0.00");

    ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50,
            SafeHtmlUtils.fromTrustedString("<b>Company</b>"));

    ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
    ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

    ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
    changeCol.setCell(new AbstractCell<Double>() {

        @Override/* www  . j a v  a  2  s . c  om*/
        public void render(Context context, Double value, SafeHtmlBuilder sb) {
            String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
            String v = number.format(value);
            sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
        }
    });

    ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
            "Last Updated");
    lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

    List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
    l.add(nameCol);
    l.add(symbolCol);
    l.add(lastCol);
    l.add(changeCol);
    l.add(lastTransCol);

    ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

    ListStore<Stock> store = new ListStore<Stock>(props.key());
    store.addAll(getStocks());

    root = new ContentPanel();

    // panel = new ();
    // panel.setCollapsible(true);
    // panel.setPixelSize(500, 400);
    // panel.addStyleName("margin-10");

    root.setHeadingText("Basic Grid");
    root.getHeader().setIcon(ExampleImages.INSTANCE.table());
    root.setPixelSize(600, 300);
    root.addStyleName("margin-10");

    //ToolButton info = new ToolButton(ToolButton.QUESTION);
    //ToolTipConfig config = new ToolTipConfig("Example Info",
    //   "This examples includes resizable panel, reorderable columns and grid state.");
    //config.setMaxWidth(225);
    //info.setToolTipConfig(config);
    // root.addTool(info);

    final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S);
    root.addExpandHandler(new ExpandHandler() {
        @Override
        public void onExpand(ExpandEvent event) {
            resizable.setEnabled(true);
        }
    });
    root.addCollapseHandler(new CollapseHandler() {
        @Override
        public void onCollapse(CollapseEvent event) {
            resizable.setEnabled(false);
        }
    });

    final Grid<Stock> grid = new Grid<Stock>(store, cm);
    grid.getView().setAutoExpandColumn(nameCol);
    grid.getView().setStripeRows(true);
    grid.getView().setColumnLines(true);
    grid.setBorders(false);

    grid.setColumnReordering(true);
    grid.setStateful(true);
    grid.setStateId("gridExample");

    GridStateHandler<Stock> state = new GridStateHandler<Stock>(grid);
    state.loadState();

    ToolBar toolBar = new ToolBar();
    toolBar.setEnableOverflow(false);
    // toolBar.add(new LabelToolItem("Selection Mode: "));

    BoxLayoutData flex = new BoxLayoutData(new Margins(0, 5, 0, 5));
    flex.setFlex(1);
    toolBar.add(new Label(), flex);

    TextButton btn0 = new TextButton();
    btn0.setIcon(ExampleImages.INSTANCE.add());
    btn0.setWidth(50);
    btn0.setToolTip("Ajouter");
    btn0.setIconAlign(IconAlign.TOP);
    toolBar.add(btn0);

    HelloWindowExample helloWindowExample = new HelloWindowExample();
    final Window window = (Window) helloWindowExample.asWidget();
    btn0.addSelectHandler(new SelectHandler() {
        @Override
        public void onSelect(SelectEvent event) {
            window.show();
        }
    });
    window.setData("open", btn0);

    TextButton btn2 = new TextButton();
    btn2.setIcon(ExampleImages.INSTANCE.delete0());
    btn2.setWidth(50);
    btn2.setToolTip("Supprimer");
    btn2.setIconAlign(IconAlign.TOP);
    toolBar.add(btn2);

    TextButton btn1 = new TextButton();
    btn1.setIcon(ExampleImages.INSTANCE.edit());
    btn1.setWidth(50);
    btn1.setToolTip("Editer");
    btn1.setIconAlign(IconAlign.TOP);
    toolBar.add(btn1);

    TextButton btn3 = new TextButton();
    btn3.setIcon(ExampleImages.INSTANCE.search());
    btn3.setWidth(50);
    btn3.setToolTip("Chercher");
    btn3.setIconAlign(IconAlign.TOP);
    toolBar.add(btn3);

    // toolBar.getToolTip().add

    SimpleComboBox<String> type = new SimpleComboBox<String>(new StringLabelProvider<String>());
    type.setTriggerAction(TriggerAction.ALL);
    type.setEditable(false);
    type.setWidth(100);
    type.add("Row");
    type.add("Cell");
    type.setValue("Row");
    // we want to change selection model on select, not value change which
    // fires on blur
    type.addSelectionHandler(new SelectionHandler<String>() {

        @Override
        public void onSelection(SelectionEvent<String> event) {
            boolean cell = event.getSelectedItem().equals("Cell");
            if (cell) {
                CellSelectionModel<Stock> c = new CellSelectionModel<Stock>();
                c.addCellSelectionChangedHandler(new CellSelectionChangedHandler<Stock>() {

                    @Override
                    public void onCellSelectionChanged(CellSelectionChangedEvent<Stock> event) {

                    }
                });

                grid.setSelectionModel(c);
            } else {
                grid.setSelectionModel(new GridSelectionModel<Stock>());
            }
        }
    });
    type.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {

        }
    });
    // toolBar.add(type);

    VerticalLayoutContainer con = new VerticalLayoutContainer();
    root.setWidget(con);
    // root.setHeaderVisible(false);

    con.add(toolBar, new VerticalLayoutData(1, -1));
    con.add(grid, new VerticalLayoutData(1, 1));
    // final PagingLoader<PagingLoadConfig, PagingLoadResult<Post>> loader =
    // new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>(
    // proxy);
    // loader.setRemoteSort(true);
    // loader.addLoadHandler(new
    // LoadResultListStoreBinding<PagingLoadConfig, Post,
    // PagingLoadResult<Post>>(store));

    final PagingToolBar pagingToolBar = new PagingToolBar(50);
    pagingToolBar.getElement().getStyle().setProperty("borderBottom", "none");
    // pagingToolBar.bind(loader);
    con.add(pagingToolBar, new VerticalLayoutData(1, -1));

    // needed to enable quicktips (qtitle for the heading and qtip for the
    // content) that are setup in the change GridCellRenderer
    new QuickTip(grid);

    return root;
}

From source file:com.npisoft.officine.client.application.referentiel.product.refofficine.edit.GridExample.java

License:sencha.com license

@Override
public Widget asWidget() {
    if (root == null) {
        final NumberFormat number = NumberFormat.getFormat("0.00");

        ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50,
                SafeHtmlUtils.fromTrustedString("<b>Company</b>"));

        ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
        ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

        ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
        changeCol.setCell(new AbstractCell<Double>() {

            @Override//from   w  w  w  .jav  a  2 s  .  com
            public void render(Context context, Double value, SafeHtmlBuilder sb) {
                String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
                String v = number.format(value);
                sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
            }
        });

        ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
                "Last Updated");
        lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

        List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
        l.add(nameCol);
        l.add(symbolCol);
        l.add(lastCol);
        l.add(changeCol);
        l.add(lastTransCol);
        ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

        ListStore<Stock> store = new ListStore<Stock>(props.key());
        store.addAll(TestData.getStocks());

        root = new ContentPanel();
        root.setHeaderVisible(false);
        root.setHeadingText("Basic Grid");
        root.getHeader().setIcon(ExampleImages.INSTANCE.table());
        root.setPixelSize(680, 300);
        root.addStyleName("margin-10");

        ToolButton info = new ToolButton(ToolButton.QUESTION);
        ToolTipConfig config = new ToolTipConfig("Example Info",
                "This examples includes resizable panel, reorderable columns and grid state.");
        config.setMaxWidth(225);
        info.setToolTipConfig(config);
        root.addTool(info);

        final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S);
        root.addExpandHandler(new ExpandHandler() {
            @Override
            public void onExpand(ExpandEvent event) {
                resizable.setEnabled(true);
            }
        });
        root.addCollapseHandler(new CollapseHandler() {
            @Override
            public void onCollapse(CollapseEvent event) {
                resizable.setEnabled(false);
            }
        });

        final Grid<Stock> grid = new Grid<Stock>(store, cm);
        grid.getView().setAutoExpandColumn(nameCol);
        grid.getView().setStripeRows(true);
        grid.getView().setColumnLines(true);
        grid.setBorders(false);

        grid.setColumnReordering(true);
        grid.setStateful(true);
        grid.setStateId("gridExample");

        GridStateHandler<Stock> state = new GridStateHandler<Stock>(grid);
        state.loadState();

        ToolBar toolBar = new ToolBar();
        toolBar.setEnableOverflow(false);
        toolBar.add(new LabelToolItem("Selection Mode: "));

        SimpleComboBox<String> type = new SimpleComboBox<String>(new StringLabelProvider<String>());
        type.setTriggerAction(TriggerAction.ALL);
        type.setEditable(false);
        type.setWidth(100);
        type.add("Row");
        type.add("Cell");
        type.setValue("Row");
        // we want to change selection model on select, not value change which fires on blur
        type.addSelectionHandler(new SelectionHandler<String>() {

            @Override
            public void onSelection(SelectionEvent<String> event) {
                boolean cell = event.getSelectedItem().equals("Cell");
                if (cell) {
                    CellSelectionModel<Stock> c = new CellSelectionModel<Stock>();
                    c.addCellSelectionChangedHandler(new CellSelectionChangedHandler<Stock>() {

                        @Override
                        public void onCellSelectionChanged(CellSelectionChangedEvent<Stock> event) {

                        }
                    });

                    grid.setSelectionModel(c);
                } else {
                    grid.setSelectionModel(new GridSelectionModel<Stock>());
                }
            }
        });
        type.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {

            }
        });
        toolBar.add(type);

        VerticalLayoutContainer con = new VerticalLayoutContainer();
        root.setWidget(con);

        //con.add(toolBar, new VerticalLayoutData(1, -1));
        con.add(grid, new VerticalLayoutData(1, 1));

        // needed to enable quicktips (qtitle for the heading and qtip for the
        // content) that are setup in the change GridCellRenderer
        new QuickTip(grid);
    }

    return root;
}

From source file:com.retech.reader.web.client.labs.LabsIconDecoratorCell.java

License:Apache License

@Override
public void render(final com.google.gwt.cell.client.Cell.Context context, final LabsIconDecorator value,
        final SafeHtmlBuilder sb) {
    if (value == null) {
        return;/*w ww  .  ja v a  2  s . c om*/
    }
    SafeHtml image = AbstractImagePrototype.create(value.getImage()).getSafeHtml();
    SafeHtml link = SafeHtmlUtils.fromTrustedString(value.getTitle());
    sb.append(template.put(image, link, LabsResources.css().cellItemLeftDiv()));

}

From source file:com.ritchey.athleticEventManage.client.ui.ClickTextCell.java

License:Apache License

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {

    if (value != null) {// 
        String x = "";
        if (clazz != null) {
            x = " class='" + clazz + "' ";
        }/*from   w  w w .  j  a  v a 2 s .  c o m*/
        SafeHtml html = SafeHtmlUtils.fromTrustedString("<div" + x + ">" + value + "</div>" + "");
        sb.append(html);
    }

}

From source file:com.ritchey.athleticEventManage.client.ui.HyperlinkCell.java

License:Apache License

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, Hyperlink value, SafeHtmlBuilder sb) {
    sb.append(SafeHtmlUtils.fromTrustedString(value.toString()));
}

From source file:com.ritchey.attendance.client.view.ClickImageCell.java

License:Apache License

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {

    if (value != null) {// 
        SafeHtml html = SafeHtmlUtils.fromTrustedString(
                "<div style='background:lightgray; min-height: 128px; max-width: 128px; min-width: 128px; text-align: center;'><img alt='No Photo Available' style='vertical-align: middle; width: 128px; height: 128px;' src='"
                        + value + "' /></div>" + "");
        sb.append(html);//from  www .  j  a  v  a 2s  . com
    }

}