1 28 29 package com.caucho.widget; 30 31 import com.caucho.util.L10N; 32 33 import java.io.IOException; 34 35 public class LabelWidget 36 extends XulWidget 37 { 38 private static final L10N L = new L10N(LabelWidget.class); 39 40 private static final String NULL_VALUE = ""; 41 42 private VarDefinition valueDef = new XulVarDefinition(this, "value", String.class); 43 private DisabledProperty _disabledProperty = new DisabledProperty(this); 44 45 public LabelWidget() 46 { 47 } 48 49 public LabelWidget(String id) 50 { 51 setId(id); 52 } 53 54 public LabelWidget(String id, String initialValue) 55 { 56 setId(id); 57 setValue(initialValue); 58 } 59 60 public void setValue(String value) 61 { 62 valueDef.setValue(value); 63 } 64 65 public String getValue() 66 { 67 return valueDef.getValue(); 68 } 69 70 public void setDisabled(boolean isDisabled) 71 { 72 _disabledProperty.setValue(isDisabled); 73 } 74 75 public boolean isDisabled() 76 { 77 return _disabledProperty.getValue(); 78 } 79 80 public void init(WidgetInit init) 81 throws WidgetException 82 { 83 super.init(init); 84 85 _disabledProperty.init(init); 86 87 if (valueDef.getValue() == null) 88 valueDef.setValue(NULL_VALUE); 89 90 init.addVarDefinition(valueDef); 91 92 } 93 94 97 public void setValue(VarContext context, String value) 98 { 99 if (value == null) 100 value = NULL_VALUE; 101 102 context.setVar(this, valueDef, value); 103 } 104 105 109 public String getValue(VarContext context) 110 { 111 return context.getVar(this, valueDef); 112 } 113 114 public void setDisabled(VarContext context, boolean isDisabled) 115 { 116 _disabledProperty.setValue(context, isDisabled); 117 } 118 119 public boolean isDisabled(VarContext context) 120 { 121 return _disabledProperty.getValue(context); 122 } 123 124 public void invocation(WidgetInvocation invocation) 125 throws WidgetException 126 { 127 super.invocation(invocation); 128 129 if (!valueDef.isReadOnly()) { 130 String value = invocation.getParameter(); 131 132 if (value != null) 133 setValue(invocation, value); 134 } 135 } 136 137 public void url(WidgetURL url) 138 throws WidgetException 139 { 140 if (isTransient(url)) 141 return; 142 143 super.url(url); 144 145 if (!valueDef.isReadOnly()) { 146 String value = getValue(url); 147 148 if (value == null) 149 value = NULL_VALUE; 150 151 if (!value.equals(valueDef.getValue())) 152 url.setParameter(value); 153 } 154 } 155 156 public void response(WidgetResponse response) 157 throws WidgetException, IOException 158 { 159 String value = getValue(response); 160 161 if (value == null) 162 return; 163 164 String id = getId(); 165 String cssClass = getCssClass(response); 166 boolean isDisabled = isDisabled(response); 167 168 WidgetWriter out = response.getWriter(); 169 170 out.startElement("span"); 171 out.writeAttribute("id", id); 172 173 String disabledAttribute = isDisabled ? "disabled" : null; 174 175 out.writeAttribute("class", cssClass, disabledAttribute); 176 177 out.writeText(value); 178 179 out.endElement("span"); 180 } 181 } 182 | Popular Tags |