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.google.gwt.sample.expenses.client.MobileReportList.java

License:Apache License

public MobileReportList(final Listener listener, final ExpensesRequestFactory requestFactory,
        EmployeeProxy employee) {/*from   www.  j av  a2 s  . com*/
    this.listener = listener;
    this.requestFactory = requestFactory;
    this.employee = employee;

    EntityProxyKeyProvider<ReportProxy> keyProvider = new EntityProxyKeyProvider<ReportProxy>();

    reportDataProvider = new AsyncDataProvider<ReportProxy>(keyProvider) {
        @Override
        protected void onRangeChanged(HasData<ReportProxy> view) {
            requestReports();
        }
    };

    reportList = new CellList<ReportProxy>(new AbstractCell<ReportProxy>() {
        @Override
        public void render(Context context, ReportProxy value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div class='item'>");
            sb.appendEscaped(value.getPurpose());
            sb.appendHtmlConstant("</div>");
        }
    });
    reportList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

    reportSelection = new NoSelectionModel<ReportProxy>(keyProvider);
    reportSelection.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            listener.onReportSelected(reportSelection.getLastSelectedObject());
        }
    });

    reportList.setSelectionModel(reportSelection);
    reportDataProvider.addDataDisplay(reportList);

    initWidget(reportList);
    onRefresh(false);
}

From source file:com.google.gwt.sample.showcase.client.content.cell.ContactTreeViewModel.java

License:Apache License

public ContactTreeViewModel(final SelectionModel<ContactInfo> selectionModel) {
    this.selectionModel = selectionModel;
    if (images == null) {
        images = GWT.create(Images.class);
    }//from w  ww . ja  va2  s. c om

    // Create a data provider that provides categories.
    categoryDataProvider = new ListDataProvider<Category>();
    List<Category> categoryList = categoryDataProvider.getList();
    for (Category category : ContactDatabase.get().queryCategories()) {
        categoryList.add(category);
    }

    // Construct a composite cell for contacts that includes a checkbox.
    List<HasCell<ContactInfo, ?>> hasCells = new ArrayList<HasCell<ContactInfo, ?>>();
    hasCells.add(new HasCell<ContactInfo, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, false);

        public Cell<Boolean> getCell() {
            return cell;
        }

        public FieldUpdater<ContactInfo, Boolean> getFieldUpdater() {
            return null;
        }

        public Boolean getValue(ContactInfo object) {
            return selectionModel.isSelected(object);
        }
    });
    hasCells.add(new HasCell<ContactInfo, ContactInfo>() {

        private ContactCell cell = new ContactCell(images.contact());

        public Cell<ContactInfo> getCell() {
            return cell;
        }

        public FieldUpdater<ContactInfo, ContactInfo> getFieldUpdater() {
            return null;
        }

        public ContactInfo getValue(ContactInfo object) {
            return object;
        }
    });
    contactCell = new CompositeCell<ContactInfo>(hasCells) {
        @Override
        public void render(Context context, ContactInfo value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            // Return the first TR element in the table.
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Context context, ContactInfo value, SafeHtmlBuilder sb,
                HasCell<ContactInfo, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            sb.appendHtmlConstant("<td>");
            cell.render(context, hasCell.getValue(value), sb);
            sb.appendHtmlConstant("</td>");
        }
    };
}

From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java

License:Apache License

/**
 * Create the list of Contacts./*from  ww w  .  ja v a 2 s  .c om*/
 * 
 * @param images the {@link Images} used in the Contacts
 * @return the list of contacts
 */
