001: package com.technoetic.xplanner.forms;
002:
003: import java.text.ParseException;
004: import java.text.SimpleDateFormat;
005: import java.util.Date;
006: import javax.servlet.http.HttpServletRequest;
007:
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionMapping;
011:
012: import com.technoetic.xplanner.domain.UserStory;
013: import com.technoetic.xplanner.domain.TaskDisposition;
014:
015: public class TaskEditorForm extends AbstractEditorForm {
016: private static SimpleDateFormat dateConverter;
017: private String name;
018: private String description;
019: private Date createdDate;
020: private String createdDateString;
021: private int storyId;
022: private int targetStoryId;
023: private int acceptorId;
024: private double estimatedHours;
025: private double actualHours;
026: private String type;
027: private String dispositionName;
028: private boolean completed;
029:
030: public String getContainerId() {
031: return Integer.toString(getStoryId());
032: }
033:
034: public ActionErrors validate(ActionMapping mapping,
035: HttpServletRequest request) {
036: ActionErrors errors = new ActionErrors();
037:
038: if (dateConverter == null) {
039: String format = getResources(request).getMessage(
040: "format.date");
041: dateConverter = new SimpleDateFormat(format);
042: }
043:
044: // Set created date to be now
045: // if (createdDate == null) {
046: // setCreatedDate(new Date());
047: // }
048:
049: if (isSubmitted()) {
050: if (createdDateString != null) {
051: createdDate = null;
052: try {
053: createdDate = dateConverter
054: .parse(createdDateString);
055: } catch (ParseException ex) {
056: errors.add(ActionErrors.GLOBAL_ERROR,
057: new ActionError(
058: "task.editor.bad_created_date"));
059: }
060: }
061:
062: if (!isMerge()) {
063: require(errors, name, "task.editor.missing_name");
064: require(errors, estimatedHours >= 0.0,
065: "task.editor.negative_estimated_hours");
066: }
067: }
068: return errors;
069: }
070:
071: public void reset(ActionMapping mapping, HttpServletRequest request) {
072: super .reset(mapping, request);
073: name = null;
074: description = null;
075: storyId = 0;
076: targetStoryId = 0;
077: completed = false;
078: acceptorId = 0;
079: estimatedHours = 0;
080: actualHours = 0;
081: type = null;
082: dispositionName = null;
083: }
084:
085: public String getName() {
086: return name;
087: }
088:
089: public void setName(String name) {
090: this .name = name;
091: }
092:
093: public void setDescription(String description) {
094: this .description = description;
095: }
096:
097: public String getDescription() {
098: return description;
099: }
100:
101: public void setStoryId(int storyId) {
102: if (targetStoryId == 0) {
103: targetStoryId = storyId;
104: }
105: this .storyId = storyId;
106: }
107:
108: public int getStoryId() {
109: return storyId;
110: }
111:
112: public void setStory(UserStory story) {
113: this .storyId = story == null ? 0 : story.getId();
114: }
115:
116: public void setEstimatedHours(double estimatedHours) {
117: this .estimatedHours = estimatedHours;
118: }
119:
120: public double getEstimatedHours() {
121: return estimatedHours;
122: }
123:
124: public void setActualHours(double actualHours) {
125: this .actualHours = actualHours;
126: }
127:
128: public double getActualHours() {
129: return actualHours;
130: }
131:
132: public void setAcceptorId(int acceptorId) {
133: this .acceptorId = acceptorId;
134: }
135:
136: public int getAcceptorId() {
137: return acceptorId;
138: }
139:
140: public void setType(String type) {
141: this .type = type;
142: }
143:
144: public String getType() {
145: return type;
146: }
147:
148: public void setDispositionName(String dispositionName) {
149: this .dispositionName = dispositionName;
150: }
151:
152: public String getDispositionName() {
153: return dispositionName;
154: }
155:
156: public void setCompleted(boolean flag) {
157: this .completed = flag;
158: }
159:
160: public boolean isCompleted() {
161: return completed;
162: }
163:
164: public void setCreatedDateString(String createdDateString) {
165: this .createdDateString = createdDateString;
166: }
167:
168: public String getCreatedDateString() {
169: return createdDateString;
170: }
171:
172: public Date getCreatedDate() {
173: if (createdDate == null) {
174: setCreatedDate(new Date());
175: }
176:
177: return createdDate;
178: }
179:
180: public void setCreatedDate(Date createdDate) {
181: if (createdDate == null) {
182: createdDate = new Date();
183: }
184:
185: this .createdDate = createdDate;
186: createdDateString = dateConverter.format(createdDate);
187: }
188:
189: public int getTargetStoryId() {
190: return targetStoryId;
191: }
192:
193: public void setTargetStoryId(int targetStoryId) {
194: this.targetStoryId = targetStoryId;
195: }
196:
197: }
|