Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

Introduction

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

Prototype

public SafeHtml toSafeHtml() 

Source Link

Document

Returns the safe HTML accumulated in the builder as a SafeHtml .

Usage

From source file:stroom.dashboard.client.table.TablePresenter.java

License:Apache License

private void addColumn(final Field field, final int pos) {
    final Column<Row, SafeHtml> column = new Column<Row, SafeHtml>(new SafeHtmlCell()) {
        @Override//from w w  w  .j a  v a  2s  .  c  o m
        public SafeHtml getValue(final Row row) {
            if (row == null) {
                return null;
            }

            final List<String> values = row.getValues();
            if (values != null) {
                final String value = values.get(pos);
                if (value != null) {
                    if (field.getGroup() != null && field.getGroup() >= row.getDepth()) {
                        final SafeHtmlBuilder sb = new SafeHtmlBuilder();
                        sb.appendHtmlConstant("<b>");
                        sb.appendEscaped(value);
                        sb.appendHtmlConstant("</b>");

                        return sb.toSafeHtml();
                    }
                    return SafeHtmlUtils.fromString(value);
                }
            }
            return null;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, Row object) {
            if (field.getFormat() != null && field.getFormat().getWrap() != null
                    && field.getFormat().getWrap()) {
                return super.getCellStyleNames(context, object) + " "
                        + getView().getResources().dataGridStyle().dataGridCellWrapText();
            }

            return super.getCellStyleNames(context, object);
        }
    };

    final FieldHeader fieldHeader = new FieldHeader(fieldsManager, field);
    fieldHeader.setUpdater(value -> getView().redrawHeaders());

    getView().addResizableColumn(column, fieldHeader, field.getWidth());
    existingColumns.add(column);
}

From source file:stroom.pipeline.structure.client.presenter.PipelineReferenceListPresenter.java

License:Apache License

private SafeHtml getSafeHtmlWithState(final PipelineReference pipelineReference, final String string) {
    if (string == null) {
        return SafeHtmlUtils.EMPTY_SAFE_HTML;
    }/*w w w. j  a v a 2s.co  m*/

    final SafeHtmlBuilder builder = new SafeHtmlBuilder();
    final State state = referenceStateMap.get(pipelineReference);
    switch (state) {
    case ADDED:
        builder.append(ADDED);
        break;
    case REMOVED:
        builder.append(REMOVED);
        break;
    case INHERITED:
        builder.append(INHERITED);
        break;
    }

    builder.appendEscaped(string);
    builder.append(END);

    return builder.toSafeHtml();
}

From source file:stroom.pipeline.structure.client.presenter.PropertyListPresenter.java

License:Apache License

private SafeHtml getSafeHtmlWithState(final PipelineProperty property, final String string,
        final boolean showRemovedAsDefault) {
    if (string == null) {
        return SafeHtmlUtils.EMPTY_SAFE_HTML;
    }//from  w  w  w.j a va 2s.com

    final SafeHtmlBuilder builder = new SafeHtmlBuilder();
    if (pipelineModel.getPipelineData().getAddedProperties().contains(property)) {
        builder.append(ADDED);
    } else if (pipelineModel.getPipelineData().getRemovedProperties().contains(property)) {
        if (showRemovedAsDefault) {
            builder.append(DEFAULT);
        } else {
            builder.append(REMOVED);
        }
    } else {
        final PipelineProperty inheritedProperty = getInheritedProperty(property);
        if (inheritedProperty != null) {
            builder.append(INHERITED);
        } else {
            builder.append(DEFAULT);
        }
    }

    builder.appendEscaped(string);
    builder.append(END);

    return builder.toSafeHtml();
}

From source file:stroom.streamstore.client.presenter.MarkerListPresenter.java

License:Apache License

