1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.control.form;
16
17 import org.figure8.join.control.JoinForm;
18 import org.figure8.join.control.action.StatusActions;
19
20 import org.apache.struts.action.ActionMapping;
21
22 import javax.servlet.http.HttpServletRequest;
23 /**
24 * Form object used for manipulating Steps into Join application.
25 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26 * @version $Revision: 1.1 $
27 *
28 * @struts.form name="statusForm"
29 */
30 public class StatusForm extends JoinForm{
31
32
33
34 /** The unique key of this status */
35 private String key;
36 /** The display label of this status */
37 private String label;
38 /** The type of process this status is for */
39 private String type;
40 /** Whether this status is terminal in process */
41 private boolean terminal;
42 /** Whether this status corresponds to a 'cancel' status in process */
43 private boolean cancelled;
44
45 /** String representation of <b>terminal</b> */
46 private String terminalStr;
47 /** String representation of <b>cancelled</b> */
48 private String cancelledStr;
49
50
51
52
53 /** Creates a new instance of StatusForm. */
54 public StatusForm(){
55 }
56
57
58
59
60 /** @return The unique key of this status */
61 public String getKey(){
62 return key;
63 }
64 /** @param key The unique key of this status */
65 public void setKey(String key){
66 this.key = key;
67 }
68 /** @return The display label of this status */
69 public String getLabel(){
70 return label;
71 }
72 /** @param label The label of this status */
73 public void setLabel(String label){
74 this.label = label;
75 }
76 /** @return The type of process this status is for */
77 public String getType(){
78 return type;
79 }
80 /** @param type The type of process this status is for */
81 public void setType(String type){
82 this.type = type;
83 }
84 /** @return Flag telling if status is terminal for a process */
85 public boolean isTerminal(){
86 return terminal;
87 }
88 /** @param terminal Flag telling if status is terminal for a process */
89 public void setTerminal(boolean terminal){
90 this.terminal = terminal;
91 this.terminalStr = String.valueOf(terminal);
92 }
93 /** @return Flag telling if status corresponds to a 'cancel' */
94 public boolean isCancelled(){
95 return cancelled;
96 }
97 /** @param cancelled Flag telling if status corresponds to a 'cancel' */
98 public void setCancelled(boolean cancelled){
99 this.cancelled = cancelled;
100 this.cancelledStr = String.valueOf(cancelled);
101 }
102
103 /** @return Flag telling if status is terminal for a process (should be a boolean) */
104 public String getTerminalStr(){
105 return terminalStr;
106 }
107 /** @param terminalStr Flag telling if status is terminal for a process (should be a boolean) */
108 public void setTerminalStr(String terminalStr){
109 this.terminalStr = terminalStr;
110 }
111 /** @return Flag telling if status corresponds to a 'cancel' (should be a boolean) */
112 public String getCancelledStr(){
113 return cancelledStr;
114 }
115 /** @param cancelledStr Flag telling if status corresponds to a 'cancel' */
116 public void setCancelledStr(String cancelledStr){
117 this.cancelledStr = cancelledStr;
118 }
119
120
121
122
123 /**
124 * Validation of the form attributes.
125 * @param operation String representing the operation to invoke on Action
126 * @param mapping Mapping between forwards name and path for this action
127 * @param request The servlet container request wrapper
128 */
129 public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
130
131 if (StatusActions.LOAD_OP.equals(operation)){
132
133 validateEntityObjectId();
134 }
135 else if (StatusActions.SAVE_OP.equals(operation)){
136
137 if (key == null || key.length() == 0)
138 addActionError("errors.required", getGuiMessageResources().getMessage("label.status.key"));
139
140 if (label == null || label.length() == 0)
141 addActionError("errors.required", getGuiMessageResources().getMessage("label.status.label"));
142
143
144 terminal = Boolean.valueOf(terminalStr).booleanValue();
145 cancelled = Boolean.valueOf(cancelledStr).booleanValue();
146
147 if (terminal && cancelled)
148 addActionError("errors.invalid", getGuiMessageResources().getMessage("label.status.cancelled"));
149 }
150 }
151
152
153
154
155 /**
156 * Reset form attributes.
157 * @param mapping Mapping between forwards name and path for this action
158 * @param request The servlet container request wrapper
159 */
160 public void reset(ActionMapping mapping, HttpServletRequest request){
161 super.reset(mapping, request);
162 key = null;
163 label = null;
164 type = null;
165 terminal = false;
166 cancelled = false;
167 terminalStr = null;
168 cancelledStr = null;
169 }
170 }