@ShowcaseSource
private Widget createContactsItem(Images images) {
    // Create a popup to show the contact info when a contact is clicked
    HorizontalPanel contactPopupContainer = new HorizontalPanel();
    contactPopupContainer.setSpacing(5);
    contactPopupContainer.add(new Image(images.defaultContact()));
    final HTML contactInfo = new HTML();
    contactPopupContainer.add(contactInfo);
    final PopupPanel contactPopup = new PopupPanel(true, false);
    contactPopup.setWidget(contactPopupContainer);

    // Create the list of contacts
    VerticalPanel contactsPanel = new VerticalPanel();
    contactsPanel.setSpacing(4);
    String[] contactNames = constants.cwStackLayoutPanelContacts();
    String[] contactEmails = constants.cwStackLayoutPanelContactsEmails();
    for (int i = 0; i < contactNames.length; i++) {
        final String contactName = contactNames[i];
        final String contactEmail = contactEmails[i];
        final Anchor contactLink = new Anchor(contactName);
        contactsPanel.add(contactLink);

        // Open the contact info popup when the user clicks a contact
        contactLink.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // Set the info about the contact
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendEscaped(contactName);
                sb.appendHtmlConstant("<br><i>");
                sb.appendEscaped(contactEmail);
                sb.appendHtmlConstant("</i>");
                contactInfo.setHTML(sb.toSafeHtml());

                // Show the popup of contact info
                int left = contactLink.getAbsoluteLeft() + 14;
                int top = contactLink.getAbsoluteTop() + 14;
                contactPopup.setPopupPosition(left, top);
                contactPopup.show();
            }
        });
    }
    return new SimplePanel(contactsPanel);
}

From source file:com.google.javascript.jscomp.debugger.gwt.DebuggerGwtMain.java

License:Apache License

private void createCheckboxes(CellPanel checkboxPanel) {
    for (CompilationParam.ParamGroup group : CompilationParam.ParamGroup.values()) {
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant("<b>");
        builder.appendEscaped(group.name);
        builder.appendHtmlConstant("</b>");

        checkboxPanel.add(new HTML(builder.toSafeHtml()));
        for (final CompilationParam param : CompilationParam.getGroupedSortedValues().get(group)) {
            CheckBox cb = new CheckBox(param.toString());
            if (param.getJavaInfo() != null) {
                cb.setTitle("Java API equivalent: " + param.getJavaInfo());
            }/*from   www. j  av  a2 s  . com*/
            cb.setValue(param.getDefaultValue());
            param.apply(options, param.getDefaultValue());
            cb.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    boolean checked = ((CheckBox) event.getSource()).getValue();
                    param.apply(options, checked);
                    doCompile();
                }
            });
            checkboxPanel.add(cb);
        }
    }
}

From source file:com.google.maps.gwt.samples.basics.client.MapCoordinates.java

License:Apache License

private String createInfoWindowContent() {
    int numTiles = 1 << (int) map.getZoom();
    MercatorProjection projection = new MercatorProjection();
    Point worldCoordinate = projection.fromLatLngToPoint(CHICAGO);
    Point pixelCoordinate = Point.create(worldCoordinate.getX() * numTiles, worldCoordinate.getY() * numTiles);
    Point tileCoordinate = Point.create(Math.floor(pixelCoordinate.getX() / TILE_SIZE),
            Math.floor(pixelCoordinate.getY() / TILE_SIZE));

    SafeHtmlBuilder returnString = new SafeHtmlBuilder();
    returnString.appendHtmlConstant("Chicago, IL<br>");
    returnString.appendHtmlConstant("LatLng: ");
    returnString.append(CHICAGO.lat());//from  w  ww . j  a va2 s . c om
    returnString.appendHtmlConstant(", ");
    returnString.append(CHICAGO.lng());
    returnString.appendHtmlConstant("<br />");
    returnString.appendHtmlConstant("World Coordinate: ");
    returnString.append(worldCoordinate.getX());
    returnString.appendHtmlConstant(", ");
    returnString.append(worldCoordinate.getY());
    returnString.appendHtmlConstant("<br />");

    returnString.appendHtmlConstant("Pixel Coordinate: ");
    returnString.append(Math.floor(pixelCoordinate.getX()));
    returnString.appendHtmlConstant(", ");
    returnString.append(Math.floor(pixelCoordinate.getY()));
    returnString.appendHtmlConstant("<br />");

    returnString.appendHtmlConstant("Tile Coordinate: ");
    returnString.append(Math.floor(tileCoordinate.getX()));
    returnString.appendHtmlConstant(", ");
    returnString.append(Math.floor(tileCoordinate.getY()));
    returnString.appendHtmlConstant("<br />");

    returnString.appendHtmlConstant("at Zoom Level: ");
    returnString.append(map.getZoom());
    return returnString.toSafeHtml().asString();
}

From source file:com.google.maps.gwt.samples.overlays.client.PolygonArrays.java

License:Apache License

