2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.client.ui.cell;
22 import org.glom.web.shared.layout.LayoutItemField.GlomFieldType;
24 import com.google.gwt.cell.client.AbstractCell;
25 import com.google.gwt.safehtml.shared.SafeHtml;
26 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
27 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
30 * Cell renderer for {@link GlomFieldType} TYPE_TEXT.
32 * @author Ben Konrath <ben@bagu.org>
35 public class TextCell extends AbstractCell<String> {
36 SafeHtml colourCSSProp;
37 SafeHtml backgroundColourCSSProp;
39 // TODO Find a way to set the colours on the whole column
40 public TextCell(String foregroundColour, String backgroundColour) {
41 if (foregroundColour != null && !foregroundColour.isEmpty()) {
42 colourCSSProp = SafeHtmlUtils.fromString("color:" + foregroundColour + ";");
44 colourCSSProp = SafeHtmlUtils.fromSafeConstant("");
46 if (backgroundColour != null && !backgroundColour.isEmpty()) {
47 backgroundColourCSSProp = SafeHtmlUtils.fromString("background-color:" + backgroundColour + ";");
49 backgroundColourCSSProp = SafeHtmlUtils.fromSafeConstant("");
56 * @see com.google.gwt.cell.client.AbstractCell#render(com.google.gwt.cell.client.Cell.Context, java.lang.Object,
57 * com.google.gwt.safehtml.shared.SafeHtmlBuilder)
60 public void render(Context context, String value, SafeHtmlBuilder sb) {
62 // The value is from an empty row.
63 sb.appendHtmlConstant(" ");
67 // Set the text and some CSS properties for the text.
68 // The overflow and text-overflow properties tell the browser to add an ellipsis when the text overflows the
70 // FIXME this isn't using safe html correctly!
71 sb.appendHtmlConstant("<div style=\"overflow: hidden; text-overflow: ellipsis; " + colourCSSProp.asString()
72 + backgroundColourCSSProp.asString() + "\">");
73 sb.append(SafeHtmlUtils.fromString(value));
74 sb.appendHtmlConstant("</div>");