001package com.github.gwtbootstrap.client.ui; 002 003import com.github.gwtbootstrap.client.ui.constants.Constants; 004import com.github.gwtbootstrap.client.ui.constants.LabelType; 005import com.google.gwt.safehtml.shared.SafeHtml; 006import com.google.gwt.safehtml.shared.SafeHtmlBuilder; 007 008/** 009 * A cell used to render text as a colored label, with a given type (error, 010 * warning etc). 011 * 012 * @see Label 013 */ 014public class LabelCell extends com.google.gwt.cell.client.TextCell { 015 016 private LabelType type = null; 017 018 /** 019 * Construct a new {@link LabelCell} with the default label type 020 */ 021 public LabelCell() { 022 this(LabelType.DEFAULT); 023 } 024 025 /** 026 * Construct a new {@link LabelCell} with the specified label type 027 * 028 * @param type 029 */ 030 public LabelCell(LabelType type) { 031 this.type = type; 032 } 033 034 /** 035 * Set the label type for labels rendered by this cell. 036 * 037 * @param type 038 */ 039 public void setType(LabelType type) { 040 this.type = type; 041 } 042 043 public LabelType getType() { 044 return type; 045 } 046 047 @Override 048 public void render(Context context, SafeHtml value, SafeHtmlBuilder sb) { 049 if (value != null) { 050 sb.appendHtmlConstant("<span class=\"" + Constants.LABEL + " " 051 + type.get() + "\">"); 052 sb.append(value); 053 sb.appendHtmlConstant("</span>"); 054 } 055 } 056 057}