001 /** ===================================================================== 002 * 003 * File Name : $Id: ManageSystem.java,v 1.7 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 Jan 15 2008 C.Bevil First Release 023 * 024 * Commissioning Notes 025 * ------------------- 026 * 027 * None 028 * 029 * ===================================================================== 030 * 031 * @Version : $Id: ManageSystem.java,v 1.7 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/ManageSystem.java,v 1.7 2008/01/15 11:08:15 cb Exp $ 036 * 037 * Log : $Log: ManageSystem.java,v $ 038 * Log : Revision 1.7 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.6 2007/12/12 15:26:13 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/10/02 12:14:48 cb 047 * Log : Corrected a label for the reset password field 048 * Log : 049 * Log : Revision 1.4 2007/08/17 14:26:42 cb 050 * Log : Updated for lastest prototype incorporating a lot of Nikos comments 051 * Log : 052 * Log : Revision 1.3 2007/08/01 13:00:05 cb 053 * Log : First prototype after import 054 * Log : 055 * Log : Revision 1.2 2007/07/13 10:54:05 cb 056 * Log : Complete interface prototype 057 * Log : 058 * Log : Revision 1.1.1.1 2007/06/01 08:33:26 cb 059 * Log : Imported using TkCVS 060 * Log : 061 * 062 * =====================================================================*/ 063 064 package GWTApplication.client; 065 066 import com.google.gwt.user.client.*; 067 import com.google.gwt.user.client.rpc.*; 068 import com.google.gwt.user.client.ui.*; 069 import com.google.gwt.user.client.ui.FlexTable.*; 070 071 import com.gwtext.client.core.EventObject; 072 import com.gwtext.client.util.Format; 073 import com.gwtext.client.widgets.MessageBox; 074 import com.gwtext.client.widgets.MessageBoxConfig; 075 076 import java.util.*; 077 078 /** 079 * This class will be used to add to a tab panel, a form which may be 080 * used by a privileged use it to administer the fault management 081 * system. It will allow the user to Update for example the list of 082 * uses of the system, reset passwords and add new components into the 083 * list which represents data within the systems. 084 * <P> 085 * The user in order to perform this role, must authenticate himself 086 * against the system before any changes that he makes will be 087 * accepted by the system. 088 *<P> 089 * @author Craige Bevil 090 * @version $Id: ManageSystem.java,v 1.7 2008/01/15 11:08:15 cb Exp $ 091 */ 092 093 class ManageSystem extends FaultDBForm implements ClickListener { 094 095 /** 096 * This will be used for collating together all of the information 097 * associated with an input field in the form 098 */ 099 100 class InterfaceInputField { 101 102 /** 103 * This is the label which will be attached to the input field 104 */ 105 106 public String InputFieldLabel; 107 108 /** 109 * This is the label which which will be attached to in the 110 * input acknowledge button 111 */ 112 113 public String AcknowledgementWidgetLabel; 114 115 /** 116 * This is the input widget 117 */ 118 119 public Widget InputWidget; 120 121 /** 122 * This is the button which will be used to acknowledge that 123 * the user input is now complete 124 */ 125 126 public Button ButtonAcknowledgementWidget; 127 128 InterfaceInputField (String InputFieldLabel, 129 String AcknowledgementWidgetLabel, 130 Widget InputWidget, 131 Button ButtonAcknowledgementWidget) { 132 133 this.InputFieldLabel = InputFieldLabel; 134 this.AcknowledgementWidgetLabel = AcknowledgementWidgetLabel; 135 this.InputWidget = InputWidget; 136 this.ButtonAcknowledgementWidget = ButtonAcknowledgementWidget; 137 } 138 } 139 140 final static int INSTRUMENTIDX = 0; 141 final static int TELESCOPEOPERATORIDX = 1; 142 final static int DUTYTECHNICIANIDX = 2; 143 final static int SUPPORTASTRONOMERIDX = 3; 144 final static int SYSTEMIDX = 4; 145 146 final InterfaceInputField[] InterfaceInputFields = new InterfaceInputField [] { 147 new InterfaceInputField(internationalizationConstants.newLabel() + " " + internationalizationConstants.instrument(),"+",null,null), 148 new InterfaceInputField(internationalizationConstants.newLabel() + " " + internationalizationConstants.telescopeOperator(), "+",null,null), 149 new InterfaceInputField(internationalizationConstants.newLabel() + " " + internationalizationConstants.dutyTechnician(),"+",null,null), 150 new InterfaceInputField(internationalizationConstants.newLabel() + " " + internationalizationConstants.supportAstronomer(),"+",null,null), 151 new InterfaceInputField(internationalizationConstants.newLabel() + " " + internationalizationConstants.system(), "+",null,null) 152 }; 153 154 /** 155 * This is the button which is to be used for resetting the password of a user 156 */ 157 158 private Button ResetPasswordButton; 159 160 /** 161 * This is the field into which the user will enter the details of 162 * the new password for a user 163 */ 164 165 final private PasswordTextBox PasswordField; 166 167 /** 168 * This is the field into which the user will use to confirm the password 169 */ 170 171 final private PasswordTextBox PasswordConfirmField; 172 173 /** 174 * This is the list of users from which the user can select the 175 * name of the person who he wants to change the password for. 176 */ 177 178 final private ListBox UserToChangePwdList; 179 180 181 /** 182 * This is the button which will be pressed to generate a new user 183 */ 184 185 private Button CreateNewUserButton; 186 187 /** 188 * This is the text box which the user will use to enter the name 189 * of the new user to the system 190 */ 191 192 final private TextBox NameOfNewUser = new TextBox(); 193 194 /** 195 * This is the text box which the user will use to enter the surname 196 * of the new user to the system 197 */ 198 199 final private TextBox SurnameOfNewUser = new TextBox(); 200 201 /** 202 * This is the text box which the user will use to enter the email 203 * address of the new user to the system 204 */ 205 206 private TextBox MailAddressOfNewUser = new TextBox(); 207 208 /** 209 * This is the main panel into which we pack up all of the Widgets 210 * which comprise this form. 211 */ 212 213 final private HorizontalPanel mainPanel; 214 215 /** 216 * This is used to create the panel which will be used by the 217 * manager of the system to manage the data 218 */ 219 220 ManageSystem (final TabPanel MainTabPanel,final FaultServiceAsync svc,final AuthenticationDetails UserAuthentication) { 221 222 this.svc = svc; 223 this.UserAuthentication = UserAuthentication; 224 225 mainPanel = new HorizontalPanel(); 226 227 final FlexTable table = new FlexTable(); 228 final FlexCellFormatter formatter = (FlexCellFormatter)table.getCellFormatter(); 229 230 table.setWidth("98%"); 231 232 Label tempLabel; 233 234 tempLabel = new Label(internationalizationConstants.createNewOptions()); 235 table.setWidget(0,0,tempLabel); 236 tempLabel.setStyleName("modifyFaultTitleLabel"); 237 238 formatter.setStyleName(0,0,"manageSystemTableBackground"); 239 formatter.setColSpan(0,0,3); 240 241 tempLabel.setWidth("98%"); 242 243 // Now add the labels and the buttons to the form. Note that 244 // we index the InterfaceInputFields variable here so be careful 245 // with the indexing 246 247 for (int i = 0; i <= SYSTEMIDX; i++) { 248 249 Label j; 250 251 j = new Label(InterfaceInputFields[i].InputFieldLabel); 252 j.setStyleName("gwt-Label"); 253 254 table.setWidget(i+1,0,j); 255 256 // Now create a button which will be used to perform the action 257 258 InterfaceInputFields[i].ButtonAcknowledgementWidget = new Button(InterfaceInputFields[i].AcknowledgementWidgetLabel,this); 259 InterfaceInputFields[i].ButtonAcknowledgementWidget.addStyleName("gwt-Label"); 260 261 // Store the button widget so we can work out when the 262 // user clicks on the button which button he actually 263 // pressed. 264 265 table.setWidget(i+1,2,InterfaceInputFields[i].ButtonAcknowledgementWidget); 266 } 267 268 // Now allow the user to enter the details of a new instrument 269 270 final TextBox newInstrument = new TextBox(); 271 272 newInstrument.setMaxLength(20); 273 newInstrument.setWidth("98%"); 274 InterfaceInputFields[INSTRUMENTIDX].InputWidget = newInstrument; 275 276 table.setWidget(1,1,newInstrument); 277 278 // Field which allows the user to create a new TO 279 280 final ListBox newTO = new ListBox(); 281 newTO.setVisibleItemCount(1); 282 newTO.setName("NewTO"); 283 newTO.setMultipleSelect(false); 284 newTO.setWidth("98%"); 285 table.setWidget(2,1,newTO); 286 InterfaceInputFields[TELESCOPEOPERATORIDX].InputWidget = newTO; 287 setupDropDownList(new Integer(FaultDatabaseConstants.TELESCOPEOPERATOR),newTO); 288 289 // Now create the new duty technician field 290 291 final ListBox newDE = new ListBox(); 292 newDE.setVisibleItemCount(1); 293 newDE.setName("NewDE"); 294 newDE.setMultipleSelect(false); 295 newDE.setWidth("98%"); 296 table.setWidget(3,1,newDE); 297 InterfaceInputFields[DUTYTECHNICIANIDX].InputWidget = newDE; 298 setupDropDownList(new Integer(FaultDatabaseConstants.DUTYENGINEERS),newDE); 299 300 // Now create the new support astronomer field 301 302 final ListBox newSA = new ListBox(); 303 newSA.setVisibleItemCount(1); 304 newSA.setName("NewDE"); 305 newSA.setMultipleSelect(false); 306 newSA.setWidth("98%"); 307 table.setWidget(4,1,newSA); 308 InterfaceInputFields[SUPPORTASTRONOMERIDX].InputWidget = newSA; 309 setupDropDownList(new Integer (FaultDatabaseConstants.SUPPORTASTRONOMERS),newSA); 310 311 // Now create the new system field 312 313 final TextBox newSystem = new TextBox(); 314 newSystem.setName("NewSystem"); 315 newSystem.setWidth("98%"); 316 newSystem.setMaxLength(20); 317 table.setWidget(5,1,newSystem); 318 InterfaceInputFields[SYSTEMIDX].InputWidget = newSystem; 319 320 // Create a label which shows that the user can create a new 321 // user for the system 322 323 tempLabel = new Label(internationalizationConstants.createNewUser()); 324 tempLabel.setWidth("98%"); 325 tempLabel.setStyleName("modifyFaultTitleLabel"); 326 327 table.setWidget(7,0,tempLabel); 328 formatter.setStyleName(7,0,"manageSystemTableBackground"); 329 formatter.setColSpan(7,0,3); 330 331 // Now create the field which will allow the user to enter the name of the new user 332 333 tempLabel = new Label(internationalizationConstants.name()); 334 tempLabel.setStyleName("gwt-Label"); 335 tempLabel.setWidth("98%"); 336 table.setWidget(8,0,tempLabel); 337 338 NameOfNewUser.setMaxLength(30); 339 NameOfNewUser.setWidth("4cm"); 340 table.setWidget(8,1,NameOfNewUser); 341 342 // Now create the field which will allow the user to enter the surname of the new user 343 344 tempLabel = new Label(internationalizationConstants.surname()); 345 tempLabel.setStyleName("gwt-Label"); 346 tempLabel.setWidth("98%"); 347 table.setWidget(9,0,tempLabel); 348 349 SurnameOfNewUser.setMaxLength(30); 350 SurnameOfNewUser.setWidth("4cm"); 351 table.setWidget(9,1,SurnameOfNewUser); 352 353 // Now create the field which will allow the user to enter the 354 // email address of the new user 355 356 tempLabel = new Label(internationalizationConstants.emailAddress()); 357 tempLabel.setStyleName("gwt-Label"); 358 tempLabel.setWidth("98%"); 359 table.setWidget(10,0,tempLabel); 360 361 MailAddressOfNewUser.setMaxLength(30); 362 MailAddressOfNewUser.setWidth("4cm"); 363 table.setWidget(10,1,MailAddressOfNewUser); 364 365 // Now create a button which will create a new user when pressed 366 367 CreateNewUserButton = new Button(internationalizationConstants.createNewUser(),this); 368 369 table.setWidget(10,2,CreateNewUserButton); 370 371 // Now allow the sysadm to reset the password of a user 372 373 // Create a label which shows that the user can create a new 374 375 tempLabel = new Label(internationalizationConstants.resetPassword()); 376 tempLabel.setWidth("98%"); 377 tempLabel.setStyleName("modifyFaultTitleLabel"); 378 379 table.setWidget(11,0,tempLabel); 380 formatter.setStyleName(11,0,"manageSystemTableBackground"); 381 formatter.setColSpan(11,0,3); 382 383 // Now give the user a chance of selecting the name of the 384 // person who needs his password changing 385 386 tempLabel = new Label(internationalizationConstants.name()); 387 tempLabel.setStyleName("gwt-Label"); 388 tempLabel.setWidth("98%"); 389 table.setWidget(12,0,tempLabel); 390 391 UserToChangePwdList = new ListBox(); 392 393 UserToChangePwdList.setVisibleItemCount(1); 394 UserToChangePwdList.setName("ChangeUserPassword"); 395 UserToChangePwdList.setMultipleSelect(false); 396 UserToChangePwdList.setWidth("98%"); 397 table.setWidget(12,1,UserToChangePwdList); 398 fillListBoxWithStaffMembers(UserToChangePwdList,null,false); 399 400 // Now the password and password confirmation field 401 402 tempLabel = new Label(internationalizationConstants.newPassword()); 403 tempLabel.setStyleName("gwt-Label"); 404 tempLabel.setWidth("98%"); 405 table.setWidget(13,0,tempLabel); 406 407 PasswordField = new PasswordTextBox(); 408 PasswordField.setName("ChangeUserPassword"); 409 PasswordField.setWidth("98%"); 410 table.setWidget(13,1,PasswordField); 411 412 // Now the field into which the user will confirm his password 413 414 tempLabel = new Label(internationalizationConstants.confirmPassword()); 415 tempLabel.setStyleName("gwt-Label"); 416 tempLabel.setWidth("98%"); 417 table.setWidget(14,0,tempLabel); 418 419 PasswordConfirmField = new PasswordTextBox(); 420 PasswordConfirmField.setName("ChangeUserPasswordConfirm"); 421 PasswordConfirmField.setWidth("98%"); 422 table.setWidget(14,1,PasswordConfirmField); 423 424 // Now create a button which will reset the password when 425 // pressed 426 427 ResetPasswordButton = new Button(internationalizationConstants.resetPassword(),this); 428 table.setWidget(14,2,ResetPasswordButton); 429 430 // Now add to the main panel 431 432 mainPanel.add(table); 433 434 formatter.setWidth(0,1,"3cm"); 435 436 // Now add the panel to the tab bar 437 438 MainTabPanel.add(mainPanel,internationalizationConstants.manageSystem()); 439 } 440 441 442 /** 443 * Used to fill the drop down menu which contains a list of all of 444 * the people who are not in the group which is specified in the 445 * <b>GroupToExclude</b> parameter 446 * @param listBox This is the list into which we should put the staff members 447 */ 448 449 private void setupDropDownList (final Integer GroupToExclude, final ListBox listBox) { 450 451 svc.getMembersOfStaffNotInGroup (GroupToExclude,new AsyncCallback() { 452 453 /** 454 * On success we enter the details of the telescope 455 * operators into the list which was provided by the 456 * caller 457 */ 458 459 public void onSuccess (final Object result) { 460 461 listBox.clear(); 462 463 final ArrayList temp = (ArrayList)result; 464 465 for (int i=0; i < temp.size(); i++) { 466 467 final Person person = (Person)temp.get(i); 468 469 // Now add the name of the telescope operator 470 // to the list 471 472 listBox.addItem(person.getName() + " " + person.getSurname(),person.getEmailAddress()); 473 } 474 } 475 476 public void onFailure (Throwable ex) { 477 MessageBox.alert(internationalizationConstants.information(),"Unable to get the list of potential " + GroupToExclude + "s"); 478 } 479 }); 480 481 } 482 483 /** 484 * Called when the user presses one of the buttons on the 485 * interface and requests the business associated with that button 486 * to be performed. 487 * @param sender This is the widget which is reponsible for the 488 * click event and we will use this to establish exactly what the 489 * user was trying to do with the interface. 490 */ 491 492 public void onClick(final Widget sender) { 493 494 // Now we have to decide what button the user clicked on in 495 // the interface and then act accordingly 496 497 if (sender.equals(InterfaceInputFields[INSTRUMENTIDX].ButtonAcknowledgementWidget)) { 498 499 // The user wants to add a new instrument to the system 500 501 addNewInstrumentToSystem(); 502 503 } else if (sender.equals(InterfaceInputFields[TELESCOPEOPERATORIDX].ButtonAcknowledgementWidget)) { 504 505 // The user wants to add a new TO to the system 506 507 createNewRoleForUser(TELESCOPEOPERATORIDX,new Integer(FaultDatabaseConstants.TELESCOPEOPERATOR),internationalizationConstants.telescopeOperator()); 508 509 } else if (sender.equals(InterfaceInputFields[DUTYTECHNICIANIDX].ButtonAcknowledgementWidget)) { 510 511 // The user wants to add a new duty technician to the system 512 513 createNewRoleForUser(DUTYTECHNICIANIDX,new Integer(FaultDatabaseConstants.DUTYENGINEERS),internationalizationConstants.dutyTechnician()); 514 515 } else if (sender.equals(InterfaceInputFields[SUPPORTASTRONOMERIDX].ButtonAcknowledgementWidget)) { 516 517 // The user wants to add a new support astronomer to the system 518 519 createNewRoleForUser(SUPPORTASTRONOMERIDX,new Integer(FaultDatabaseConstants.SUPPORTASTRONOMERS),internationalizationConstants.supportAstronomer()); 520 521 522 } else if (sender.equals(InterfaceInputFields[SYSTEMIDX].ButtonAcknowledgementWidget)) { 523 524 // The user wants to add a new systen to the system 525 526 addNewSystemToSystem(); 527 528 } else if (sender.equals(ResetPasswordButton)) { 529 530 // The user wants to reset the password of a user 531 532 resetPasswordForUser(); 533 534 } else if (sender.equals(CreateNewUserButton)) { 535 536 // The user wants to add a new user to the system 537 538 createNewUser(); 539 } 540 } 541 542 /** 543 * This is a callback which is attached to the reset password 544 * button which will permit the manager to reset the password of a 545 * user 546 */ 547 548 private void resetPasswordForUser() { 549 550 // Verify that all of the fields have been filled in 551 552 final String password = PasswordField.getText(); 553 final String confirmedPassword = PasswordConfirmField.getText(); 554 final String emailAddress = UserToChangePwdList.getValue(UserToChangePwdList.getSelectedIndex()); 555 final String fullName = UserToChangePwdList.getItemText(UserToChangePwdList.getSelectedIndex()); 556 557 // Ensure that the user has filled in all of the fields in this section 558 559 if (password.equalsIgnoreCase("")) { 560 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.userPassword())); 561 return; 562 } 563 564 if (confirmedPassword.equalsIgnoreCase("")) { 565 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.confirmPassword())); 566 return; 567 } 568 569 if (emailAddress.equalsIgnoreCase("")) { 570 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.emailAddress())); 571 return; 572 } 573 574 // Check that the two passwords are the same 575 576 if (!confirmedPassword.equals(password)) { 577 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.passwordMismatch()); 578 return; 579 } 580 581 582 // Now we can reset the password which is associated with this user 583 584 MessageBox.confirm(internationalizationConstants.confirm(),internationalizationConstants.areYouSureYouWantToResetThisPassword(fullName),new MessageBox.ConfirmCallback() { 585 586 public void execute(String btnID) { 587 588 if ("yes".equals(btnID)) { 589 590 // Now execute the action of the servlet 591 592 svc.resetPassword (emailAddress,confirmedPassword,new AsyncCallback() { 593 594 public void onSuccess (final Object result) { 595 596 // Reset the input fields 597 598 PasswordField.setText(""); 599 PasswordConfirmField.setText(""); 600 } 601 602 public void onFailure (Throwable ex) { 603 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToResetPassword(fullName)); 604 } 605 }); 606 } 607 } 608 }); 609 } 610 611 612 /** 613 * This will add a new user to the system. The user must have 614 * filled in the name, surname and email fields in the form for 615 * this to happen. 616 */ 617 618 private void createNewUser() { 619 620 // First we need to check that the user has filled in all of 621 // the fields which he is expected to fill in 622 623 final String name = NameOfNewUser.getText(); 624 final String surname = SurnameOfNewUser.getText(); 625 final String emailAddress = MailAddressOfNewUser.getText(); 626 627 // Ensure that the user has filled in the name, surname and the email fields of the form 628 629 if (name.equalsIgnoreCase("")) { 630 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.name())); 631 return; 632 } 633 634 if (surname.equalsIgnoreCase("")) { 635 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.surname())); 636 return; 637 } 638 639 if (emailAddress.equalsIgnoreCase("")) { 640 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.emailAddress())); 641 return; 642 } 643 644 // Verify that the email address is a valid email address 645 646 if (!emailAddress.matches("(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*")) { 647 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.invalidEmailAddress()); 648 return; 649 } 650 651 // Now call the servlet to add the details of the new user to 652 // the system 653 654 svc.addNewUser (name,surname,emailAddress,new AsyncCallback() { 655 656 public void onSuccess (final Object result) { 657 658 // Reset the input fields 659 660 NameOfNewUser.setText(""); 661 SurnameOfNewUser.setText(""); 662 MailAddressOfNewUser.setText(""); 663 664 // Now reset the listbox fields to include the 665 // details of the new user which has been added 666 667 setupDropDownList(new Integer(FaultDatabaseConstants.TELESCOPEOPERATOR),(ListBox)InterfaceInputFields[TELESCOPEOPERATORIDX].InputWidget); 668 setupDropDownList(new Integer(FaultDatabaseConstants.DUTYENGINEERS),(ListBox)InterfaceInputFields[DUTYTECHNICIANIDX].InputWidget); 669 setupDropDownList(new Integer (FaultDatabaseConstants.SUPPORTASTRONOMERS),(ListBox)InterfaceInputFields[SUPPORTASTRONOMERIDX].InputWidget); 670 671 // Now update the list of users in the reset password list 672 673 fillListBoxWithStaffMembers(UserToChangePwdList,null,false); 674 675 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.newUserAdded(name,surname)); 676 } 677 678 public void onFailure (Throwable ex) { 679 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToAddNewUser()); 680 } 681 }); 682 } 683 684 /** 685 * Creates a new instrument in the system after first ensuring 686 * that the user has filled in the field correctly. 687 */ 688 689 private void addNewInstrumentToSystem () { 690 691 // Establish that the user has entered something sensible in 692 // the instrument field 693 694 final TextBox inputField = (TextBox)InterfaceInputFields[INSTRUMENTIDX].InputWidget; 695 696 final String newInstrument = inputField.getText(); 697 698 // Check that here has been something put into the field 699 700 if (newInstrument.equalsIgnoreCase("")) { 701 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.newInstrument())); 702 return; 703 } 704 705 svc.addNewInstrumentToSystem (newInstrument,new AsyncCallback() { 706 707 public void onSuccess (final Object result) { 708 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.newFieldAdded(newInstrument)); 709 inputField.setText(""); 710 } 711 712 public void onFailure (Throwable ex) { 713 MessageBox.alert(internationalizationConstants.information(),"Unable to add new instrument to the system"); 714 } 715 }); 716 717 } 718 719 /** 720 * Creates a new system in the system after first ensuring 721 * that the user has filled in the field correctly. 722 */ 723 724 private void addNewSystemToSystem () { 725 726 // Establish that the user has entered something sensible in 727 // the system field 728 729 final TextBox inputField = (TextBox)InterfaceInputFields[SYSTEMIDX].InputWidget; 730 731 final String newSystem = inputField.getText(); 732 733 // Check that here has been something put into the field 734 735 if (newSystem.equalsIgnoreCase("")) { 736 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.textFieldEmpty(internationalizationConstants.newSystem())); 737 return; 738 } 739 740 svc.addNewSystemToSystem (newSystem,new AsyncCallback() { 741 742 public void onSuccess (final Object result) { 743 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.newFieldAdded(newSystem)); 744 inputField.setText(""); 745 } 746 747 public void onFailure (Throwable ex) { 748 MessageBox.alert(internationalizationConstants.information(),"Unable to add new system to the system"); 749 } 750 }); 751 752 } 753 754 /** 755 * Creates a new role for a user. This will be used to add the use 756 * to the list of support astronomers, TOs etc. Calls the servlet 757 * which will add the user to the role. 758 * <P> 759 * @param WidgetIndex This is the index into the array which contains the drop down listboxes with the names of the potential members of the roles. 760 * @param Role This is the role into which he will be placed i.e. Support astronomer, TO etc. 761 * @param RoleDescription This is the description of the role in 762 * natural language expressed in the language of the current 763 * locale. 764 */ 765 766 private void createNewRoleForUser (final int WidgetIndex, final Integer Role,final String RoleDescription) { 767 768 // Fetch the email address of the person that is to be added 769 // to the new role from the drop down menu 770 771 final ListBox temp = (ListBox)InterfaceInputFields[WidgetIndex].InputWidget; 772 773 final String usersName = temp.getItemText(temp.getSelectedIndex()); 774 775 final String emailAddress = temp.getValue(temp.getSelectedIndex()); 776 777 // Ask the user if he is sure that he wants to do this before we go ahead 778 779 MessageBox.confirm(internationalizationConstants.confirm(),internationalizationConstants.areYouSureYouWantToAddUserToThisRole(usersName,RoleDescription + "s"),new MessageBox.ConfirmCallback() { 780 781 public void execute(String btnID) { 782 783 // If the user pressed yes 784 785 if ("yes".equals(btnID)) { 786 787 // Now make a call to the servlet to ask it to add the user to 788 // the role. 789 790 svc.addNewRole (emailAddress,Role,new AsyncCallback() { 791 792 public void onSuccess (final Object result) { 793 794 // Now we need to rebuild the list in the manage 795 // system interface to exclude the user which has 796 // just been added to the list 797 798 switch (Role.intValue()) { 799 800 case FaultDatabaseConstants.TELESCOPEOPERATOR : 801 setupDropDownList(new Integer(FaultDatabaseConstants.TELESCOPEOPERATOR),(ListBox)InterfaceInputFields[TELESCOPEOPERATORIDX].InputWidget); 802 break; 803 804 case FaultDatabaseConstants.DUTYENGINEERS : 805 setupDropDownList(new Integer(FaultDatabaseConstants.DUTYENGINEERS),(ListBox)InterfaceInputFields[DUTYTECHNICIANIDX].InputWidget); 806 break; 807 808 case FaultDatabaseConstants.SUPPORTASTRONOMERS : 809 setupDropDownList(new Integer (FaultDatabaseConstants.SUPPORTASTRONOMERS),(ListBox)InterfaceInputFields[SUPPORTASTRONOMERIDX].InputWidget); 810 break; 811 } 812 813 } 814 815 public void onFailure (Throwable ex) { 816 MessageBox.alert(internationalizationConstants.information(),"Unable to add user " + emailAddress + " to role"); 817 } 818 }); 819 } 820 } 821 }); 822 } 823 } 824 825