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:com.jitlogic.zico.client.views.traces.TraceDetailCell.java

License:Open Source License

@Override
public void render(Context context, TraceInfo ti, SafeHtmlBuilder sb) {
    if (ti.getAttributes() != null) {
        sb.appendHtmlConstant("<table border=\"0\" cellspacing=\"2\"><tbody>");
        for (KeyValuePair e : ti.getAttributes()) {
            sb.appendHtmlConstant("<tr><td align=\"right\" style=\"color:blue; font-size: small;\"><b>");
            sb.append(SafeHtmlUtils.fromString(e.getKey()));
            sb.appendHtmlConstant(//from w  w w.ja va 2  s .c om
                    "</b></td><td><div style=\"text-wrap: unrestricted; white-space: pre; word-wrap: break-word; font-size: small;\">");
            sb.append(SafeHtmlUtils.fromString(e.getValue() != null ? e.getValue().toString() : ""));
            sb.appendHtmlConstant("</div></td></tr>");
        }
        sb.appendHtmlConstant("</tbody></table>");
    }
    if (ti.getExceptionInfo() != null) {
        SymbolicExceptionInfo e = ti.getExceptionInfo();
        sb.appendHtmlConstant("<div><span style=\"color: red;\">");
        sb.append(SafeHtmlUtils.fromString("Caught: " + e.getExClass()));
        sb.appendHtmlConstant("</span></div><div><b>");
        sb.append(SafeHtmlUtils.fromString("" + e.getMessage()));
        sb.appendHtmlConstant("</b></div>");
        int i = 0;
        for (String s : e.getStackTrace()) {
            sb.appendHtmlConstant("<div>");
            sb.append(SafeHtmlUtils.fromString("" + s));
            sb.appendHtmlConstant("</div>");
            i++;
            if (i > 5) {
                sb.appendHtmlConstant("<div>");
                sb.append(SafeHtmlUtils
                        .fromString("...      (open trace attributes window to see full stack trace)"));
                sb.appendHtmlConstant("</div>");
                break;
            }

        }
    }
}

From source file:com.jitlogic.zico.client.widgets.NanoTimeRenderingCell.java

License:Open Source License

@Override
public void render(Context context, Long time, SafeHtmlBuilder sb) {
    sb.appendHtmlConstant("<span>");
    sb.append(SafeHtmlUtils.fromString(ClientUtil.formatDuration(time)));
    sb.appendHtmlConstant("</span>");
}

From source file:com.jitlogic.zico.widgets.client.SelectCell.java

License:Open Source License

@Override
public void render(Context context, V value, SafeHtmlBuilder sb) {
    Object key = context.getKey();
    V viewData = getViewData(key);/*from   w  ww  .  java2s  . c o  m*/
    if (viewData != null && viewData.equals(value)) {
        clearViewData(key);
        viewData = null;
    }

    V selected = viewData == null ? value : viewData;

    sb.appendHtmlConstant("<select tabindex=\"-1\">");

    for (int i = 0; i < options.size(); i++) {
        V val = values.get(i);
        T opt = options.get(i);
        if (selected != null && selected.equals(val)) {
            sb.append(template.selectedOption("" + val, "" + opt));
        } else {
            sb.append(template.option("" + val, "" + opt));
        }
    }

    sb.appendHtmlConstant("</select>");
}

From source file:com.kk_electronic.kkportal.core.security.IdentityProvider.java

License:Open Source License

private SafeHtml getDialogText() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    if (motd != null) {
        sb.appendEscapedLines(motd);/* w  w w  .java  2s  . co  m*/
        sb.appendHtmlConstant("<br /><br />");
    }
    if (errortext != null) {
        sb.appendHtmlConstant("<span style=\"color:#C4151B;\"><br />");
        sb.appendEscapedLines(errortext);
        sb.appendHtmlConstant("<br /><br /></span>");
    }
    sb.appendEscapedLines(dialogtext);
    return sb.toSafeHtml();
}

From source file:com.kk_electronic.kkportal.core.ui.LogoutLink.java

License:Open Source License

private void setIdentity(Identity identity) {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    html.appendHtmlConstant("Logout");
    if (identity != null) {
        html.appendHtmlConstant(" ");
        html.appendEscaped(identity.toString());
    }//from  w  ww . jav  a 2s  .  co  m
    anchor.setHTML(html.toSafeHtml());
}

From source file:com.kk_electronic.kkportal.core.util.DebugPanel.java

License:Open Source License

private static void updatelog() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendEscaped("Raw log");
    builder.appendHtmlConstant(
            "<table><tr><th>Time</th><th>Sub System</th><th>Group Key</th><th>Type</th></tr>");
    for (MetricInfo i : infos) {
        builder.appendHtmlConstant("<tr><td>");
        builder.append((long) (i.getMillis() - start));
        builder.appendHtmlConstant("</td><td>");
        builder.appendEscaped(i.getSubSystem());
        builder.appendHtmlConstant("</td><td>");
        builder.appendEscaped(i.getEvtGroup());
        builder.appendHtmlConstant("</td><td>");
        builder.appendEscaped(i.getType());
        builder.appendHtmlConstant("</td></tr>");
    }/*  w  w w . j a v a2  s.com*/
    builder.appendHtmlConstant("</table>");
    panel.setHTML(builder.toSafeHtml());
}