private void addElementId() {
    getView().addResizableColumn(new Column<Marker, SafeHtml>(new SafeHtmlCell()) {
        @Override//from   w ww.j  a va2s.  c  o m
        public SafeHtml getValue(final Marker marker) {
            if (marker instanceof StoredError) {
                final StoredError storedError = (StoredError) marker;
                if (storedError.getElementId() != null) {
                    return SafeHtmlUtils.fromString(storedError.getElementId());
                }

            } else if (marker instanceof Summary) {
                final Summary summary = (Summary) marker;

                final StringBuilder sb = new StringBuilder();
                sb.append(summary.getSeverity().getSummaryValue());
                sb.append(" (");
                if (summary.getTotal() > summary.getCount()) {
                    sb.append(summary.getCount());
                    sb.append(" of ");
                    sb.append(summary.getTotal());

                    if (summary.getTotal() >= FetchMarkerResult.MAX_TOTAL_MARKERS) {
                        sb.append("+");
                    }

                    if (summary.getTotal() <= 1) {
                        sb.append(" item)");
                    } else {
                        sb.append(" items)");
                    }
                } else {
                    sb.append(summary.getCount());
                    if (summary.getCount() <= 1) {
                        sb.append(" item)");
                    } else {
                        sb.append(" items)");
                    }
                }

                // Make summery items bold.
                final SafeHtmlBuilder builder = new SafeHtmlBuilder();
                builder.appendHtmlConstant("<div style=\"font-weight:bold;\">");
                builder.appendEscaped(sb.toString());
                builder.appendHtmlConstant("</div>");

                return builder.toSafeHtml();
            }

            return null;
        }
    }, "Element", 150);
}

From source file:stroom.widget.xsdbrowser.client.view.XSDDisplay.java

License:Apache License

private void addChild(final Grid layout, final SelectionMap map, final XSDNode node,
        final boolean showOccurance, final int row, final int col) {
    // Ensure layout size.
    if (layout.getRowCount() < row + 1) {
        layout.resizeRows(row + 1);//from w  ww . j  av  a  2  s .c  om
    }

    final XSDType type = node.getType();
    rowMap.put(node, row);

    // Add the image for the structure element if this is one.
    if (type.isStructural()) {
        final String occurrence = node.getOccurance();

        if (occurrence != null) {
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendHtmlConstant("<div class=\"occuranceLabel\">");
            builder.appendEscaped(occurrence);
            builder.appendHtmlConstant("</div>");

            final HTML html = new HTML(builder.toSafeHtml());

            final FlowPanel fp = new FlowPanel();
            fp.add(getImage(type));
            fp.add(html);
            fp.getElement().getStyle().setPosition(Position.RELATIVE);

            layout.setWidget(row, col, fp);
        } else {
            layout.setWidget(row, col, getImage(type));
        }

        layout.setWidget(row, col + 1, AbstractImagePrototype.create(resources.xsdTree03()).createImage());

    } else {
        // Otherwise add the element.
        XSDNode refNode = null;

        Image image = null;
        XSDNodeLabel lblName = null;
        Label lblOccurrence = null;
        Label lblType = null;

        String name = node.getName();
        String valueType = null;

        if (type == XSDType.ELEMENT || type == XSDType.ATTRIBUTE) {
            if (name == null) {
                refNode = node.getRefNode();
                if (refNode != null) {
                    name = refNode.getName();
                }
            }

            if (refNode != null) {
                valueType = refNode.getValueType();
                if (valueType == null) {
                    valueType = "(" + name + "Type)";
                }

            } else {
                valueType = node.getValueType();
                if (valueType == null) {
                    valueType = "(" + name + "Type)";
                }
            }

            if (showOccurance) {
                final String occurance = node.getOccurance();
                if (occurance != null) {
                    lblOccurrence = new Label(node.getOccurance(), false);
                }
            }
        }

        // Get the image to use.
        if (refNode != null) {
            image = getImage(XSDType.ELEMENT_REF);
        } else {
            image = getImage(type);
        }
        if (name != null) {
            lblName = new XSDNodeLabel(name, map, model, node, refNode);
        }
        if (valueType != null) {
            lblType = new Label(valueType, false);
        }

        final int colCount = layout.getColumnCount();

        // Add line images to get back to the structure level.
        if (node.getParent() != null && node.getParent().getType().isStructural()) {
            for (int i = col; i < colCount - 6; i++) {
                layout.setWidget(row, i, AbstractImagePrototype.create(resources.xsdTree03()).createImage());
            }
        }

        // Add other images to create the tree lines.
        int pos = col - 1;
        XSDNode parent = node;
        while (pos >= 0 && parent != null && parent.getType().isStructuralOrElement()) {
            if (node == parent || rowMap.get(parent) == row) {
                if (parent.isFirstChild() && parent.isLastChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree03()).createImage());
                } else if (parent.isFirstChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree06()).createImage());
                } else if (parent.isLastChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree09()).createImage());
                } else {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree05()).createImage());
                }
            } else if (!parent.isLastChild()) {
                layout.setWidget(row, pos, AbstractImagePrototype.create(resources.xsdTree02()).createImage());
            }

            parent = parent.getParent();
            pos -= 2;
        }

        if (image != null) {
            layout.setWidget(row, colCount - 6, image);
            image.addStyleName("marginRight");
        }
        if (lblName != null) {
            layout.setWidget(row, colCount - 5, lblName);
        }
        if (lblOccurrence != null) {
            layout.setWidget(row, colCount - 4, new Label("[", false));
            layout.setWidget(row, colCount - 3, lblOccurrence);
            layout.setWidget(row, colCount - 2, new Label("]", false));
        }
        if (lblType != null) {
            layout.setWidget(row, colCount - 1, lblType);
            lblType.addStyleName("marginLeft");
        }
    }
}

