1 28 29 30 package com.caucho.widget; 31 32 import com.caucho.util.L10N; 33 34 import java.io.IOException ; 35 import java.util.Locale ; 36 import java.util.logging.Logger ; 37 38 public class FieldWidget 39 extends WidgetContainer 40 { 41 private static L10N L = new L10N( FieldWidget.class ); 42 43 static protected final Logger log = 44 Logger.getLogger( FieldWidget.class.getName() ); 45 46 private LocaleString _displayName; 47 private LocaleString _shortDescription; 48 49 public FieldWidget() 50 { 51 } 52 53 public FieldWidget( String id ) 54 { 55 super( id ); 56 } 57 58 public FieldWidget( Widget parent ) 59 { 60 super( parent ); 61 } 62 63 public FieldWidget( Widget parent, String id ) 64 { 65 super( parent, id ); 66 } 67 68 71 public void setDisplayName( String displayName ) 72 { 73 _displayName = LocaleString.add( _displayName, displayName ); 74 } 75 76 79 public void addDisplayName( LocaleString displayName ) 80 { 81 _displayName = LocaleString.add( _displayName, displayName ); 82 } 83 84 87 public String getDisplayName( Locale locale ) 88 { 89 return LocaleString.get( _displayName, locale ); 90 } 91 92 95 public String getDisplayName() 96 { 97 return LocaleString.get( _displayName ); 98 } 99 100 103 public void setShortDescription( String shortDescription ) 104 { 105 _shortDescription = LocaleString.add( _shortDescription, shortDescription ); 106 } 107 108 111 public void addShortDescription( LocaleString shortDescription ) 112 { 113 _shortDescription = LocaleString.add( _shortDescription, shortDescription ); 114 } 115 116 119 public String getShortDescription() 120 { 121 return LocaleString.get( _shortDescription ); 122 } 123 124 127 public String getShortDescription( Locale locale ) 128 { 129 return LocaleString.get( _shortDescription, locale ); 130 } 131 132 protected String calculateId( Widget child ) 133 { 134 String id = null; 135 136 int size = size(); 137 138 if ( size == 0 ) 139 id = "value"; 140 else 141 id = "value" + size; 142 143 return id; 144 } 145 146 public void init() 147 throws WidgetException 148 { 149 super.init(); 150 151 if ( getDisplayName() == null ) 152 throw new IllegalStateException ( 153 L.l( "`{0}' is required", "display-name" ) ); 154 } 155 156 protected FieldWidgetState createState( WidgetConnection connection ) 157 throws WidgetException 158 { 159 return new FieldWidgetState(); 160 } 161 162 protected WidgetState decodeChild( WidgetConnection connection, 163 WidgetState thisState, 164 Widget child ) 165 throws WidgetException 166 { 167 WidgetState childState 168 = super.decodeChild( connection, thisState, child ); 169 170 FieldWidgetState state = (FieldWidgetState) thisState; 171 172 state.setChildWithValue( childState ); 173 174 return childState; 175 } 176 177 public void renderTextHtml( WidgetConnection connection, 178 FieldWidgetState widgetState ) 179 throws WidgetException, IOException 180 { 181 WidgetWriter writer = connection.getWriter(); 182 183 Locale locale = connection.getLocale(); 184 185 String displayName = getDisplayName( locale ); 186 String shortDescription = getShortDescription( locale ); 187 188 writer.startElement( "div", true ); 189 writer.writeAttribute( "id", getClientId() ); 190 writer.writeAttribute( "class", getCssClass() ); 191 192 194 writer.startElement( "div", true ); 195 writer.writeAttribute( "id", getClientId() ); 196 writer.writeAttribute( "class", "name" ); 197 198 if ( shortDescription != null ) 199 writer.writeAttribute( "title", shortDescription ); 200 201 if ( displayName != null ) 202 writer.writeText( displayName ); 203 204 writer.endElement( "div", true ); 205 206 207 211 213 writer.startElement( "div", true ); 214 writer.writeAttribute( "id", getClientId() ); 215 writer.writeAttribute( "class", "value" ); 216 217 super.renderChildren( connection, widgetState ); 218 219 writer.endElement( "div", true ); 220 221 223 writer.endElement( "div", true ); 224 } 225 } 226 | Popular Tags |