From source file:com.kk_electronic.kkportal.scada.ScadaDataElementExample.java

License:Open Source License

@Inject
public ScadaDataElementExample(IDataElementService scada) {
    /*//from   w w w  .  j  a  v a  2  s.c om
     * All rpc calls are asynchronous since we must not halt the ui while
     * fetching data.
     */
    AsyncCallback<Result<List<DataElementValue>>> callback = new AsyncCallback<Result<List<DataElementValue>>>() {

        @Override
        public void onSuccess(Result<List<DataElementValue>> result) {
            /**
             * We create a SafeHtmlBuilder to create the new HTML of label
             * The result is similar to this:
             * 
             * <pre>
             * Current W=48.8[A]
             * Frequence=49.928[Hz]
             * Gearoil temperature=46.5[C]
             * </pre>
             */
            SafeHtmlBuilder sb = new SafeHtmlBuilder();

            /**
             * This is an example of the json that gets transferred from
             * scada. While not nessesary to know it helps to understand the
             * structure
             * 
             * <pre>
             * {
             *   "Errors": null, 
             *   "TotalResults": 37, 
             *   "Result": [
             *     {
             *       "StationGUID": "b64af73e-5f2c-464b-addf-7912542ccdf0", 
             *       "ElementName": null, 
             *       "RepresentationGUID": "cfd108bf-557f-4103-9176-1895bacda8b5", 
             *       "TimeStamp": "0001-01-01 00:00:00.0000000", 
             *       "Value": "N/M", 
             *       "MappingName": "DCLink voltage", 
             *       "ElementFullName": null, 
             *       "MappingGUID": "fd8e1338-e210-428d-9c54-1d3baca9426c", 
             *       "Units": null, 
             *       "ElementGUID": "00000000-0000-0000-0000-000000000000", 
             *       "EnumValueName": null
             *     },
             *     ...
             * }
             * </pre>
             * 
             * The {@link com.kk_electronic.kkportal.scada.dto.Result<T>}
             * object corresponds to the outermost element in the json, and
             * the Result element is a List<DataElementValue>
             */

            // Iteration is done over the results
            for (DataElementValue i : result.Result) {
                //If we have both a name and a value we add it as name=value
                if (i.MappingName != null && i.Value != null) {
                    sb.appendEscaped(i.MappingName);
                    sb.append('=');
                    sb.appendEscaped(i.Value);
                    //We optionally appends the unit if defined as [unit]
                    if (i.Units != null) {
                        sb.append('[').appendEscaped(i.Units).append(']');
                    }
                    sb.appendHtmlConstant("<br />");
                }
            }
            //and finally we update the label to contain the result
            label.setHTML(sb.toSafeHtml());
        }

        @Override
        public void onFailure(Throwable caught) {
            // If the call failed we simply notify the user
            label.setText("Call failed");
        }
    };
    /*
     * When calling the server, we add some parameters it expect, and use our previous callback.
     * as a special note here we have stripped UserKey from the interface. That responsibility is delegated to another class.
     * For more info read the documentation on the interface
     */
    scada.GetDataElementValue("b64af73e-5f2c-464b-addf-7912542ccdf0", "0",
            "EBABF07A-99A7-41ec-8E90-8C65D79CDB67,A250597F-5768-445f-A668-0D97C054A32A,4E50A845-A86F-486a-901A-E6FC2AF3C2B1,F9C1415D-BDDC-4343-B421-9F9BAE96A781,6E5FFB7E-31BB-4561-A57D-652E2805C50D,A3DED774-054D-40ef-BD5D-EBC668F5E3E4,1BBC05FD-EBD6-4738-995D-DC41947636D0,DC8BC9EF-91FA-4c39-9469-CA69FA7ACB3E,625F01B9-7302-4cc1-8010-A3446C343848,FD8E1338-E210-428d-9C54-1D3BACA9426C,EA65A1AB-2952-43d1-A5AD-F06B95E49EFC,1C855DE9-75D7-425c-A8EF-3974385A2358,65cbd39b-37d5-471e-8bb4-147bbe9ec332,E27B096C-CD76-44ad-9A4E-A190F998F0E2,03C237CF-C1C4-413f-B951-938A58AA78F8,9DFC4A73-29CB-47bb-8F9C-2DD625F390C6,6D51F747-365D-46b1-AD01-9CB9FE2670AF,6720db90-f5d6-4df6-9f85-de3420adeafc,A52D2DB1-8848-40ec-9C79-3880B0AF1171,2EF819D3-88E0-468d-97D4-21AACF2FC996,8DAA0769-7E3D-4d24-B724-C3BBD3BD3A5B,A7DFBF40-466A-4df9-ABE1-2C2C8BF0EFD0,FB086AFF-A4D5-4675-B97F-EF16BCC2B552,bb00d11f-1546-4324-995d-5cf4a19a1a06,7d217e48-2eb0-4ea8-bd08-9c4cd1e0deb3,4C6B8768-D939-4225-A427-5873C4F637F8,FC10A518-DD88-425c-88C0-5598E1EEAEE1,9a9258af-e920-4bf4-a97f-fee506aa86e7,474cf253-92c5-4692-8f01-008c642b15e8,9A1B8AF3-1812-4e78-A6E2-EA2E5ED6B89B,A1F846F2-F6C4-42a1-9B6E-88859F9EE3B9,00b34192-7885-4b9f-a50f-fa96a4a05f42,9A0FC960-8794-437f-9B7F-AFCDC5A402C3,4E5E3FA9-A341-440f-B9DF-6DAF85000CE3,b987d0d8-b0b8-4658-9a34-747c9a74fa99,c1c2bbc0-becf-4efc-b1c1-5003d5c92864,073f1e92-081b-41d7-b061-0b67b1763870",
            null, null, false, callback);
}

