001 /** =====================================================================
002 *
003 * File Name : $Id: ModifyFault.java,v 1.12 2008/01/15 11:08:15 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 16 Apr 2007 C.Bevil First Release
023 *
024 * Commissioning Notes
025 * -------------------
026 *
027 * None
028 *
029 * =====================================================================
030 *
031 * @Version : $Id: ModifyFault.java,v 1.12 2008/01/15 11:08:15 cb Exp $
032 *
033 * @Author : $Author: cb $
034 *
035 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/ModifyFault.java,v 1.12 2008/01/15 11:08:15 cb Exp $
036 *
037 * Log : $Log: ModifyFault.java,v $
038 * Log : Revision 1.12 2008/01/15 11:08:15 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.11 2008/01/10 16:13:35 cb
043 * Log : Updated so we check that the assigned to and the fault type field has
044 * Log : been set to something other than unknown before it is saved when the
045 * Log : state of the fault is set to resolved.
046 * Log :
047 * Log : Revision 1.10 2007/12/12 15:26:13 cb
048 * Log : Added new javascript library which allows fancy message boxes to be
049 * Log : displayed.
050 * Log :
051 * Log : Revision 1.9 2007/10/08 15:37:20 cb
052 * Log : Tried to syncronise the sending of the email which informs the user
053 * Log : that a fault has changed with the updating of all of the details of
054 * Log : the fault in the database after the user has attempted to save it.
055 * Log :
056 * Log : Revision 1.8 2007/09/04 14:11:36 cb
057 * Log : Move back to the quick view display after fault updated. Only display
058 * Log : fault updated dialog after ALL entries in the update have been saved
059 * Log :
060 * Log : Revision 1.7 2007/08/17 14:26:41 cb
061 * Log : Updated for lastest prototype incorporating a lot of Nikos comments
062 * Log :
063 * Log : Revision 1.6 2007/08/17 08:18:14 cb
064 * Log : Updated error handling, removed staff who are no longer here from the lists
065 * Log :
066 * Log : Revision 1.5 2007/08/09 08:34:59 cb
067 * Log : Modified so that we select a different tab in the main menu when we do
068 * Log : not have any more faults to update.
069 * Log :
070 * Log : Revision 1.4 2007/08/01 13:00:05 cb
071 * Log : First prototype after import
072 * Log :
073 * Log : Revision 1.3 2007/07/26 14:12:28 cb
074 * Log : Updated to check that if the fault is updated from this interface that
075 * Log : we syncronise the time of the lastmodification so that we do not get a
076 * Log : warning when we updated the fault information.
077 * Log :
078 * Log : Revision 1.2 2007/07/13 10:54:05 cb
079 * Log : Complete interface prototype
080 * Log :
081 * Log : Revision 1.1.1.1 2007/06/01 08:33:26 cb
082 * Log : Imported using TkCVS
083 * Log :
084 *
085 * =====================================================================*/
086
087 package GWTApplication.client;
088
089 import com.google.gwt.user.client.*;
090 import com.google.gwt.user.client.rpc.*;
091 import com.google.gwt.user.client.ui.*;
092 import com.google.gwt.user.client.ui.FlexTable.*;
093
094 import com.gwtext.client.core.EventObject;
095 import com.gwtext.client.util.Format;
096 import com.gwtext.client.widgets.MessageBox;
097 import com.gwtext.client.widgets.MessageBoxConfig;
098
099 // Import the rich text widget
100
101 import com.jpavel.gwt.wysiwyg.client.*;
102
103 import java.util.*;
104
105 /**
106 * This class will be used to generate a form from which the user may
107 * be able to modify and update existing faults within the
108 * fault management system. In order to perform such duties, the user
109 * must have authenticated himself against the system and have
110 * sufficient privileges to perform such actions.
111 *<P>
112 * In addition to being able to modify the details of a fault, the
113 * user will be able to associate with a fault, a comment, a
114 * workaround or a solution.
115 * @author Craige Bevil
116 * @version $Id: ModifyFault.java,v 1.12 2008/01/15 11:08:15 cb Exp $
117 */
118
119 class ModifyFault extends FaultDBForm implements ClickListener, FaultUpdatedListener {
120
121 /**
122 * This is the main tab panel
123 */
124
125 final private TabPanel MainTabPanel;
126
127 /**
128 * Button which is used for submitting the changes which have been
129 * made to a fault to the servlet container
130 */
131
132 Button SubmitFaultModificationsButton;
133
134 /**
135 * Button which will be used to reject any changes which have been
136 * made to the form and reset them to the default values in the
137 * database.
138 */
139
140 Button ResetFaultModificationsButton;
141
142 /**
143 * This button will be used to cancel the form
144 */
145
146 Button CancelFormButton;
147
148 /**
149 * This is the tab panel which contains the update fault form
150 */
151
152 TabPanel FaultContainerPanel = null;
153
154 /**
155 * This is the fault number which is associated with the fault
156 * which is being edited
157 */
158
159 int FaultNumber;
160
161 /**
162 * This is the details of the fault which is being edited as they
163 * came from the database
164 */
165
166 Fault FaultBeingEdited = null;
167
168 /**
169 * This is a hash map which contains the details of all of the
170 * widgets which are contained within the form
171 */
172
173 HashMap InputFieldWidgets = new HashMap();
174
175 /**
176 * This table is used to hold all of the widgets within the form.
177 */
178
179 FlexTable ModifyFaultTable = new FlexTable();
180
181 /**
182 * This tab panel is located at the foot of the form and will
183 * allow the user to add a comment, a solution or a workarounds to
184 * the fault
185 */
186
187 TabPanel FaultAdditionPanel = new TabPanel();
188
189 /**
190 * This is an instance of the object which will allow the user to
191 * enter the details of the comments which will be associated with
192 * the fault
193 */
194
195 final FaultComment FaultCommentPanel;
196
197 /**
198 * This is an instance of the object which will allow the user to
199 * associate with the fault, the details of the solution which has
200 * been performed
201 */
202
203 final FaultSolution FaultSolutionPanel;
204
205 /**
206 * This is an instance of the object which will allow the user to
207 * associate with a fault, the details of a workaround which has
208 * been performed
209 */
210
211 final FaultWorkAround FaultWorkAroundPanel;
212
213 /**
214 * A count of the number of asynchronous subtasks which are
215 * performed when the form is created. There are two subtasks
216 * which are involved, one of creating the form and the second is
217 * the retrieval of the fault data from the servlet.
218 */
219
220 int noOfSubTasksCompleted = 0;
221
222 /**
223 * This is implements the obligation of the ClickListener
224 * interface and will be called when the user presses various
225 * buttons on the interface. It is a callback for the following
226 * buttons.
227 *<P>
228 * <OL>
229 * <li> The Submit button
230 * <LI> The Cancel form button
231 * <li> The Reset form button
232 * </ol>
233 * @param sender The widget which was responsible for firing the click event.
234 */
235
236 public void onClick (final Widget sender) {
237
238 // If the user pressed the submit button on the form then
239 // validate and submit changes to the database
240
241 if (sender.equals(SubmitFaultModificationsButton)) {
242
243 // First verify that all of the fields are in the correct
244 // format before we attempt ot send the data down to the
245 // servlet for saving
246
247 try {
248 final Editor temp = (Editor)InputFieldWidgets.get("DESCRIPTION");
249 verifyText(internationalizationConstants.description(), NOLENGTHCHECK, temp.getHTML());
250 } catch (FieldInvalidException e) {
251 MessageBox.alert(internationalizationConstants.information(),e.getMessage());
252 return;
253 }
254
255 try {
256 LabelTextBox temp = (LabelTextBox)InputFieldWidgets.get("TITLE");
257 verifyText(internationalizationConstants.title(), 200 , temp.textBox.getText());
258 } catch (FieldInvalidException e) {
259 MessageBox.alert(internationalizationConstants.information(),e.getMessage());
260 return;
261 }
262
263 // Now verify that the time and date fields are in the correct format
264
265 if (!verifyTimeFormat(((LabelTextBox)InputFieldWidgets.get("TIMEOCCURED")).textBox.getText())) {
266 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.timeFieldNotCompletedCorrectly(internationalizationConstants.timeOccured()));
267 return;
268 }
269
270 if (!verifyDateFormat(((LabelTextBox)InputFieldWidgets.get("DATEOCCURED")).textBox.getText())) {
271 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.dateFieldNotCompletedCorrectly(internationalizationConstants.dateOccured()));
272 return;
273 }
274
275 // Now we can update the database with the modified values
276
277 final Fault faultUpdateDetails = new Fault();
278
279 // Send down the time of last modification for the details
280 // of the fault that we were modifying so that we can
281 // check to ensure that we are not overwriting
282 // information which has since been updated in the
283 // database
284
285 faultUpdateDetails.lastModified = FaultBeingEdited.lastModified;
286
287 faultUpdateDetails.id = FaultNumber;
288
289 faultUpdateDetails.title = ((LabelTextBox)InputFieldWidgets.get("TITLE")).textBox.getText();
290
291 faultUpdateDetails.description = ((Editor)InputFieldWidgets.get("DESCRIPTION")).getHTML();
292
293 faultUpdateDetails.timeOccured = ((LabelTextBox)InputFieldWidgets.get("TIMEOCCURED")).textBox.getText();
294
295 faultUpdateDetails.dateOccured = ((LabelTextBox)InputFieldWidgets.get("DATEOCCURED")).textBox.getText();
296
297 faultUpdateDetails.timeLost = ((LabelTextBox)InputFieldWidgets.get("TIMELOST")).textBox.getText();
298
299 faultUpdateDetails.observer = ((LabelTextBox)InputFieldWidgets.get("OBSERVER")).textBox.getText();
300
301 ListBox tmp;
302
303 tmp = ((LabelListBox)InputFieldWidgets.get("PRIORITY")).listBox;
304 faultUpdateDetails.priority = Integer.parseInt(tmp.getValue(tmp.getSelectedIndex()));
305
306 tmp = ((LabelListBox)InputFieldWidgets.get("FAULTTYPE")).listBox;
307 faultUpdateDetails.faultType_id = tmp.getValue(tmp.getSelectedIndex());
308
309 tmp = ((LabelListBox)InputFieldWidgets.get("ASSIGNED")).listBox;
310 faultUpdateDetails.assignedToEmail = tmp.getValue(tmp.getSelectedIndex());
311
312 tmp = ((LabelListBox)InputFieldWidgets.get("TELESCOPEOPERATOR")).listBox;
313 faultUpdateDetails.telescopeOperatorEmail = tmp.getValue(tmp.getSelectedIndex());
314
315 tmp = ((LabelListBox)InputFieldWidgets.get("SITE")).listBox;
316 faultUpdateDetails.site_id =tmp.getValue(tmp.getSelectedIndex());
317
318 tmp = ((LabelListBox)InputFieldWidgets.get("SYSTEM")).listBox;
319 faultUpdateDetails.system_id =tmp.getValue(tmp.getSelectedIndex());
320
321 tmp = ((LabelListBox)InputFieldWidgets.get("STATUS")).listBox;
322 faultUpdateDetails.state_id =tmp.getValue(tmp.getSelectedIndex());
323
324 tmp = ((LabelListBox)InputFieldWidgets.get("INSTRUMENT")).listBox;
325 faultUpdateDetails.instrument_id =tmp.getValue(tmp.getSelectedIndex());
326
327 tmp = ((LabelListBox)InputFieldWidgets.get("DUTYTECHNICIAN")).listBox;
328 faultUpdateDetails.dutyTechnicianEmail =tmp.getValue(tmp.getSelectedIndex());
329
330 tmp = ((LabelListBox)InputFieldWidgets.get("SUPPORTASTRONOMER")).listBox;
331 faultUpdateDetails.supportAstronomerEmail =tmp.getValue(tmp.getSelectedIndex());
332
333 tmp = ((LabelListBox)InputFieldWidgets.get("SEVERITY")).listBox;
334 faultUpdateDetails.severity_id = tmp.getValue(tmp.getSelectedIndex());
335
336 // When the user attempts to update a fault, we need to
337 // make sure that the if the state of the fault is being
338 // set to resolved, that the fields assigned to and fault
339 // type are not set to unknown
340
341 if (faultUpdateDetails.state_id.equals("RESOLVED")) {
342
343 // Ensure that the assigned field is not set to unknown
344
345 if (faultUpdateDetails.assignedToEmail.equals("UNKNOWN")) {
346 Window.alert(internationalizationConstants.assignedToFieldIsNotAssigned());
347 return;
348 }
349
350 // Ensure that the fault type is not set to unknown
351
352 if (faultUpdateDetails.faultType_id.equals("UNKNOWN")) {
353 Window.alert(internationalizationConstants.faultTypeFieldIsNotAssigned());
354 return;
355 }
356 }
357
358 // Now update the fault in the database
359
360 svc.updateFault (faultUpdateDetails, internationalizationConstants.locale(),new AsyncCallback() {
361
362 /**
363 * Inform the user that the fault was updated in the database
364 * the number of the defect which was assigned
365 */
366
367 public void onSuccess (final Object result) {
368
369 // Now we need to get the details of the fault back to
370 // update the details of the fault which is being edited
371 // otherwise the reset button will not work any longer
372
373 svc.getFaultDetails (new Integer(FaultNumber), internationalizationConstants.locale(),new AsyncCallback() {
374
375 public void onSuccess (final Object result) {
376
377 FaultBeingEdited = (Fault)result;
378
379 // Now save the data which is included in the other forms
380 // as well such as the solution, workaround and the
381 // comment form
382
383 FaultCommentPanel.saveFormContentsToDatabase();
384 FaultSolutionPanel.saveFormContentsToDatabase();
385 FaultWorkAroundPanel.saveFormContentsToDatabase();
386
387 // After saving the fault we should return to the quick
388 // view panel after removing the update page.
389
390 removeUpdateTab();
391
392 svc.informEmailListenersFaultHasChanged ("The details of this fault have been changed", FaultNumber,null);
393 }
394
395 public void onFailure (Throwable ex) {
396 }
397 });
398
399 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.faultUpdated(FaultNumber));
400 }
401
402 public void onFailure (Throwable ex)
403 {
404 MessageBox.alert(internationalizationConstants.information(),ex.getMessage());
405 }
406 });
407
408 } else if (sender.equals(ResetFaultModificationsButton)) {
409
410 // Reset the form to the current value of the fault in the
411 // database and discard the changes
412
413 MessageBox.confirm(internationalizationConstants.confirm(),internationalizationConstants.areYouSureYouWantToResetTheForm(),new MessageBox.ConfirmCallback() {
414
415 public void execute(String btnID) {
416
417 if ("yes".equals(btnID)) {
418
419 // Now reset all of the forms which are used to input
420 // fault details such as the fault, solution, workaround
421 // and the comment form
422
423 resetFormToDefaultValues();
424
425 // Record which tab has bee selected in the fault addition
426 // panel and remember it.
427 //
428 // I should point out that I have to select the tab BEFORE
429 // I reset the contents of the HTML WYSIWG editor as if
430 // the editor is NOT visible when the contents are
431 // refreshed, it creates havoc with firefox. I have
432 // reported the problem.
433
434 final int currentlySelectedTab = FaultAdditionPanel.getTabBar().getSelectedTab();
435
436 FaultAdditionPanel.selectTab(FaultDatabaseConstants.COMMENTTAB);
437 FaultCommentPanel.resetFormToDefaultValues();
438
439 FaultAdditionPanel.selectTab(FaultDatabaseConstants.SOLUTIONTAB);
440 FaultSolutionPanel.resetFormToDefaultValues();
441
442 FaultAdditionPanel.selectTab(FaultDatabaseConstants.WORKAROUNDTAB);
443 FaultWorkAroundPanel.resetFormToDefaultValues();
444
445 FaultAdditionPanel.selectTab(currentlySelectedTab);
446
447 }
448 }
449 });
450
451
452 } else if (sender.equals(CancelFormButton)) {
453
454 // Cancel the form and remove it from the interface
455
456 if (Window.confirm(internationalizationConstants.confirmLoseFaultDetails())) {
457
458 FaultContainerPanel.remove(this);
459
460 // Now if there is another tab in the update tab
461 // panel we should select that, otherwise we should
462 // select a different tab in the main tab
463
464 if (FaultContainerPanel.getTabBar().getTabCount() != 0) {
465 FaultContainerPanel.selectTab(0);
466 } else {
467
468 // Select another tab in the main tab panel if
469 // there are no faults left for edit, the quick
470 // view panel.
471
472 MainTabPanel.selectTab(1);
473 }
474 }
475 }
476 }
477
478 /**
479 * Discard the exisiting changes that the user has made to the
480 * form and rest the contents to the values from the database.
481 */
482
483 void resetFormToDefaultValues () {
484
485 // Make sure we have the details of the fault to be edited
486
487 if (FaultBeingEdited == null) {
488 MessageBox.alert(internationalizationConstants.information(),"Unable to find the details of the fault to be edited");
489 return;
490 }
491
492 /*
493 * Now fill in all of the fields which are in the form
494 */
495
496 // Description field
497
498 final Editor temp = (Editor)InputFieldWidgets.get("DESCRIPTION");
499 temp.setHTML(FaultBeingEdited.description);
500
501 // Title field
502
503 LabelTextBox a = (LabelTextBox)InputFieldWidgets.get("TITLE");
504 a.textBox.setText(FaultBeingEdited.title);
505
506 // Label at the top of the edit fault tab
507
508 Label tmpLabel = (Label)InputFieldWidgets.get("SUMMARY");
509
510 tmpLabel.setText("By " + FaultBeingEdited.enteredByName + " " + FaultBeingEdited.enteredBySurname + " " + internationalizationConstants.at() + " " +
511 FaultBeingEdited.timeEntered + " " + internationalizationConstants.onThe() + " " + FaultBeingEdited.dateEntered);
512
513 tmpLabel.setStyleName("modifyFaultTitleLabel");
514
515 // Now set the time and date occurred field
516
517 a = (LabelTextBox)InputFieldWidgets.get("DATEOCCURED");
518 a.textBox.setText(FaultBeingEdited.dateOccured);
519
520 a = (LabelTextBox)InputFieldWidgets.get("TIMEOCCURED");
521 a.textBox.setText(FaultBeingEdited.timeOccured);
522
523 // The amount of time list field due to the fault
524
525 a = (LabelTextBox)InputFieldWidgets.get("TIMELOST");
526 a.textBox.setText(FaultBeingEdited.timeLost);
527
528 // The observer field
529
530 a = (LabelTextBox)InputFieldWidgets.get("OBSERVER");
531 a.textBox.setText(FaultBeingEdited.observer);
532
533 // Now we need to select the options in the drop down menus
534 // which were chosen when the fault was originally entered
535 // into the system.
536
537 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("SYSTEM")).listBox,FaultBeingEdited.system_id)) {
538 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.system + " in the system drop down");
539 }
540
541 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("FAULTTYPE")).listBox,FaultBeingEdited.faultType_id)) {
542 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.faultType + " in the fault type drop down");
543 }
544
545 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("SUPPORTASTRONOMER")).listBox,FaultBeingEdited.supportAstronomerEmail)) {
546 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.supportAstronomerEmail + " in the support astronomer drop down");
547 }
548
549 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("DUTYTECHNICIAN")).listBox,FaultBeingEdited.dutyTechnicianEmail)) {
550 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.dutyTechnicianEmail + " in the duty technician drop down");
551 }
552
553 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("SEVERITY")).listBox,FaultBeingEdited.severity_id)) {
554 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.severity + " in the severity drop down");
555 }
556
557 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("ASSIGNED")).listBox,FaultBeingEdited.assignedToEmail)) {
558 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.assignedToEmail + " in the assigned to drop down");
559 }
560
561 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("SITE")).listBox,FaultBeingEdited.site_id)) {
562 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.site + " in the site drop down");
563 }
564
565 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("PRIORITY")).listBox,Integer.toString(FaultBeingEdited.priority))) {
566 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.priority + " in the priority drop down");
567 }
568
569 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("STATUS")).listBox,FaultBeingEdited.state_id)) {
570 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.state + " in the status drop down");
571 }
572
573 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("TELESCOPEOPERATOR")).listBox,FaultBeingEdited.telescopeOperatorEmail)) {
574 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.telescopeOperatorEmail + " in the TO drop down");
575 }
576
577 if (!setSelectedItemInListbox(((LabelListBox)InputFieldWidgets.get("INSTRUMENT")).listBox,FaultBeingEdited.instrument_id)) {
578 MessageBox.alert(internationalizationConstants.information(),"Unable to find the value " + FaultBeingEdited.instrument + " in the instrument drop down");
579 }
580
581 }
582
583 /**
584 * This is used to create the form which will be used to enter the
585 * modify the details of the fault. It will get back from the
586 * servlet the details of the fault and then populate the form
587 * accordingly.
588 * @param FaultNumber This is the number of the defect fault which
589 * is to be edited.
590 * @param svc This is a service reference which will be used to access the servlet in the tomcat container
591 * @param internationalizationConstants Used for internationalization of the interface
592 * @param FaultContainerPanel This is the tab panel in which the form is to be packed.
593 * @param MainTabPanel This is the main tab panel, on occasion we
594 * need to be able to select tabs in this panel.
595 */
596
597 ModifyFault (final int FaultNumber,
598 final FaultServiceAsync svc,
599 final InternationalizationConstants internationalizationConstants,
600 final TabPanel FaultContainerPanel,
601 final AuthenticationDetails UserAuthentication,
602 final TabPanel MainTabPanel) {
603
604 this.internationalizationConstants = internationalizationConstants;
605 this.svc = svc;
606 this.FaultNumber = FaultNumber;
607 this.FaultContainerPanel = FaultContainerPanel;
608 this.UserAuthentication = UserAuthentication;
609 this.MainTabPanel = MainTabPanel;
610
611 initWidget(ModifyFaultTable);
612
613 final FlexCellFormatter formatter = (FlexCellFormatter)ModifyFaultTable.getCellFormatter();
614
615 // Get the details of the fault from the servlet Now we need
616 // to send the data across to the servlet which will be
617 // responsible for storing the data in the database
618
619 busyIndicator.showBusy(true);
620
621 // Create the fault comment, workarouna and solution panels
622
623 FaultCommentPanel = new FaultComment(FaultNumber,svc,internationalizationConstants,UserAuthentication,this);
624 FaultSolutionPanel = new FaultSolution(FaultNumber,svc,internationalizationConstants,UserAuthentication,this);
625 FaultWorkAroundPanel = new FaultWorkAround(FaultNumber,svc,internationalizationConstants,UserAuthentication,this);
626
627 svc.getFaultDetails (new Integer(FaultNumber), internationalizationConstants.locale(),new AsyncCallback() {
628
629 /**
630 * On success we clear the form and inform the user of
631 * the number of the defect which was assigned
632 */
633
634 public void onSuccess (final Object result) {
635 FaultBeingEdited = (Fault)result;
636 noOfSubTasksCompleted++;
637 }
638
639 public void onFailure (Throwable ex)
640 {
641 MessageBox.alert(internationalizationConstants.information(),"Unable to get the fault data back for fault " + FaultNumber + " for editing");
642 }
643 });
644
645 // First row in the table is a summary of the read only
646 // aspects of the fault
647
648 Label temp = new Label();
649
650 temp = new Label("Unknown");
651 InputFieldWidgets.put("SUMMARY",temp);
652 temp.setStyleName("system-LabelHighlight");
653 ModifyFaultTable.setWidget(0,0,temp);
654 formatter.setColSpan(0,0,4);
655
656 // Second row in the table is the title bar
657
658 LabelTextBox tempTextBox = new LabelTextBox(LabelTextBox.VERTICAL);
659
660 tempTextBox.label.setText(internationalizationConstants.title());
661 tempTextBox.textBox.setVisibleLength(100);
662 tempTextBox.setWidth("100%");
663
664 InputFieldWidgets.put("TITLE",tempTextBox);
665
666 ModifyFaultTable.setWidget(1,0,tempTextBox);
667
668 formatter.setColSpan(1,0,4);
669
670 // This is the field into which the user can change the text
671 // of the description
672
673 final Editor description = new Editor();
674
675 //description.setVisibleLines(15);
676 description.setWidth("100%");
677 description.setHeight("300px");
678
679 ModifyFaultTable.setWidget(3,0,description);
680
681 formatter.setColSpan(3,0,4);
682 formatter.setRowSpan(3,0,3);
683
684 InputFieldWidgets.put("DESCRIPTION",description);
685
686 // The Fault Type
687
688 LabelListBox tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
689
690 tempListBox.label.setText(internationalizationConstants.faultType());
691 tempListBox.setWidth("4cm","4cm");
692 tempListBox.listBox.setVisibleItemCount(1);
693
694 InputFieldWidgets.put("FAULTTYPE",tempListBox);
695 ModifyFaultTable.setWidget(6,0,tempListBox);
696
697 fillListBoxWithFaultType(tempListBox.listBox,internationalizationConstants.locale());
698
699 // The Severity Field
700
701 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
702
703 tempListBox.label.setText(internationalizationConstants.severity());
704 tempListBox.setWidth("4cm","4cm");
705 tempListBox.listBox.setVisibleItemCount(1);
706
707 InputFieldWidgets.put("SEVERITY",tempListBox);
708 ModifyFaultTable.setWidget(6,1,tempListBox);
709
710 fillListBoxWithSeverity(tempListBox.listBox,internationalizationConstants.locale());
711
712 // The Site Field
713
714 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
715
716 tempListBox.label.setText(internationalizationConstants.site());
717 tempListBox.setWidth("4cm","4cm");
718 tempListBox.listBox.setVisibleItemCount(1);
719
720 InputFieldWidgets.put("SITE",tempListBox);
721 ModifyFaultTable.setWidget(6,2,tempListBox);
722
723 fillListBoxWithSites(tempListBox.listBox,internationalizationConstants.locale());
724
725 // The Duty Technician
726
727 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
728
729 tempListBox.label.setText(internationalizationConstants.dutyTechnician());
730 tempListBox.setWidth("4cm","4cm");
731 tempListBox.listBox.setVisibleItemCount(1);
732
733 InputFieldWidgets.put("DUTYTECHNICIAN",tempListBox);
734 ModifyFaultTable.setWidget(7,0,tempListBox);
735
736 fillListBoxWithDutyTechnicians(tempListBox.listBox,null,false);
737
738 // 2nd row in the table
739
740 // Assigned To
741
742 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
743
744 tempListBox.label.setText(internationalizationConstants.assignedTo());
745 tempListBox.listBox.setVisibleItemCount(1);
746
747 tempListBox.setWidth("4cm","4cm");
748 InputFieldWidgets.put("ASSIGNED",tempListBox);
749 ModifyFaultTable.setWidget(7,1,tempListBox);
750
751 fillListBoxWithStaffMembers(tempListBox.listBox,null,false);
752
753 // The Priority
754
755 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
756
757 tempListBox.label.setText(internationalizationConstants.priority());
758 tempListBox.listBox.setVisibleItemCount(1);
759 tempListBox.setWidth("4cm","4cm");
760
761 InputFieldWidgets.put("PRIORITY",tempListBox);
762 ModifyFaultTable.setWidget(7,2,tempListBox);
763
764 tempListBox.listBox.addItem("1","1");
765 tempListBox.listBox.addItem("2","2");
766 tempListBox.listBox.addItem("3","3");
767 tempListBox.listBox.addItem("4","4");
768 tempListBox.listBox.addItem("5","5");
769
770 // The Support Astronomer
771
772 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
773
774 tempListBox.label.setText(internationalizationConstants.supportAstronomer());
775 tempListBox.setWidth("4cm","4cm");
776 tempListBox.listBox.setVisibleItemCount(1);
777
778 InputFieldWidgets.put("SUPPORTASTRONOMER",tempListBox);
779 ModifyFaultTable.setWidget(8,0,tempListBox);
780
781 fillListBoxWithSupportAstronomers(tempListBox.listBox,null,false);
782
783 // The Telescope Operator
784
785 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
786
787 tempListBox.label.setText(internationalizationConstants.telescopeOperator());
788 tempListBox.setWidth("4cm","4cm");
789 tempListBox.listBox.setVisibleItemCount(1);
790
791 InputFieldWidgets.put("TELESCOPEOPERATOR",tempListBox);
792
793 ModifyFaultTable.setWidget(8,1,tempListBox);
794
795 fillListBoxWithTelescopeOperators(tempListBox.listBox,null,false);
796
797 // Now the text based fields which the user can enter data
798 // into
799
800 // The time that the fault occurred
801
802 tempTextBox = new LabelTextBox(LabelTextBox.HORIZONTAL);
803
804 tempTextBox.label.setText(internationalizationConstants.timeOccured());
805 tempTextBox.setWidth("4cm","4cm");
806 tempTextBox.label.setTitle("The time that the fault occured (HH:MM)");
807 InputFieldWidgets.put("TIMEOCCURED",tempTextBox);
808
809 ModifyFaultTable.setWidget(8,2,tempTextBox);
810
811
812 // The time that the fault occurred
813
814 tempTextBox = new LabelTextBox(LabelTextBox.HORIZONTAL);
815
816 tempTextBox.label.setText(internationalizationConstants.timeLost());
817 tempTextBox.setWidth("4cm","4cm");
818 tempTextBox.label.setTitle("The time that was lost to the fault");
819 InputFieldWidgets.put("TIMELOST",tempTextBox);
820
821 ModifyFaultTable.setWidget(10,0,tempTextBox);
822
823 // The instrument
824
825 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
826
827 tempListBox.label.setText(internationalizationConstants.instrument());
828 tempListBox.setWidth("4cm","4cm");
829 tempListBox.listBox.setVisibleItemCount(1);
830
831 InputFieldWidgets.put("INSTRUMENT",tempListBox);
832 ModifyFaultTable.setWidget(9,1,tempListBox);
833
834 fillListBoxWithInstruments(tempListBox.listBox,internationalizationConstants.locale());
835
836 // The observer which is associated with the fault.
837
838 tempTextBox = new LabelTextBox(LabelTextBox.HORIZONTAL);
839
840 tempTextBox.label.setText(internationalizationConstants.observer());
841 tempTextBox.setWidth("4cm","4cm");
842 tempTextBox.label.setTitle("The name of the observer who was observing when the fault occured.");
843 InputFieldWidgets.put("OBSERVER",tempTextBox);
844
845 ModifyFaultTable.setWidget(10,2,tempTextBox);
846
847 // The System Field
848
849 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
850
851 tempListBox.label.setText(internationalizationConstants.system());
852 tempListBox.setWidth("4cm","4cm");
853 tempListBox.listBox.setVisibleItemCount(1);
854
855 InputFieldWidgets.put("SYSTEM",tempListBox);
856 ModifyFaultTable.setWidget(9,0,tempListBox);
857
858 fillListBoxWithSystems(tempListBox.listBox,internationalizationConstants.locale());
859
860 // The Status
861
862 tempListBox = new LabelListBox(LabelListBox.HORIZONTAL_ALIGNMENT);
863
864 tempListBox.label.setText(internationalizationConstants.status());
865 tempListBox.setWidth("4cm","4cm");
866 tempListBox.listBox.setVisibleItemCount(1);
867
868 InputFieldWidgets.put("STATUS",tempListBox);
869 ModifyFaultTable.setWidget(10,1,tempListBox);
870
871 fillListBoxWithStates(tempListBox.listBox,internationalizationConstants.locale());
872
873 // The date that the fault occurred
874
875 tempTextBox = new LabelTextBox(LabelTextBox.HORIZONTAL);
876
877 tempTextBox.label.setText(internationalizationConstants.dateOccured());
878 tempTextBox.label.setTitle("The date that the fault occured (DD-MMM-YYYY)");
879 tempTextBox.setWidth("4cm","4cm");
880 InputFieldWidgets.put("DATEOCCURED",tempTextBox);
881
882 ModifyFaultTable.setWidget(9,2,tempTextBox);
883
884 // Now put a button which will allow the user to enter the modifications of the fault
885
886 ModifyFaultTable.setHTML(11,0,"<hr>");
887 formatter.setColSpan(11,0,3);
888
889 // Create the buttons which will allow the user to submit the change, reset the form and cancel the form.
890
891 SubmitFaultModificationsButton = new Button(internationalizationConstants.updateFault(),this);
892 ResetFaultModificationsButton = new Button(internationalizationConstants.resetForm(),this);
893 CancelFormButton = new Button(internationalizationConstants.cancelUpdateFault(),this);
894
895 ModifyFaultTable.setWidget(12,0,SubmitFaultModificationsButton);
896 ModifyFaultTable.setWidget(12,1,ResetFaultModificationsButton);
897
898 ModifyFaultTable.setWidget(12,2,CancelFormButton);
899
900 ModifyFaultTable.setHTML(13,0,"<hr>");
901 formatter.setColSpan(13,0,3);
902
903 // Now we need to make a tab panel at the foot of the form
904 // from which the user can create comments, solutions and work
905 // arounds.
906
907 FaultAdditionPanel.add(FaultCommentPanel,internationalizationConstants.comment());
908 FaultAdditionPanel.add(FaultSolutionPanel,internationalizationConstants.solution());
909 FaultAdditionPanel.add(FaultWorkAroundPanel,internationalizationConstants.workAround());
910
911 // Now add the fault addition panel to the main fault
912 // modification form
913
914 ModifyFaultTable.setWidget(14,0,FaultAdditionPanel);
915 FaultAdditionPanel.setWidth("100%");
916 FaultAdditionPanel.selectTab(1);
917 formatter.setColSpan(14,0,3);
918
919 // We have now completed one of the subtasks which is
920 // associated with editing the form
921
922 noOfSubTasksCompleted++;
923
924 // Now wait until the fault data has been retrieved from the
925 // servlet using a deferred command. This is basically a
926 // mechanism for syncronisation when a command is built into
927 // subtasks and we need to syncronise when all of the subtasks
928 // are completed. The javascript GWT engine will call this
929 // class intermittingly until all of the subtasks have been
930 // completed or it times out an complains to the user to that
931 // effect.
932
933 DeferredCommand.addCommand(new IncrementalCommand() {
934
935 public boolean execute() {
936
937 // If the information relating to the fault has
938 // arrived then display it now otherwise we wait
939 // for the next time that we are called and try
940 // again
941
942 final int NOOFSUBTASKSINVOLVEDINCREATINGFAULTUPDATE = 2;
943
944 if (noOfSubTasksCompleted == NOOFSUBTASKSINVOLVEDINCREATINGFAULTUPDATE) {
945
946 busyIndicator.showBusy(false);
947
948 resetFormToDefaultValues();
949
950 // false indicates that we are not waiting for
951 // anything more to be done
952
953 return false;
954 }
955
956 // We are still waiting for things to be completed.
957
958 return true;
959 }
960 });
961 }
962
963 /**
964 * This method will be used to remove the current update tab and
965 * return the user to the quick view panel if there is not another
966 * fault open for edit
967 */
968
969 private void removeUpdateTab() {
970
971 FaultContainerPanel.remove(this);
972
973 // Now if there is another tab in the update tab panel we
974 // should select that, otherwise we should select a different
975 // tab in the main tab
976
977 if (FaultContainerPanel.getTabBar().getTabCount() != 0) {
978 FaultContainerPanel.selectTab(0);
979 }
980
981 // Now select the quick view panel
982
983 MainTabPanel.selectTab(1);
984 }
985
986 /**
987 * Return the fault number which is associated with this panel to
988 * the caller
989 */
990
991 public int getFaultNumber () {
992 return FaultNumber;
993 }
994
995 /**
996 * The obligation of the fault update listener interface which is
997 * called when one of the components in this interface updates a
998 * fault. We need to know if the user updates the fault from this
999 * interface in any way as the if a solution/workaround/comment is
1000 * added to the fault in the database, the lastModified field will
1001 * be updated and so when we get around to saving the details of
1002 * the fault, the database will complain the fault is out of date.
1003 * <P>
1004 * @param faultNumber This is the fault which has been updated
1005 */
1006
1007 public void faultUpdatedEvent (final int faultNumber) {
1008
1009 // Get the details of the updated last modified time for this
1010 // fault from the database.
1011
1012 svc.getFaultDetails (new Integer(faultNumber), internationalizationConstants.locale(),new AsyncCallback() {
1013
1014 public void onSuccess (final Object result) {
1015
1016 final Fault fault = (Fault)result;
1017
1018 FaultBeingEdited.lastModified = fault.lastModified;
1019 }
1020
1021 public void onFailure (Throwable ex)
1022 {
1023 MessageBox.alert(internationalizationConstants.information(),ex.getMessage());
1024 }
1025 });
1026 }
1027 }
1028
1029
1030