Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - Make CellTable Cell use HTML?

Tags:

html

cell

gwt

I have a CellTable where I want to put HTML-code in the cells. The following code is not working, the blank spaces are removed from the output.

    TextColumn<MyCell> column1 = new TextColumn<MyCell>()
    {
        @Override
        public String getValue(MyCell myCell)
        {
            String result = "     " +myCell.getValue();
            return result;
        }
    };
    table.addColumn(column1 , "Header1");

I know this could be done using css but I just want to know how to put HTML-code in the cells. Any help is appreciated!

like image 765
gusjap Avatar asked Apr 27 '11 09:04

gusjap


1 Answers

AFAIK additional whitespace is ignored in HTML - you should use pre tag to maintain formatting.Anyway please find my column sample below. It generates nice progress bar from values contained in objects backed by data provider.

final SafeHtmlCell progressCell = new SafeHtmlCell();

    Column<UiScheduledTask, SafeHtml> progressCol = new Column<UiScheduledTask, SafeHtml>(
            progressCell) {

        @Override
        public SafeHtml getValue(UiScheduledTask value) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            float percent = new Float(value.getCompleted())
                    / new Float(value.getAll());
            int rounded = Math.round(percent * 100);
            sb.appendHtmlConstant("<div style='width: 100px; height: 20px; position: relative;'>");
            sb.appendHtmlConstant("<div style='z-index: 2; display: inline; width: 100px; position: absolute; left: 0px, top: 0px; text-align: center;'>"
                    + value.getCompleted()
                    + "/"
                    + value.getAll()
                    + "</div>");
            sb.appendHtmlConstant("<div style='position: absolute; left: 0; top: 0; width: 100px; z-index: 1'><div style='display: inline; float: left; width: "
                    + rounded
                    + "%; height: 20px; background-color: #82cd80;'></div>");
            sb.appendHtmlConstant("<div style='display: inline; float: right; width: "
                    + (100 - rounded)
                    + "%; height: 20px; background-color: #c54c4d;'></div></div>");
            sb.appendHtmlConstant("</div>");
            return sb.toSafeHtml();
        }
    };
like image 56
jgrabowski Avatar answered Oct 04 '22 20:10

jgrabowski