001 /** =====================================================================
002 *
003 * File Name : $Id: NewFaultForm.java,v 1.17 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 6 Jun 2007 C.Bevil First Release
023 *
024 * Commissioning Notes
025 * -------------------
026 *
027 * None
028 *
029 * =====================================================================
030 *
031 * @Version : $Id: NewFaultForm.java,v 1.17 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/NewFaultForm.java,v 1.17 2008/01/15 11:08:15 cb Exp $
036 *
037 * Log : $Log: NewFaultForm.java,v $
038 * Log : Revision 1.17 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.16 2008/01/14 16:59:45 cb
043 * Log : Modified so that the text field will resize when the main window is
044 * Log : resized.
045 * Log :
046 * Log : Revision 1.15 2007/12/14 08:27:37 cb
047 * Log : Fixed a subtle timing issue associated with DR 17940
048 * Log :
049 * Log : "When multiple faults are submitted with the new fault DB a minor error
050 * Log : occurs when trying to submit additional faults. When the user clicks
051 * Log : `create fault` having proviously submitted a fault the fault
052 * Log : submission page does not load properly. None of the boxes / pull down
053 * Log : menus (with the exception of time occurred, date occurred, time lost
054 * Log : and observer) are displayed. Clicking the reset form button clears the
055 * Log : problem.
056 * Log :
057 * Log : I`m currently running internet explorer 7 on a windows XP laptop."
058 * Log :
059 * Log : Revision 1.14 2007/10/22 11:39:44 cb
060 * Log : Changed some of the dimensions of some of the widgets to try and line
061 * Log : them up
062 * Log :
063 * Log : Revision 1.13 2007/10/19 13:41:09 cb
064 * Log : Converted to use the gwtext widgets for the dialogs which are quite nice
065 * Log :
066 * Log : Revision 1.12 2007/10/18 08:43:50 cb
067 * Log : Support for decommissioned instruments has been added to the system
068 * Log :
069 * Log : Revision 1.11 2007/10/08 09:32:50 cb
070 * Log : Modified to allow and review the user to change the faults which he is
071 * Log : subscribed to.
072 * Log :
073 * Log : Revision 1.10 2007/09/26 08:39:51 cb
074 * Log : Now double warning when the reset button is pressed
075 * Log :
076 * Log : Revision 1.9 2007/09/03 10:51:09 cb
077 * Log : Modified to check that the user enters something into the description
078 * Log : field
079 * Log :
080 * Log : Revision 1.8 2007/08/23 15:29:17 cb
081 * Log : Display the results of the exception if the fault could not be
082 * Log : created.
083 * Log :
084 * Log : Revision 1.7 2007/08/20 11:52:52 cb
085 * Log : Modified to check to see if the date which is entered is in the
086 * Log : future.
087 * Log :
088 * Log : Revision 1.6 2007/08/14 14:32:25 cb
089 * Log : Sorted out the reset of the form so that it asks for
090 * Log : confirmation. Selects the quick view tab once the user has entered a
091 * Log : fault.
092 * Log :
093 * Log : Revision 1.5 2007/08/13 09:47:48 cb
094 * Log : Reset the form correctly as we were not resetting the names of the
095 * Log : people when the reset form button was being pressed.
096 * Log :
097 * Log : Revision 1.4 2007/08/01 13:00:05 cb
098 * Log : First prototype after import
099 * Log :
100 * Log : Revision 1.3 2007/07/13 10:54:05 cb
101 * Log : Complete interface prototype
102 * Log :
103 * Log : Revision 1.2 2007/06/06 09:10:07 cb
104 * Log : Before moving the menu and changing the options into buttons
105 * Log :
106 * Log : Revision 1.1.1.1 2007/06/01 08:33:26 cb
107 * Log : Imported using TkCVS
108 * Log :
109 *
110 * =====================================================================*/
111
112 package GWTApplication.client;
113
114 import com.google.gwt.user.client.*;
115 import com.google.gwt.user.client.rpc.*;
116 import com.google.gwt.user.client.ui.*;
117 import com.google.gwt.user.client.ui.FlexTable.*;
118 import java.util.*;
119
120 import com.gwtext.client.core.EventObject;
121 import com.gwtext.client.util.Format;
122 import com.gwtext.client.widgets.MessageBox;
123 import com.gwtext.client.widgets.MessageBoxConfig;
124
125 // Import the rich text widget
126
127 import com.jpavel.gwt.wysiwyg.client.*;
128
129 /**
130 * This class represents a form into which the user can enter the
131 * details of a new fault which may subsequently be entered into the
132 * system. This class makes extensive use of the google web
133 * toolkit.
134 * @author Craige Bevil
135 * @version $Id: NewFaultForm.java,v 1.17 2008/01/15 11:08:15 cb Exp $
136 */
137
138 class NewFaultForm extends FaultDBForm implements ClickListener, WindowResizeListener {
139
140 /**
141 * This is the main tab panel
142 */
143
144 TabPanel mainTabPanel;
145
146 /**
147 * Button which is used for submitting the fault for insertion
148 */
149
150 Button SubmitButton;
151
152 /**
153 * Button which will be used to reset the form to the default
154 * values
155 */
156
157 Button ResetButton;
158
159 /**
160 * This is a checkbox which the user will be use to indicate
161 * whether or not he wants to be informed when there are
162 * modifications to the fault in any way
163 */
164
165 private final CheckBox InterestedInFaultUpdatesCheckbox = new CheckBox();
166
167 /**
168 * This field will be used to hold the title of the new fault
169 */
170
171 private final TextBox Title = new TextBox();
172
173 /**
174 * This field will be used to hold a free format text description
175 * of the fault
176 */
177
178 private final Editor FaultDescription = new Editor();
179
180 /**
181 * This widget will be used to hold the time That the fault
182 * occurred
183 */
184
185 private final TextBox TimeOccurred = new TextBox();
186
187 /**
188 * This widget will be used to hold the date that the fault
189 * occured.
190 */
191
192 private final TextBox DateOccurred = new TextBox();
193
194 /**
195 * This widget will be used to hold the amount of time which was
196 * lost as a result of this fault
197 */
198
199 private final TextBox TimeLost = new TextBox();
200
201 /**
202 * This widget will be used to hold the name of the observer who
203 * was using the system when the fault occurred.
204 */
205
206 private final TextBox Observer = new TextBox();
207
208 /**
209 * This widget will be used to hold the level of the severity of
210 * the fault
211 */
212 private final ListBox Severity = new ListBox();
213
214 /**
215 * This widget will be used to hold the name of the instrument
216 * which is associated with the fault
217 */
218
219 private final ListBox Instrument = new ListBox();
220
221 /**
222 * This widget will be used to hold the name of the site
223 * associated with the fault
224 */
225
226 private final ListBox Site = new ListBox();
227
228 /**
229 * This widget will be used to hold the name of the system which
230 * is associated with the fault
231 */
232
233 private final ListBox System = new ListBox();
234
235 /**
236 * This widget will be used to hold the name of the originator of
237 * the fault.
238 */
239
240 private final ListBox Originator = new ListBox();
241
242 /**
243 * This widget will be used to hold the name of the telescope
244 * operator who was on duty when the fault occurred.
245 */
246
247 private final ListBox TelescopeOperator = new ListBox();
248
249 /**
250 * This widget will be used to hold the name of the duty
251 * technician who was on duty when the fault occurred
252 */
253
254 private final ListBox DutyEngineer = new ListBox();
255
256 /**
257 * This widget will be usedto enter the name of the support
258 * astronomer
259 */
260
261 private final ListBox SupportAstronomer = new ListBox();
262
263 /**
264 * This is called when the user presses one of the buttons at the
265 * foot for the screen
266 * @param sender The widget which caused the event
267 */
268
269 public void onClick (final Widget sender) {
270
271 if (sender.equals(SubmitButton)) {
272
273 // Verify the contents of the form to ensure that the user
274 // has filled in all of the fields which he was expected
275 // to fill in.
276 //
277
278 try {
279 verifyText(internationalizationConstants.description(), NOLENGTHCHECK, FaultDescription.getHTML());
280 } catch (FieldInvalidException e) {
281 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.descriptionFieldNotCompleted());
282 return;
283 }
284
285 if (Title.getText().length() == 0) {
286 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.titleFieldNotCompleted());
287 return;
288 }
289
290 // Check the time occured field to ensure that it is not
291 // empty.
292
293 if (!verifyTimeFormat(TimeOccurred.getText())) {
294 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.timeFieldNotCompletedCorrectly(internationalizationConstants.timeOccured()));
295 return;
296 }
297
298 // Check the date occured field to ensure that it is not
299 // empty.
300
301 if (!verifyDateFormat(DateOccurred.getText())) {
302 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.dateFieldNotCompletedCorrectly(internationalizationConstants.dateOccured()));
303 return;
304 }
305
306 // Check that the date that the user specified for the
307 // time that the fault occured is not in the future.
308
309 if (!verifyDateNotInFuture(DateOccurred.getText())) {
310 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.dateInTheFuture(internationalizationConstants.dateOccured()));
311 return;
312 }
313
314 // Check the time lost field to make sure that the user has completed it correctly
315
316 if (!verifyTimeFormat(TimeLost.getText())) {
317 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.timeFieldNotCompletedCorrectly(internationalizationConstants.timeLost()));
318 return;
319 }
320
321 // Now we need to send the user entered data down to the
322 // fault database servlet in order to put the fault into
323 // the database
324
325 final Fault newFaultDetails = new Fault();
326
327 newFaultDetails.description = FaultDescription.getHTML();
328 newFaultDetails.title = Title.getText();
329 newFaultDetails.timeOccured = TimeOccurred.getText();
330 newFaultDetails.dateOccured = DateOccurred.getText();
331 newFaultDetails.timeLost = TimeLost.getText();
332 newFaultDetails.telescopeOperatorEmail = TelescopeOperator.getValue(TelescopeOperator.getSelectedIndex());
333 newFaultDetails.site = Site.getValue(Site.getSelectedIndex());
334 newFaultDetails.observer = Observer.getText();
335 newFaultDetails.instrument = Instrument.getValue(Instrument.getSelectedIndex());
336 newFaultDetails.dutyTechnicianEmail = DutyEngineer.getValue(DutyEngineer.getSelectedIndex());
337 newFaultDetails.supportAstronomerEmail = SupportAstronomer.getValue(SupportAstronomer.getSelectedIndex());
338 newFaultDetails.enteredByEmail = Originator.getValue(Originator.getSelectedIndex());
339 newFaultDetails.severity = Severity.getValue(Severity.getSelectedIndex());
340 newFaultDetails.instrument = Instrument.getValue(Instrument.getSelectedIndex());
341 newFaultDetails.userWantsEmailUpdates = InterestedInFaultUpdatesCheckbox.isChecked();
342 newFaultDetails.system = System.getValue(System.getSelectedIndex());
343
344 // Now we need to send the data across to the servlet
345 // which will be responsible for storing the data in the
346 // database
347
348 svc.createFault (newFaultDetails,new AsyncCallback() {
349
350 /**
351 * On success we clear the form and inform the user of
352 * the number of the defect which was assigned
353 */
354
355 public void onSuccess (final Object result) {
356
357 final Integer faultReport = (Integer)result;
358
359 // Reset the form back to the default values
360
361 resetForm(true);
362
363 // Now select the quick view tab. Depending on
364 // whether the user is logged on as an ING
365 // user or a casual user, the quick view panel
366 // is either on panel 0 or 1
367
368 if (UserAuthentication.hasPriviledgeLevel(FaultDatabaseConstants.INGUSERPRIVILEDGE)) {
369 mainTabPanel.selectTab(1);
370 } else {
371 mainTabPanel.selectTab(0);
372 }
373
374 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.reportFaultCreated(faultReport.intValue()));
375 }
376
377 public void onFailure (Throwable ex)
378 {
379 // If we were unable to create the fault then
380 // report the error that came back from the
381 // servlet
382
383 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToCreateNewFault() + " : " + ex.getMessage());
384 }
385 });
386
387 } else if (sender.equals(ResetButton)) {
388
389 // Make sure that this is what the user wants to do
390
391 MessageBox.confirm(internationalizationConstants.confirm(),internationalizationConstants.areYouSureYouWantToResetTheForm(),new MessageBox.ConfirmCallback() {
392
393 public void execute(String btnID) {
394
395 if ("yes".equals(btnID)) {
396 resetForm(true);
397 }
398 }
399 });
400 }
401 }
402
403 /**
404 * This method will be used to reset the form to it's initial
405 * values.
406 * @param resetWithoutWarning True if we are to ignore the fact
407 * that there are changes which may not have been saved in the form
408 */
409
410 void resetForm (final boolean resetWithoutWarning) {
411
412 // If we have been requested to reset the form without warning
413 // then do so now.
414
415 if (!resetWithoutWarning) {
416
417 boolean changesDetected = false;
418
419 // Check to make to see if there are any changes in the
420 // form which will be lost if we reset the form
421
422 String descriptionText = FaultDescription.getHTML();
423
424 descriptionText = descriptionText.replaceAll("<.*?>","");
425
426 if (descriptionText.length() > 0 || Title.getText().length() > 0) {
427 changesDetected = true;
428 }
429
430 // Check to see if the user has changed the amount of time lost
431
432 if (!TimeLost.getText().equalsIgnoreCase("00:00")) {
433 changesDetected = true;
434 }
435
436 // If there are changes detected then ask the user if he
437 // does not mind losing them
438
439 if (changesDetected) {
440
441 if (!Window.confirm(internationalizationConstants.getUnsavedChangesConfirmation())) {
442 return;
443 }
444 }
445 }
446
447 // Ensure that the tick box which is associated with the fault
448 // updates is not checked.
449
450 InterestedInFaultUpdatesCheckbox.setChecked(false);
451
452 // Reset the amount of time which has been lost
453
454 TimeLost.setText("00:00");
455
456 // Get the current date and drop it into the field which holds
457 // the date.
458
459 DateOccurred.setText(getCurrentDate());
460
461 // Now set the instrument to None
462
463 if (!setSelectedItemInListbox(Instrument,"None")) {
464 MessageBox.alert(internationalizationConstants.information(),"Unable to set instrument field to none");
465 }
466
467 // Set the system field to unknown
468
469 if (!setSelectedItemInListbox(System,"Unknown")) {
470 MessageBox.alert(internationalizationConstants.information(),"Unable to set system field to unknown");
471 }
472
473 // Set the site field to WHT
474
475 if (!setSelectedItemInListbox(Site,"WHT")) {
476 MessageBox.alert(internationalizationConstants.information(),"Unable to set site field to unknown");
477 }
478
479 // Now set the time occurred field to the current time
480
481 TimeOccurred.setText(getCurrentTime());
482
483 FaultDescription.setHTML("");
484 Title.setText("");
485
486 // Now we need to reset the names of the people in the various
487 // lists back to the default values.
488
489 setSelectedItemInListbox(Originator,UserAuthentication.UserEmailAddress);
490 setSelectedItemInListbox(DutyEngineer,UserAuthentication.UserEmailAddress);
491 setSelectedItemInListbox(TelescopeOperator,UserAuthentication.UserEmailAddress);
492 setSelectedItemInListbox(SupportAstronomer,UserAuthentication.UserEmailAddress);
493 }
494
495 /**
496 * This is used to create the form which will be used to enter the
497 * details of a new fault.
498 * @param MainTabPanel This is the parent tab panel into which we
499 * will build the new fault form.
500 * @param svc This is a object which can be used to access the
501 * servlet
502 * @param UserAuthentication The user credentials which were used
503 * when the user logged on.
504 */
505
506 NewFaultForm (final TabPanel MainTabPanel,final FaultServiceAsync svc, final AuthenticationDetails UserAuthentication) {
507
508 HorizontalPanel mainPanel;
509
510 final FlexTable MainTable = new FlexTable();
511 final FlexCellFormatter CellFormatter = MainTable.getFlexCellFormatter();
512
513 this.svc = svc;
514 this.UserAuthentication = UserAuthentication;
515
516 mainPanel = new HorizontalPanel();
517
518 MainTable.setWidth("98%");
519
520 // The title of the fault
521
522 Label tempLabel;
523
524 tempLabel = new Label(internationalizationConstants.title());
525 MainTable.setWidget(1,0,tempLabel);
526
527 Title.setMaxLength(100);
528 Title.setWidth("99%");
529 Title.setStyleName("gwt-Label");
530
531 MainTable.setWidget(2,0,Title);
532 CellFormatter.setColSpan(2,0,4);
533
534 // This is the field into which the user will enter the
535 // details of a fault
536
537 FaultDescription.setHeight(Math.max(Window.getClientHeight()-360, 300) + "px");
538
539 FaultDescription.setWidth("99%");
540 MainTable.setWidget(3,0,FaultDescription);
541 CellFormatter.setColSpan(3,0,4);
542
543 // Time Occurred Field
544
545 tempLabel = new Label(internationalizationConstants.timeOccured());
546 MainTable.setWidget(5,0,tempLabel);
547
548 TimeOccurred.setMaxLength(5);
549 TimeOccurred.setStyleName("gwt-Label");
550 TimeOccurred.setWidth("98%");
551 MainTable.setWidget(5,1,TimeOccurred);
552
553 // Date Occurred Field
554
555 tempLabel = new Label(internationalizationConstants.dateOccured());
556 MainTable.setWidget(5,2,tempLabel);
557
558 DateOccurred.setMaxLength(11);
559 DateOccurred.setStyleName("gwt-Label");
560 DateOccurred.setWidth("98%");
561 MainTable.setWidget(5,3,DateOccurred);
562
563 // Time Lost Field
564
565 tempLabel = new Label(internationalizationConstants.timeLost());
566 MainTable.setWidget(6,0,tempLabel);
567
568 TimeLost.setMaxLength(5);
569 TimeLost.setStyleName("gwt-Label");
570 TimeLost.setWidth("98%");
571 MainTable.setWidget(6,1,TimeLost);
572
573 // Observer Field
574
575 tempLabel = new Label(internationalizationConstants.observer());
576 MainTable.setWidget(6,2,tempLabel);
577
578 Observer.setMaxLength(20);
579 Observer.setStyleName("gwt-Label");
580 Observer.setWidth("98%");
581 MainTable.setWidget(6,3,Observer);
582
583 // Severity
584
585 tempLabel = new Label(internationalizationConstants.severity());
586 MainTable.setWidget(7,0,tempLabel);
587
588 Severity.setWidth("98%");
589 Severity.setStyleName("gwt-Label");
590 MainTable.setWidget(7,1,Severity);
591
592 fillListBoxWithSeverity(Severity,internationalizationConstants.locale());
593
594 // Instrument
595
596 tempLabel = new Label(internationalizationConstants.instrument());
597 MainTable.setWidget(7,2,tempLabel);
598
599 Instrument.setStyleName("gwt-Label");
600 Instrument.setWidth("98%");
601 MainTable.setWidget(7,3,Instrument);
602
603 fillListBoxWithCurrentInstruments(Instrument,internationalizationConstants.locale());
604
605 // Site
606
607 tempLabel = new Label(internationalizationConstants.site());
608 MainTable.setWidget(8,0,tempLabel);
609
610 Site.setWidth("98%");
611 Site.setStyleName("gwt-Label");
612 MainTable.setWidget(8,1,Site);
613
614 fillListBoxWithSites(Site,internationalizationConstants.locale());
615
616 // System
617
618 tempLabel = new Label(internationalizationConstants.system());
619 MainTable.setWidget(8,2,tempLabel);
620
621 System.setStyleName("gwt-Label");
622 System.setWidth("98%");
623 MainTable.setWidget(8,3,System);
624
625 fillListBoxWithSystems(System,internationalizationConstants.locale());
626
627 // Telescope Operator
628
629 tempLabel = new Label(internationalizationConstants.telescopeOperator());
630 MainTable.setWidget(9,0,tempLabel);
631
632 TelescopeOperator.setWidth("98%");
633 TelescopeOperator.setStyleName("gwt-Label");
634 MainTable.setWidget(9,1,TelescopeOperator);
635
636 // Now get the list of the telescope operators from the
637 // database and enter them into the drop down menu which will
638 // be used to select the telescope operator.
639
640 fillListBoxWithTelescopeOperators(TelescopeOperator,UserAuthentication.UserEmailAddress,false);
641
642 // Duty Engineer
643
644 tempLabel = new Label(internationalizationConstants.dutyTechnician());
645 MainTable.setWidget(9,2,tempLabel);
646
647 DutyEngineer.setStyleName("gwt-Label");
648 DutyEngineer.setWidth("98%");
649 MainTable.setWidget(9,3,DutyEngineer);
650
651 fillListBoxWithDutyTechnicians(DutyEngineer,UserAuthentication.UserEmailAddress,false);
652
653 // Support Astronomer
654
655 tempLabel = new Label(internationalizationConstants.supportAstronomer());
656 MainTable.setWidget(10,0,tempLabel);
657
658 SupportAstronomer.setWidth("98%");
659 SupportAstronomer.setStyleName("gwt-Label");
660 MainTable.setWidget(10,1,SupportAstronomer);
661
662 fillListBoxWithSupportAstronomers(SupportAstronomer,UserAuthentication.UserEmailAddress,false);
663
664 // Entered by field
665
666 tempLabel = new Label(internationalizationConstants.enteredBy());
667 MainTable.setWidget(10,2,tempLabel);
668
669 Originator.setStyleName("gwt-Label");
670 Originator.setWidth("98%");
671 MainTable.setWidget(10,3,Originator);
672
673 fillListBoxWithStaffMembers(Originator,UserAuthentication.UserEmailAddress,false);
674
675 // If the user only has default access then do not give him
676 // the option of registering for email updates.
677
678 if (UserAuthentication.hasPriviledgeLevel(FaultDatabaseConstants.INGUSERPRIVILEDGE)) {
679
680 // Now the check box which will beused to indicate whether the
681 // person which entered the fault wants to be informed when
682 // the fault is updated in anyway
683
684 tempLabel = new Label(internationalizationConstants.sendEmailFeedback());
685 MainTable.setWidget(11,0,tempLabel);
686
687 InterestedInFaultUpdatesCheckbox.setStyleName("gwt-Label");
688 InterestedInFaultUpdatesCheckbox.setWidth("98%");
689
690 MainTable.setWidget(11,1,InterestedInFaultUpdatesCheckbox);
691 }
692
693 // Now we need to add the submit and reset form buttons to the
694 // button of the interface
695
696 SubmitButton = new Button(internationalizationConstants.submitFault(),this);
697 ResetButton = new Button(internationalizationConstants.resetForm(),this);
698
699 // Add the buttons to the button of the interface
700
701 MainTable.setWidget(12,0,SubmitButton);
702 MainTable.setWidget(12,1,ResetButton);
703
704 // Now reset the fields in the form to their default values.
705
706 resetForm(true);
707
708 // Now add the main panel to the tab
709
710 mainPanel.add(MainTable);
711
712 MainTabPanel.add(mainPanel,internationalizationConstants.createFault());
713
714 // Remember the main tab panel
715
716 this.mainTabPanel = MainTabPanel;
717
718 Window.addWindowResizeListener(this);
719
720 }
721
722 /**
723 * Called when the main window is resized and we resize the size
724 * of the text field so that it takes advantage of the size of the
725 * screen.
726 */
727
728 public void onWindowResized (int width, int height) {
729 FaultDescription.setHeight(Math.max(height-360, 300) + "px");
730 }
731 }
732
733