From source file:thothbot.parallax.demo.client.Demo.java

License:Open Source License

/**
 * Create a hidden site map for crawlability.
 * /*from  w  w  w .  j  av  a2  s. co m*/
 * @param contentWidgets the {@link ContentWidget}s used in Demo
 */
private void createSiteMap(Set<ContentWidget> contentWidgets) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    for (ContentWidget cw : contentWidgets) {
        String token = cw.getContentWidgetToken();
        sb.append(SafeHtmlUtils.fromTrustedString("<a href=\"#" + token + "\">" + token + "</a>"));
    }

    // Add the site map to the page.
    HTML siteMap = new HTML(sb.toSafeHtml());
    siteMap.setVisible(false);
    RootPanel.get().add(siteMap, 0, 0);
}

From source file:tv.dyndns.kishibe.qmaclone.client.game.sentence.WidgetProblemSentenceEffect.java

License:Open Source License

@VisibleForTesting
void update() {/*from w w w  .  j  a va 2s.c  o  m*/
    // SHOW_ALL_TIMING_MS??????
    int showAllCount = SHOW_ALL_TIMING_MS / UPDATE_PERIOD_MS;
    if (++count > showAllCount) {
        html.setHTML(new SafeHtmlBuilder().append(prefix).append(SURFIX_TEMPLATE).toSafeHtml());
        return;
    }

    // ????
    int lineWidth = INITIALI_WIDTH * (showAllCount - count) / showAllCount;
    for (int i = 0; i < NUMBER_OF_LINE; ++i) {
        pos[i] += velocities[i];
        if (pos[i] < 0) {
            velocities[i] = Math.abs(velocities[i]);
        } else if (pos[i] > WIDTH - lineWidth) {
            velocities[i] = -Math.abs(velocities[i]);
        }
    }

    // ??
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(prefix);

    for (int i = 0; i < NUMBER_OF_LINE; ++i) {
        SafeStyles styles = new SafeStylesBuilder().position(Position.ABSOLUTE).left(pos[i], Unit.PX)
                .top(0, Unit.PX).trustedBackgroundColor(COLORS[i]).width(lineWidth, Unit.PX).height(72, Unit.PX)
                .toSafeStyles();
        builder.append(HINT_TEMPLATE.line(styles));
    }
    builder.append(SURFIX_TEMPLATE);

    html.setHTML(builder.toSafeHtml());
}

From source file:us.softoption.proofs.TProofDisplayCellTable.java

License:Open Source License

