001 /** =====================================================================
002 *
003 * File Name : $Id: FaultComment.java,v 1.7 2008/01/15 11:08:16 cb Exp $
004 *
005 * Description
006 * -----------
007 *
008 * See javadoc comment
009 *
010 * =====================================================================
011 *
012 * @Author : Craige Bevil
013 * Control Software Group
014 * Isaac Newton Group of Telescopes
015 *
016 * =====================================================================
017 *
018 * Modification Log
019 *
020 * Vers Date Author Reason
021 * ---- ---- ------ ------
022 * 1 20 Apr 2007 C.Bevil First Release
023 *
024 * Commissioning Notes
025 * -------------------
026 *
027 * None
028 *
029 * =====================================================================
030 *
031 * @Version : $Id: FaultComment.java,v 1.7 2008/01/15 11:08:16 cb Exp $
032 *
033 * @Author : $Author: cb $
034 *
035 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/FaultComment.java,v 1.7 2008/01/15 11:08:16 cb Exp $
036 *
037 * Log : $Log: FaultComment.java,v $
038 * Log : Revision 1.7 2008/01/15 11:08:16 cb
039 * Log : Ran through PMD and sorted out the javadoc so that we could export the
040 * Log : javadoc to the javadoc repository.
041 * Log :
042 * Log : Revision 1.6 2008/01/14 17:17:23 cb
043 * Log : Comment updated
044 * Log :
045 * Log : Revision 1.5 2007/12/12 15:26:16 cb
046 * Log : Added new javascript library which allows fancy message boxes to be
047 * Log : displayed.
048 * Log :
049 * Log : Revision 1.4 2007/08/17 14:24:31 cb
050 * Log : Removed the submit & reset buttons as these functions will now be
051 * Log : controlled through the submit and reset buttons on the main update
052 * Log : panel
053 * Log :
054 * Log : Revision 1.3 2007/08/01 13:00:08 cb
055 * Log : First prototype after import
056 * Log :
057 * Log : Revision 1.2 2007/07/13 10:54:09 cb
058 * Log : Complete interface prototype
059 * Log :
060 * Log : Revision 1.1.1.1 2007/06/01 08:33:26 cb
061 * Log : Imported using TkCVS
062 * Log :
063 *
064 * =====================================================================*/
065
066
067 package GWTApplication.client;
068
069 import com.google.gwt.user.client.*;
070 import com.google.gwt.user.client.rpc.*;
071 import com.google.gwt.user.client.ui.*;
072 import com.google.gwt.user.client.ui.FlexTable.*;
073
074 import com.gwtext.client.core.EventObject;
075 import com.gwtext.client.util.Format;
076 import com.gwtext.client.widgets.MessageBox;
077 import com.gwtext.client.widgets.MessageBoxConfig;
078
079 import java.util.*;
080
081 /**
082 * This class will be used to generate a tab at the bottom of the
083 * fault modification form which will allow the user to attached to
084 * the fault the details of a comment which he has entered. The
085 * class makes extensive use of the google web toolkit.
086 * @author Craige Bevil
087 * @version $Id: FaultComment.java,v 1.7 2008/01/15 11:08:16 cb Exp $
088 */
089
090 class FaultComment extends FaultAddition {
091
092 /**
093 * This contains the details of the current comment if there is
094 * one currently entered into the database against the current
095 * fault
096 */
097
098 private Comment CurrentCommentDetails;
099
100 /**
101 * Constructor for the fault comment tab in the modify fault form
102 * @param FaultNumber This is the number of the defect report
103 * which this comment is associated with.
104 * @param svc This is an object which can be used to invoke remote
105 * calls on the servlet.
106 * @param internationalizationConstants Used for
107 * internationalization.
108 * @param userAuthentication This contains the details of the
109 * authentication which was performed by the user.
110 * @param faultUpdateListener This is a listener object which will be called when the fault which is associated with this comment is updated in the database.
111 */
112
113 FaultComment (final int FaultNumber,
114 final FaultServiceAsync svc,
115 final InternationalizationConstants internationalizationConstants,
116 final AuthenticationDetails userAuthentication,
117 final FaultUpdatedListener faultUpdateListener) {
118
119 super(FaultNumber,svc,internationalizationConstants,userAuthentication,faultUpdateListener);
120
121 resetFormToDefaultValues();
122 }
123
124 /**
125 * Save the contents of the fault comment which has been added by
126 * the user to the database
127 */
128
129 public void saveFormContentsToDatabase () {
130
131 final Comment comment = new Comment();
132
133 // If the user has not entered anything into the comment
134 // main text box then we do nothing here.
135
136 if (!stringContainsText(FaultAdditionText.getHTML())) {
137 return;
138 }
139
140 // Verify that the user has entered something for the
141 // comment field and if not then we throw it back at him
142 // to sort it out.
143
144 try {
145 verifyText(internationalizationConstants.commentDetails(),NOLENGTHCHECK,FaultAdditionText.getHTML());
146 } catch (FieldInvalidException e) {
147 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.commentDetails()));
148 return;
149 }
150
151 // Verify that the user has entered the amount of time
152 // spent in the correct format
153
154 if (!verifyTimeFormat(TimeSpent.textBox.getText())) {
155 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.timeFieldNotCompletedCorrectly(internationalizationConstants.timeSpent()));
156 return;
157 }
158
159 // If we get this far then everything is order to we can
160 // now go ahead and try and update the database with the
161 // details of the comment.
162
163 comment.description = FaultAdditionText.getHTML();
164 comment.id = FaultNumber;
165 comment.enteredByEmail = EnteredBy.listBox.getValue(EnteredBy.listBox.getSelectedIndex());
166 comment.timeSpent = TimeSpent.textBox.getText();
167 comment.enteredByName = userAuthentication.Name;
168 comment.enteredBySurname = userAuthentication.Surname;
169
170 // Now send the details of the comment down to the
171 // servlet so that it can be inserted into the database
172
173 svc.updateCommentDetails (comment,new AsyncCallback() {
174
175 public void onSuccess (final Object result) {
176 //
177 }
178
179 public void onFailure (Throwable ex)
180 {
181 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToEnterComment());
182 }
183 });
184
185 }
186
187 /**
188 * This will be used to set the default values which are
189 * associated with the fault addition.
190 */
191
192 void setFormDefaultValues () {
193 resetFormToDefaultValues();
194 }
195
196 /**
197 * Reset the form to the values which are determined the default
198 * values which have been entered for the comment by the
199 * user. The attribute <b>CurrentCommentDetails</B> holds the
200 * details of the current comment if there is one.
201 */
202
203 void resetFormToDefaultValues() {
204
205 // If there is a comment associated with the fault then we
206 // display the values associated with that comment.
207
208 FaultAdditionText.setHTML("");
209 TimeSpent.textBox.setText("00:00");
210 setSelectedItemInListbox(EnteredBy.listBox,userAuthentication.UserEmailAddress);
211 }
212 }
213