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.googlecode.mgwt.ui.client.widget.list.celllist.GroupingCellList.java

License:Apache License

/**
 * render a given set of models//from   w  w w  . ja va 2s  .  c o  m
 *
 * @param groups the model to render
 */
public void renderGroup(List<CellGroup<G, T>> groups) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();

    int count = 0;

    map.clear();
    modelMap.clear();

    int groupCounter = 0;
    int renderedGroups = 0;

    for (CellGroup<G, T> cellGroup : groups) {

        if (cellGroup.getMember().isEmpty()) {
            groupCounter++;
            continue;
        }

        // render header of group
        SafeHtmlBuilder headerBuilder = new SafeHtmlBuilder();
        header.render(headerBuilder, cellGroup.getGroup());

        sb.append(headerTemplate.li(headerBuilder.toSafeHtml(), this.groupAppearance.css().listHeadElement()));

        // render members of group
        List<T> models = cellGroup.getMember();
        for (T model : models) {
            SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();

            String clazz = this.groupAppearance.css().entry() + " ";
            if (cell.canBeSelected(model)) {
                clazz += this.groupAppearance.css().canbeSelected() + " ";
            }

            cell.render(cellBuilder, model);

            sb.append(entryTemplate.li(count, clazz, cellBuilder.toSafeHtml()));

            modelMap.put(count, model);

            count++;
        }

        map.put(renderedGroups, groupCounter);

        renderedGroups++;
        groupCounter++;

    }

    final String html = sb.toSafeHtml().asString();

    getElement().setInnerHTML(html);

    if (count > 0) {
        String innerHTML = getElement().getInnerHTML();
        if ("".equals(innerHTML.trim())) {
            fixBug(html);
        }
    }
}

From source file:com.googlecode.mgwt.ui.client.widget.list.celllist.GroupingCellList.java

License:Apache License

/**
 * render a header and return the value as html
 *
 * @param group the header to render//from   w  w  w  . j a  v a  2 s  . c o  m
 * @return the string value
 */
public String renderGroupHeader(G group) {
    SafeHtmlBuilder headerBuilder = new SafeHtmlBuilder();
    header.render(headerBuilder, group);
    return headerBuilder.toSafeHtml().asString();
}

From source file:com.gwtmodel.table.view.table.PresentationTable.java

License:Apache License

private SafeHtml getEmpty() {
    return new SafeHtmlBuilder().appendEscaped("").toSafeHtml();
}

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);//from ww w  .  java2s  . c o  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.InputDialog.java

License:Open Source License

public void setText(String string) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendEscapedLines(string);
    text.setInnerHTML(sb.toSafeHtml().asString());
}

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  2 s. 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(/*  w w w  .j  av  a2  s.  c  o  m*/
            "<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>");
    }
    builder.appendHtmlConstant("</table>");
    panel.setHTML(builder.toSafeHtml());
}

From source file:com.kk_electronic.kkportal.examples.modules.MotD.java

License:Open Source License

@Override
public void onSuccess(String result) {
    if (result != null) {
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        sb.appendEscapedLines(result);/*  ww w  .  j  a  v  a  2s.co m*/
        widget.setHTML(sb.toSafeHtml());
    } else {
        widget.setHTML("No message of the day");
    }
}

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

License:Open Source License

@Inject
public ScadaDataElementExample(IDataElementService scada) {
    /*//www  . j  a  va2  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.mgwt.imustlearn.client.ui.CellListWithButtons.java

License:Apache License

/**
 * Construct a celllist with a given cell and css
 *
 * @param cell the cell to use//from   w  w  w .ja  va  2 s.  c  o  m
 * @param css  the css to use
 */
public CellListWithButtons(JCell<T> cell, ListCss css, final CellButton... widgets) {
    //TODO change
    MGWTStyle.getTheme().getMGWTClientBundle().getButtonBarButtonCss().ensureInjected();

    hasWidgets = cell.hasWidgets();

    widgetsBuilder = new SafeHtmlBuilder();

    hasWidgets = (hasWidgets && (widgets.length > 0));

    if (hasWidgets) {

        buttons = widgets;

        for (int j = 0; j < widgets.length; j++) {

            final int finalJ = j;

            SafeStyles styles = new SafeStyles() {
                @Override
                public String asString() {
                    return "background-image:url(" + widgets[finalJ].getImageResource().getSafeUri().asString()
                            + ");float:right;";
                }
            };

            widgetsBuilder.append(WIDGET_TEMPLATE.div(j,
                    MGWTStyle.getTheme().getMGWTClientBundle().getButtonBarButtonCss().barButton(), styles,
                    ""));
        }
    }

    css.ensureInjected();
    this.cell = cell;
    this.css = css;
    main = new UlTouchWidget();

    initWidget(main);

    internalTouchHandler = new InternalTouchHandler();

    setStylePrimaryName(css.listCss());
}