public void synchronizeViewToData() {

    /*/*from  w  w  w  .  jav  a 2s .c o m*/
    A proof looks like
            
    1 | F^G                    Ass
    2 || H                     Ass
    3 || F                     1 ^E
            
    now, a line (row) on its own is fine, we can use one column for the line number, then one each for 
    the vertical lines, the formula, and the justification.
            
    Conceptually, the line numbers are col 1, the vertical lines are subcolumns of col 2, the formula
    is col 3, and the justification col 4.
            
    But, if we wanted to combine several lines into a table we have the problem that the different rows
    might have a different number of columns.
            
    But we know
            
    If this method is called with a (max) numberOfColumns, then we can insert a colspan if needed. The colspan
    needs to go with the formula (ie with F^G in line 1), we are looking for left justification.
            
    Now, some proofs start with a headlevel of -1, others with a headlevel of 0 (that information is
    on the line itself).
            
    Then the parameter tells us the maximum nesting. So the number of columns in the table as a whole is
    4 + maxSubProofLevel.
            
    So, any particular line has to look at the difference between its level and the headlevel. It that is
    maxSubProoflevel no colspan is needed. If it is one less than maxSubProoflevel a colspan of 2 is needed
            
    ie colspan = maxSubProoflevel - difference +1 (and colspan has to be greater than 1 to matter)
            
            
    */

    if (fProofListModel != null) { //updating display from the model
        //empty old
        int presentCols = this.getColumnCount();

        for (int i = 0; i < presentCols; i++)
            this.removeColumn(presentCols - i - 1);
        //prep new
        int rows = fProofListModel.getRowCount();
        int cols = fProofListModel.getColumnCount();

        List<TProofline> rowList = fProofListModel.proofAsProoflines();

        //this.setVisibleRangeAndClearData(new Range(0,0),true);

        this.setRowCount(0, true); //belt and braces

        //this.se
        // Create a value updater that will be called when the value in a cell
        // changes.
        //    ValueUpdater<String> valueUpdater = new ValueUpdater<String>() {
        //      public void update(String newValue) {
        //        Window.alert("You typed: " + newValue);
        //            }
        //          };

        // Add the value updater to the cellList.
        //    this.setUpdater(valueUpdater);

        this.setRowCount(rows, true);

        // Add a text column to show the line number
        /*       TextColumn<TProofline> nameColumn = new TextColumn<TProofline>() {
                 @Override
                 public String getValue(TProofline object) {
                   return (object.firstColumnGWT());
                 }
               };
               this.addColumn(nameColumn, "LineNo");  
              */

        //      Column<TProofline,String> aColumn=new Column<TProofline,String>();

        /*      Column<TProofline, String> editableColumn = new Column<TProofline, String>(
          new ClickableTextCell() /* (Cell)(new TProofCustomCell())*/ /*) {
                                                                       @Override
                                                                       public String getValue(TProofline parameter) {
                                                                       return parameter.firstColumnGWT();
                                                                       }
                                                                       };
                                                                               
                                                                       this.addColumn(editableColumn /*,"LineNo");
                                                                               
                                                                       */

        /****** experiment Jan 18 2013 *****/
        /*         
                 final int maxSubProofLevel = fProofListModel.maxSubProofLevel();
                          
                 final SafeHtmlCell lineNoCell = new SafeHtmlCell();
                 final SafeHtmlCell vertLinesCell = new SafeHtmlCell();
                 final SafeHtmlCell formulaCell = new SafeHtmlCell();
                 final SafeHtmlCell justificationCell = new SafeHtmlCell();
                          
                  Column<TProofline, SafeHtml> safeColumn1 = new Column<TProofline, SafeHtml>(
           lineNoCell) {
                      @Override
                      public SafeHtml getValue(TProofline parameter) {
         SafeHtmlBuilder sb = new SafeHtmlBuilder();
         sb.appendHtmlConstant(parameter.firstColumnGWT());
             return 
                sb.toSafeHtml()                 
                    ;
                      }
                  };
                         
                  this.addColumn(safeColumn1);
                   
                  Column<TProofline, SafeHtml> safeColumn2 = new Column<TProofline, SafeHtml>(
           vertLinesCell) {
                      @Override
                      public SafeHtml getValue(TProofline parameter) {
         SafeHtmlBuilder sb = new SafeHtmlBuilder();
         sb.appendHtmlConstant(parameter.secondColumnGWT());
             return 
                sb.toSafeHtml()                 
                    ;
                      }
                  };
                         
                  this.addColumn(safeColumn2);
                          
                  Column<TProofline, SafeHtml> safeColumn3 = new Column<TProofline, SafeHtml>(
           formulaCell) {
                      @Override
                      public SafeHtml getValue(TProofline parameter) {
         SafeHtmlBuilder sb = new SafeHtmlBuilder();
         sb.appendHtmlConstant(parameter.thirdColumnGWT(maxSubProofLevel));
             return 
                sb.toSafeHtml()                 
                    ;
                      }
                  };
                         
                  this.addColumn(safeColumn3);
                          
                  Column<TProofline, SafeHtml> safeColumn4 = new Column<TProofline, SafeHtml>(
           justificationCell) {
                      @Override
                      public SafeHtml getValue(TProofline parameter) {
         SafeHtmlBuilder sb = new SafeHtmlBuilder();
         sb.appendHtmlConstant(parameter.fourthColumnGWT());
             return 
                sb.toSafeHtml()                 
                    ;
                      }
                  };
                         
                  this.addColumn(safeColumn4);
                          
                 this.setRowData(rowList);
                
                         
                         
                 //now we want to set column widths   
                            
                 this.setWidth("100%", true); //fixed layout
                 this.setColumnWidth(safeColumn1, 36.0, Unit.PX);
                 this.setColumnWidth(safeColumn2, 10.0, Unit.PCT);
                 this.setColumnWidth(safeColumn3, 70.0, Unit.PCT);
                 this.setColumnWidth(safeColumn4, 20.0, Unit.PCT);   
        */
        /******************/

        /****** experiment Feb 2013 *****/

        /*we really want three columns, the line number, the vert lines and formula in one, and the justification*/

        final int maxSubProofLevel = fProofListModel.maxSubProofLevel();

        final SafeHtmlCell lineNoCell = new SafeHtmlCell();
        final SafeHtmlCell vertLinesAndFormulaCell = new SafeHtmlCell();
        //      final SafeHtmlCell formulaCell = new SafeHtmlCell();
        final SafeHtmlCell justificationCell = new SafeHtmlCell();

        Column<TProofline, SafeHtml> safeColumn1 = new Column<TProofline, SafeHtml>(lineNoCell) {
            @Override
            public SafeHtml getValue(TProofline parameter) {
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendHtmlConstant(parameter.firstColumnGWT());
                return sb.toSafeHtml();
            }
        };

        this.addColumn(safeColumn1 /*,"Line No"*/);

        Column<TProofline, SafeHtml> safeColumn2 = new Column<TProofline, SafeHtml>(vertLinesAndFormulaCell) {
            @Override
            public SafeHtml getValue(TProofline parameter) {
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendHtmlConstant(parameter.secondAndThirdColumnGWT(maxSubProofLevel));
                return sb.toSafeHtml();
            }
        };

        this.addColumn(safeColumn2 /*,"Vert Lines" and formula*/);

        Column<TProofline, SafeHtml> safeColumn3 = new Column<TProofline, SafeHtml>(justificationCell) {
            @Override
            public SafeHtml getValue(TProofline parameter) {
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendHtmlConstant(parameter.fourthColumnGWT());
                return sb.toSafeHtml();
            }
        };

        this.addColumn(safeColumn3 /*,"Justification"*/);

        this.setRowData(rowList);

        //now we want to set column widths   

        this.setWidth("100%", true); //fixed layout
        this.setColumnWidth(safeColumn1, 36.0, Unit.PX); //line no
        this.setColumnWidth(safeColumn2, 100.0, Unit.PCT); // vert lines and formula
        this.setColumnWidth(safeColumn3, 100.0, Unit.PX); // justification

        /******************/

    }

}