litesoft
@ 630
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / widget / input / support / TextLabel.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package com.temp.client.foundation.widget.input.support; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasName; import com.google.gwt.user.client.ui.Widget; import com.temp.shared.utils.HtmlUtils; import com.temp.shared.utils.ObjectUtils; import com.temp.shared.utils.StringUtils; public abstract class TextLabel extends Composite implements HasName { protected final HTML htmlWidget = new HTML(HtmlUtils.NBSP); private String text = null; private String name; public final String getText() { return text; } public final void setText(String text) { commonSetText(StringUtils.noEmpty(text)); } @Override public void setName(String name) { this.name = StringUtils.noEmpty(name); } @Override public String getName() { return name; } @Override public String toString() { return ObjectUtils.getSimpleClassName(this) + ": '" + getText() + "'"; } public final void setTextNoTrim(String text) { text = StringUtils.deNull(text); commonSetText("".equals(text) ? null : text); } public final TextLabel text(String text) { setText(text); return this; } public final TextLabel textNoTrim(String text) { setTextNoTrim(text); return this; } public final TextLabel style(String className) { className = StringUtils.noEmpty(className); if (className != null) { addStyleName(className); } return this; } protected final void commonSetText(String text) { this.text = text; String html = StringUtils.deNull((text == null) ? HtmlUtils.NBSP : StringUtils.noEmpty(normalizeHTML(text)), HtmlUtils.NBSP); htmlWidget.setHTML(html); } @Override protected void initWidget(Widget widget) { super.initWidget(widget); setStyleName(ObjectUtils.getSimpleClassName(this)); } /** * @param text will NOT be null or have any leading/trailing whitespace * @return Html Safe Text */ protected abstract String normalizeHTML(String text); } |