private void showArrays(MouseEvent event) {
    // Since this Polygon only has one path, we can call getPath()
    // to return the MVCArray of LatLngs
    MVCArray<LatLng> vertices = bermudaTriangle.getPath();

    SafeHtmlBuilder contentString = new SafeHtmlBuilder();
    contentString.appendHtmlConstant("<b>Bermuda Triangle Polygon</b><br />");

    contentString.appendHtmlConstant("Clicked Location: <br />");
    contentString.append(event.getLatLng().lat());
    contentString.appendHtmlConstant(",");
    contentString.append(event.getLatLng().lng());
    contentString.appendHtmlConstant("<br />");

    // Iterate over the vertices.
    for (int i = 0; i < vertices.getLength(); i++) {
        LatLng xy = vertices.getAt(i);/*from   w w w.j  a v  a 2  s  .  c  o  m*/
        contentString.appendHtmlConstant("<br /> Coordinate: ");
        contentString.append(i);
        contentString.appendHtmlConstant("<br />");
        contentString.append(xy.lat());
        contentString.appendHtmlConstant(",");
        contentString.append(xy.lng());
    }

    // Replace our Info Window's content and position
    infowindow.setContent(contentString.toSafeHtml().asString());
    infowindow.setPosition(event.getLatLng());

    infowindow.open(map);
}

From source file:com.gwtcx.extgwt.client.desktop.view.AbstractSettingsView.java

License:Open Source License

public ColumnModel<ContextAreaModel> getContextAreaColumModel() {

    ColumnConfig<ContextAreaModel, String> column1IconColumnConfig = new ColumnConfig<ContextAreaModel, String>(
            property.column1Icon(), ContextAreaGrid.LARGE_ICON_COLUMN_WIDTH, "");
    column1IconColumnConfig.setCell(new ImageCell() {
        @Override//from ww  w .  j ava 2 s . c  o m
        protected void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {

            if (data == null) {
                return;
            }

            SafeStyles imageStyle = SafeStylesUtils.fromTrustedString(
                    "margin-left: 10px; width:48px; height:48px; position:relative; cursor:pointer;");
            SafeHtml rendered = template.cell("column1Icon", imageStyle, getIcon(data.asString()));
            sb.append(rendered);
        }
    });

    ColumnConfig<ContextAreaModel, String> column1DisplayNameColumnConfig = new ColumnConfig<ContextAreaModel, String>(
            property.column1DisplayName(), ContextAreaGrid.DISPLAY_NAME_COLUMN_WIDTH, "");
    column1DisplayNameColumnConfig
            .setCell(new AbstractSafeHtmlCell<String>(SimpleSafeHtmlRenderer.getInstance()) {
                @Override
                protected void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {

                    if (data == null) {
                        return;
                    }

                    ContextAreaModel model = (ContextAreaModel) getGrid().getStore().get(context.getIndex());
                    sb.appendHtmlConstant("<span>" + "<b>" + data.asString() + "</b><br />"
                            + model.getColumn1Description() + "</span>");
                }
            });

    ColumnConfig<ContextAreaModel, String> column2IconColumnConfig = new ColumnConfig<ContextAreaModel, String>(
            property.column2Icon(), ContextAreaGrid.LARGE_ICON_COLUMN_WIDTH, "");
    column2IconColumnConfig.setCell(new ImageCell() {
        @Override
        protected void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {

            if (data == null) {
                return;
            }

            SafeStyles imageStyle = SafeStylesUtils.fromTrustedString(
                    "margin-left: 10px; width:48px; height:48px; position:relative; cursor:pointer;");
            SafeHtml rendered = template.cell("column2Icon", imageStyle, getIcon(data.asString()));
            sb.append(rendered);
        }
    });

    ColumnConfig<ContextAreaModel, String> column2DisplayNameColumnConfig = new ColumnConfig<ContextAreaModel, String>(
            property.column2DisplayName(), ContextAreaGrid.DISPLAY_NAME_COLUMN_WIDTH, "");
    column2DisplayNameColumnConfig
            .setCell(new AbstractSafeHtmlCell<String>(SimpleSafeHtmlRenderer.getInstance()) {
                @Override
                protected void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {

                    if (data == null) {
                        return;
                    }

                    ContextAreaModel model = (ContextAreaModel) getGrid().getStore().get(context.getIndex());
                    sb.appendHtmlConstant("<span>" + "<b>" + data.asString() + "</b><br />"
                            + model.getColumn2Description() + "</span>");
                }
            });

    List<ColumnConfig<ContextAreaModel, ?>> columnConfigList = new ArrayList<ColumnConfig<ContextAreaModel, ?>>();
    columnConfigList.add(column1IconColumnConfig);
    columnConfigList.add(column1DisplayNameColumnConfig);
    columnConfigList.add(column2IconColumnConfig);
    columnConfigList.add(column2DisplayNameColumnConfig);

    ColumnModel<ContextAreaModel> columnModel = new ColumnModel<ContextAreaModel>(columnConfigList);

    return columnModel;
}

