001 /** ===================================================================== 002 * 003 * File Name : $Id: FaultSolution.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: FaultSolution.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/FaultSolution.java,v 1.7 2008/01/15 11:08:16 cb Exp $ 036 * 037 * Log : $Log: FaultSolution.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 2007/12/12 15:26:15 cb 043 * Log : Added new javascript library which allows fancy message boxes to be 044 * Log : displayed. 045 * Log : 046 * Log : Revision 1.5 2007/08/17 14:24:30 cb 047 * Log : Removed the submit & reset buttons as these functions will now be 048 * Log : controlled through the submit and reset buttons on the main update 049 * Log : panel 050 * Log : 051 * Log : Revision 1.4 2007/08/17 07:26:46 cb 052 * Log : Added additional error reports. 053 * Log : 054 * Log : Revision 1.3 2007/08/01 13:00:07 cb 055 * Log : First prototype after import 056 * Log : 057 * Log : Revision 1.2 2007/07/13 10:54:08 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 solution which he has entered. The 085 * class makes extensive use of the google web toolkit. 086 * @author Craige Bevil 087 * @version $Id: FaultSolution.java,v 1.7 2008/01/15 11:08:16 cb Exp $ 088 */ 089 090 class FaultSolution extends FaultAddition { 091 092 /** 093 * This contains the details of the <b>current</b> solution if 094 * there is one entered into the database against the current 095 * fault 096 */ 097 098 private Solution CurrentSolutionDetails; 099 100 /** 101 * Constructor for the fault solution tab in the modify fault form 102 * @param FaultNumber This is the number of the defect report 103 * which this solution 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 */ 111 112 FaultSolution (final int FaultNumber, 113 final FaultServiceAsync svc, 114 final InternationalizationConstants internationalizationConstants, 115 final AuthenticationDetails userAuthentication, 116 final FaultUpdatedListener faultUpdateListener) { 117 118 super(FaultNumber,svc,internationalizationConstants,userAuthentication,faultUpdateListener); 119 120 setFormDefaultValues(); 121 } 122 123 /** 124 * Save the contents of the fault solution to the database 125 */ 126 127 void saveFormContentsToDatabase () { 128 129 final Solution solution = new Solution(); 130 131 // If the user has not entered anything into the solution 132 // main text box then we do nothing here. 133 134 if (!stringContainsText(FaultAdditionText.getHTML())) { 135 return; 136 } 137 138 // Verify that the user has entered something for the 139 // solution field and if not then we throw it back at him 140 // to sort it out. 141 142 try { 143 verifyText(internationalizationConstants.solutionDetails(),NOLENGTHCHECK,FaultAdditionText.getHTML()); 144 } catch (FieldInvalidException e) { 145 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.solutionDetails())); 146 return; 147 } 148 149 // Verify that the user has entered the amount of time 150 // spent in the correct format 151 152 if (!verifyTimeFormat(TimeSpent.textBox.getText())) { 153 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.timeFieldNotCompletedCorrectly(internationalizationConstants.timeSpent())); 154 return; 155 } 156 157 // If we get this far then everything is order to we can 158 // now go ahead and try and update the database with the 159 // details of the solution. 160 161 solution.description = FaultAdditionText.getHTML(); 162 solution.id = FaultNumber; 163 solution.enteredByEmail = EnteredBy.listBox.getValue(EnteredBy.listBox.getSelectedIndex()); 164 solution.timeSpent = TimeSpent.textBox.getText(); 165 166 // Now send the details of the solution down to the 167 // servlet so that it can be inserted into the database 168 169 svc.updateSolutionDetails (solution,new AsyncCallback() { 170 171 /** 172 * On success we clear the form and inform the user of 173 * the number of the defect which was assigned 174 */ 175 176 public void onSuccess (final Object result) { 177 178 // Now update the default values for the 179 // solution to be those which the user has 180 // just entered 181 182 CurrentSolutionDetails = solution; 183 184 // Inform any listener that we have updated 185 // the fault 186 187 if (faultUpdateListener != null) { 188 faultUpdateListener.faultUpdatedEvent(FaultNumber); 189 } 190 191 } 192 193 public void onFailure (Throwable ex) { 194 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToEnterSolution()); 195 } 196 }); 197 198 } 199 200 /** 201 * This will be used to set the default values which are 202 * associated with the fault solution. It will attempt to get the 203 * fields back from the database and populate the fields in the 204 * solution form. If there is no solution found then the default 205 * values of the form will be entered. 206 */ 207 208 void setFormDefaultValues () { 209 210 svc.getSolutionDetails (new Integer(FaultNumber),new AsyncCallback() { 211 212 public void onSuccess (final Object result) { 213 CurrentSolutionDetails = (Solution)result; 214 resetFormToDefaultValues(); 215 } 216 217 public void onFailure (Throwable ex) { 218 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToSolutionDetailsFromDatabase()); 219 } 220 }); 221 } 222 223 /** 224 * Reset the solution form to the solution data which is currently in the 225 * database for this fault. The attribute 226 * <b>CurrentSolutionDetails</B> holds the details of the current 227 * solution if there is one. If no fault 228 */ 229 230 void resetFormToDefaultValues() { 231 232 // If there is a solution associated with the fault then we 233 // display the values associated with that solution. 234 235 if (CurrentSolutionDetails == null) { 236 237 // Set the solution fields to be the default values. 238 239 FaultAdditionText.setHTML(""); 240 TimeSpent.textBox.setText("00:00"); 241 setSelectedItemInListbox(EnteredBy.listBox,userAuthentication.UserEmailAddress); 242 243 } else { 244 245 FaultAdditionText.setHTML(CurrentSolutionDetails.description); 246 TimeSpent.textBox.setText(CurrentSolutionDetails.timeSpent); 247 setSelectedItemInListbox(EnteredBy.listBox,CurrentSolutionDetails.enteredByEmail); 248 249 } 250 } 251 252 } 253