1 23 24 package com.sun.enterprise.tools.guiframework.view; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.RequestManager; 28 import com.iplanet.jato.NavigationException; 29 import com.iplanet.jato.model.ModelControlException; 30 import com.iplanet.jato.view.ContainerView; 31 import com.iplanet.jato.view.DisplayField; 32 import com.iplanet.jato.view.DisplayFieldDescriptor; 33 import com.iplanet.jato.view.View; 34 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 35 import com.iplanet.jato.view.event.ChildDisplayEvent; 36 import com.iplanet.jato.view.event.DisplayEvent; 37 38 import com.sun.enterprise.tools.guiframework.exception.ChildNotRegisteredException; 39 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 40 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 41 42 import com.sun.web.ui.model.CCDateTimeModelInterface; 43 import com.sun.web.ui.view.datetime.CCDateTime; 44 45 import java.text.DateFormat ; 46 import java.text.ParseException ; 47 import java.util.Date ; 48 49 50 56 public class DescriptorCCDateTime extends CCDateTime implements DescriptorContainerView, DisplayField { 57 58 65 public DescriptorCCDateTime(RequestContext ctx, String name, ViewDescriptor desc, ContainerView parent, CCDateTimeModelInterface model) { 66 super(parent, model, name); 67 setRequestContext( 68 (ctx == null) ? RequestManager.getRequestContext() : ctx); 69 setViewDescriptor(desc); 70 registerViewDescriptorChildren(); 71 } 72 73 74 78 81 protected void setViewDescriptor(ViewDescriptor desc) { 82 _viewDesc = desc; 83 } 84 85 86 91 public ViewDescriptor getViewDescriptor() { 92 return _viewDesc; 93 } 94 95 96 99 public View createChild(String name) { 100 View child = null; 101 try { 102 child = DescriptorViewHelper.createChild(this, name); 104 } catch (ChildNotRegisteredException ex) { 105 child = super.createChild(name); 107 } 108 109 return child; 111 } 112 113 114 117 public void forwardTo(RequestContext requestContext) throws NavigationException { 118 getParentViewBean().forwardTo(requestContext); 119 } 120 121 122 126 135 public Object getValue() { 136 if (((DisplayField)getChild(START_DATE_TEXT)).getValue() != null) { 138 if (_validateCheck != getRequestContext()) { 140 validateDataInput(); 141 _validateCheck = getRequestContext(); 142 } 143 } 144 return getModel().getStartDateTime(); 145 } 146 147 148 154 public String stringValue() { 155 Object value = getValue(); 156 if (value == null) { 157 return ""; 158 } 159 return value.toString(); 160 } 161 162 163 172 public void setValue(Object value) { 173 if (value == null) { 174 return; 175 } 176 Date date = null; 177 if (value instanceof Date ) { 178 date = (Date )value; 179 } else { 180 try { 181 DateFormat df = DateFormat.getDateTimeInstance( 182 DateFormat.MEDIUM, 183 DateFormat.MEDIUM, 184 getRequestContext().getRequest().getLocale()); 185 date = df.parse((String )value); 186 } catch (ParseException ex) { 187 throw new FrameworkException( 188 "Unable to set CCDateTime value: '"+value+ 189 "' for CCDateTime field '"+getName()+"'.", ex, 190 getViewDescriptor(), this); 191 } 192 } 193 getModel().setStartDateTime(date); 194 } 195 196 197 205 public Object [] getValues() { 206 return new Object [] {getValue()}; 207 } 208 209 210 218 public void setValues(Object [] values) { 219 throw new FrameworkException( 220 "setValues() not supported.", getViewDescriptor(), this); 221 } 222 223 224 230 public DisplayFieldDescriptor getDescriptor() { 231 return null; 232 } 233 234 235 239 247 public void beginDisplay(DisplayEvent event) throws ModelControlException { 248 DescriptorViewHelper.beginDisplay(this, event); 249 super.beginDisplay(event); 250 } 251 252 253 257 public boolean beginChildDisplay(ChildDisplayEvent event) throws ModelControlException { 258 try { 259 return DescriptorViewHelper.beginChildDisplay(this, event); 260 } catch (Exception ex) { 261 throw new FrameworkException(ex, getViewDescriptor(), this); 262 } 263 } 264 265 266 270 public String endChildDisplay(ChildContentDisplayEvent event) throws ModelControlException { 271 return DescriptorViewHelper.endChildDisplay(this, event); 272 } 273 274 275 279 public void endDisplay(DisplayEvent event) { 280 DescriptorViewHelper.endDisplay(this, event); 281 super.endDisplay(event); 282 } 283 284 285 303 public void registerViewDescriptorChildren() { 304 DescriptorViewHelper.registerViewDescriptorChildren(getViewDescriptor(), this); 305 } 306 307 308 private RequestContext _ctx = null; 309 private RequestContext _validateCheck = null; 310 private ViewDescriptor _viewDesc = null; 311 } 312 | Popular Tags |