From source file:com.gwtmodel.table.view.table.edit.CustomizedGwtSelectionCell.java

License:Apache License

protected void renderCustom(Context context, String value, SafeHtmlBuilder sb, String style, String cClass) {
    // Get the view data.
    Object key = context.getKey();
    String viewData = getViewData(key);
    if (viewData != null && viewData.equals(value)) {
        clearViewData(key);/*w w  w.  j  a  v  a 2s . co m*/
        viewData = null;
    }

    int selectedIndex = getSelectedIndex(viewData == null ? value : viewData);
    // sb.appendHtmlConstant("<select tabindex=\"-1\">");
    sb.append(templateInput.input(style, cClass));
    int index = 0;
    for (String option : options) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option));
        } else {
            sb.append(template.deselected(option));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:com.java33.vizpres.client.view.cell.BarCell.java

License:Open Source License

/**
 * {@inheritDoc}// w  w w .ja  v  a 2 s.co  m
 */
@Override
public void render(final Context context, final PercentValue value, final SafeHtmlBuilder sb) {
    final int percentage = value.percentage;
    if (percentage >= 0 && percentage <= 100) {
        final StringBuilder tags = new StringBuilder("<div class='java33-barCell' style='width: ")
                .append(percentage).append("%;'>").append(percentage).append("</div>");
        sb.appendHtmlConstant(tags.toString());
    } else {
        sb.appendHtmlConstant("<p><strong>Value is out-of-range.</strong></p>");
    }
}

From source file:com.jitlogic.zico.client.views.traces.MethodDetailCell.java

License:Open Source License

@Override
public void render(Context context, TraceRecordInfo tr, SafeHtmlBuilder sb) {
    if (tr.getAttributes() != null) {
        sb.appendHtmlConstant("<table border=\"0\" cellspacing=\"2\"><tbody>");
        for (KeyValuePair e : tr.getAttributes()) {
            sb.appendHtmlConstant("<tr><td align=\"right\" class=\"" + methodAttributeKey + "\"><b>");
            sb.append(SafeHtmlUtils.fromString(e.getKey()));
            sb.appendHtmlConstant("</b></td><td><div class=\"" + methodAttributeVal + "\">");
            sb.append(SafeHtmlUtils.fromString(e.getValue() != null ? e.getValue().toString() : ""));
            sb.appendHtmlConstant("</div></td></tr>");
        }//from w  ww  .  j  a v a  2 s .  co  m
        sb.appendHtmlConstant("</tbody></table>");
    }
    if (tr.getExceptionInfo() != null) {
        SymbolicExceptionInfo e = tr.getExceptionInfo();
        sb.appendHtmlConstant("<div class=\"" + methodErrorClassName + "\">");
        sb.append(SafeHtmlUtils.fromString("Caught: " + e.getExClass()));
        sb.appendHtmlConstant("</div>");
        sb.appendHtmlConstant("<div class=\"" + methodErrorMessage + "\">");
        sb.append(SafeHtmlUtils.fromString("" + e.getMessage()));
        sb.appendHtmlConstant("</b></div>");
        int i = 0;
        for (String s : e.getStackTrace()) {
            sb.appendHtmlConstant("<div class=\"" + methodErrorStack + "\">");
            sb.append(SafeHtmlUtils.fromString("" + s));
            sb.appendHtmlConstant("</div>");
            i++;
            if (i > 5) {
                sb.appendHtmlConstant("<div class=\"" + methodErrorMessage + "\">");
                sb.append(
                        SafeHtmlUtils.fromString("...  (double click on this method to see full stack trace)"));
                sb.appendHtmlConstant("</div>");
                break;
            }
        }
    }
}