001: package com.technoetic.xplanner.forms;
002:
003: import java.util.Date;
004: import javax.servlet.http.HttpServletRequest;
005:
006: import org.apache.struts.action.ActionErrors;
007: import org.apache.struts.action.ActionMapping;
008:
009: public class IterationEditorForm extends AbstractEditorForm {
010: private String name;
011: private String description;
012: private Date startDate;
013: private Date endDate;
014: private double daysWorked;
015: private String startDateString;
016: private String endDateString;
017: private String statusKey;
018: private int projectId;
019:
020: public String getContainerId() {
021: return Integer.toString(getProjectId());
022: }
023:
024: public ActionErrors validate(ActionMapping mapping,
025: HttpServletRequest request) {
026: initConverters(request);
027: ActionErrors errors = new ActionErrors();
028: if (isSubmitted()) {
029: require(errors, name, "iteration.editor.missing_name");
030: require(errors, startDateString,
031: "iteration.editor.bad_start_date");
032: require(errors, endDateString,
033: "iteration.editor.bad_end_date");
034: requirePositiveInterval(errors);
035: }
036: return errors;
037: }
038:
039: public void reset(ActionMapping mapping, HttpServletRequest request) {
040: super .reset(mapping, request);
041: name = null;
042: description = null;
043: startDateString = null;
044: endDateString = null;
045: projectId = 0;
046: dateConverter = null;
047: }
048:
049: private void requirePositiveInterval(ActionErrors errors) {
050: if (errors.size() == 0) {
051: startDate = convertToDate(startDateString,
052: "iteration.editor.bad_start_date", errors);
053: endDate = convertToDate(endDateString,
054: "iteration.editor.bad_end_date", errors);
055: if (startDate != null && endDate != null
056: && endDate.compareTo(startDate) <= 0) {
057: error(errors, "iteration.editor.nonpositive_interval");
058: }
059: }
060: }
061:
062: public String getName() {
063: return name;
064: }
065:
066: public void setName(String name) {
067: this .name = name;
068: }
069:
070: public String getStatusKey() {
071: return statusKey;
072: }
073:
074: public void setStatusKey(String statusKey) {
075: this .statusKey = statusKey;
076: }
077:
078: public void setDescription(String description) {
079: this .description = description;
080: }
081:
082: public String getDescription() {
083: return description;
084: }
085:
086: public void setStartDateString(String startDateString) {
087: this .startDateString = startDateString;
088: }
089:
090: public String getStartDateString() {
091: return startDateString;
092: }
093:
094: public void setEndDateString(String endDateString) {
095: this .endDateString = endDateString;
096: }
097:
098: public String getEndDateString() {
099: return endDateString;
100: }
101:
102: public void setProjectId(int projectId) {
103: this .projectId = projectId;
104: }
105:
106: public int getProjectId() {
107: return projectId;
108: }
109:
110: public Date getEndDate() {
111: return endDate;
112: }
113:
114: public void setEndDate(Date endDate) {
115: this .endDate = endDate;
116: endDateString = toString(endDate);
117: }
118:
119: public Date getStartDate() {
120: return startDate;
121: }
122:
123: public void setStartDate(Date startDate) {
124: this .startDate = startDate;
125: startDateString = toString(startDate);
126: }
127:
128: public double getDaysWorked() {
129: return daysWorked;
130: }
131:
132: public void setDaysWorked(double daysWorked) {
133: this .daysWorked = daysWorked;
134: }
135:
136: private String toString(Date date) {
137: return (date == null ? "" : dateConverter.format(date));
138: }
139:
140: }
|