From source file:com.laskysoftware.GXTPagingGrid.client.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, "Company");
        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.java 2  s. c o  m
            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.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);

        new Resizable(root, Dir.E, Dir.SE, Dir.S);

        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.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.laskysoftware.GXTPagingGrid.client.GridExampleLocking.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//w  w w .ja  v  a 2s .c  o  m
            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, ?>>();
        //Remove name from main set of columns
        //l.add(nameCol);
        l.add(symbolCol);
        l.add(lastCol);
        l.add(changeCol);
        l.add(lastTransCol);

        //create two column models, one for the locked section
        ColumnModel<Stock> lockedCm = new ColumnModel<Stock>(
                Collections.<ColumnConfig<Stock, ?>>singletonList(nameCol));
        ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

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

        root = new ContentPanel();
        root.setHeadingText("Locked Grid Sample");
        root.setPixelSize(600, 300);

        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);
            }
        });

        //locked grid
        final Grid<Stock> lockedGrid = new Grid<Stock>(store, lockedCm) {
            @Override
            protected Size adjustSize(Size size) {
                //this is a tricky part - convince the grid to draw just slightly too wide
                //and so push the scrollbar out of sight
                return new Size(size.getWidth() + XDOM.getScrollBarWidth() - 1, size.getHeight());
            }
        };
        lockedGrid.setView(new GridView<Stock>() {
            {
                this.scrollOffset = 0;
            }
        });
        //require columns to always fit, preventing scrollbar
        lockedGrid.getView().setForceFit(true);

        //main grid, with horiz scrollbar
        final Grid<Stock> grid = new Grid<Stock>(store, cm);
        //don't want this feature, want to encourage horizontal scrollbars
        //grid.getView().setAutoExpandColumn(nameCol);
        grid.getView().setStripeRows(true);
        grid.getView().setColumnLines(true);
        grid.setBorders(false);

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

        //link scrolling
        lockedGrid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                grid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });
        grid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                lockedGrid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });

        HorizontalLayoutContainer gridWrapper = new HorizontalLayoutContainer();
        root.setWidget(gridWrapper);

        //add locked column, only 300px wide (in this example, use layouts to change how this works
        HorizontalLayoutData lockedColumnLayoutData = new HorizontalLayoutData(300, 1.0);

        //this is optional - without this, you get a little offset issue at the very bottom of the non-locked grid
        lockedColumnLayoutData.setMargins(new Margins(0, 0, XDOM.getScrollBarWidth(), 0));

        gridWrapper.add(lockedGrid, lockedColumnLayoutData);

        //add non-locked section, taking up all remaining width
        gridWrapper.add(grid, new HorizontalLayoutData(1.0, 1.0));
    }

    return root;
}

From source file:com.msco.mil.client.com.sencha.gxt.desktopapp.client.spreadsheet.SpreadsheetViewImpl.java

License:sencha.com license

private Cell<String> getDisplayCell() {
    if (displayCell == null) {
        displayCell = new AbstractCell<String>() {
            @Override//from   ww  w . ja v  a  2  s.  c  o m
            public void render(Context context, String value, SafeHtmlBuilder sb) {
                if (value != null) {
                    if (value.startsWith(Evaluator.EXPRESSION_MARKER)) {
                        double result = getWorksheet().evaluateCell(value, context.getIndex(),
                                context.getColumn());
                        String formattedResult = getDefaultNumberFormat().format(result);
                        sb.appendHtmlConstant("<b>" + formattedResult + "</b>");
                    } else {
                        sb.appendEscaped(value);
                    }
                }
            }
        };
    }
    return displayCell;
}