1 4 package org.oddjob.designer.model; 5 6 import java.text.ParseException ; 7 import java.util.Date ; 8 import java.util.Observable ; 9 import java.util.Observer ; 10 11 import org.oddjob.util.DateHelper; 12 13 14 18 public class DateInput extends Observable 19 implements DesignDefinition, FormDefinition { 20 21 private final String heading; 22 private final SimpleAttribute designElement; 23 24 public DateInput(String heading, SimpleAttribute de) { 25 this.heading = heading; 26 this.designElement = de; 27 designElement.addObserver(new Observer () { 28 public void update(Observable o, Object arg) { 29 setChanged(); 30 notifyObservers(); 31 } 32 }); 33 } 34 35 public String getTitle() { 36 return heading; 37 } 38 39 44 public void setDate(Date date) { 45 if (date == null) { 46 designElement.attribute(null); 47 } 48 else { 49 designElement.attribute(DateHelper.formatDate(date)); 50 } 51 } 52 53 58 public Date getDate() { 59 if (designElement.attribute() == null) { 60 return null; 61 } 62 try { 63 return DateHelper.parseDate(designElement.attribute()); 64 } catch (ParseException e) { 65 return null; 66 } 67 } 68 69 73 public void accept(DesignProcessor processor) { 74 processor.onDateInput(this); 75 } 76 77 80 public boolean isPopulated() { 81 return designElement.attribute() != null; 82 } 83 } 84 | Popular Tags |