KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > worksheets > Edit


1 package projectmanagement.presentation.worksheets;
2
3 import projectmanagement.presentation.*;
4
5 import projectmanagement.spec.*;
6 import projectmanagement.spec.timewage.*;
7 import projectmanagement.spec.project.*;
8 import projectmanagement.spec.employee.*;
9 import com.lutris.appserver.server.httpPresentation.*;
10 import org.enhydra.xml.xmlc.XMLObject;
11
12 import org.w3c.dom.*;
13 import org.w3c.dom.html.*;
14
15 import java.sql.Date JavaDoc;
16 import java.sql.Time JavaDoc;
17 import java.util.*;
18
19
20 /**
21  * Manages all actions on worksheets.
22  *
23  * @author Sasa Bojanic
24  * @version 1.0
25  */

26 public class Edit extends BasePO {
27
28    /**
29     * Constants
30     */

31    private static String JavaDoc EMPLOYEE = "cboEmployee";
32    private static String JavaDoc PROJECT = "cboProject";
33    private static String JavaDoc WORKING_DATE_YYYY = "txtWorkingDateYYYY";
34    private static String JavaDoc WORKING_DATE_MM = "txtWorkingDateMM";
35    private static String JavaDoc WORKING_DATE_DD = "txtWorkingDateDD";
36    private static String JavaDoc TIME_STARTED_hh = "txtTimeStartedhh";
37    private static String JavaDoc TIME_STARTED_mm = "txtTimeStartedmm";
38    private static String JavaDoc TIME_FINISHED_hh = "txtTimeFinishedhh";
39    private static String JavaDoc TIME_FINISHED_mm = "txtTimeFinishedmm";
40    private static String JavaDoc PERSONAL_COMMENT= "txtPersonalComment";
41    private static String JavaDoc COMMENT_FOR_CLIENT = "txtCommentForClient";
42
43    private static String JavaDoc WORK_SHEET_ID = "workSheetID";
44    private static String JavaDoc SELECTED_EMPLOYEE_ID = "selectedEmployeeID";
45    private static String JavaDoc CONTEXT_PAGE = "Context.po";
46    private static String JavaDoc ADD = "add";
47    private static String JavaDoc DELETE = "delete";
48    private static String JavaDoc MODIFY = "modify";
49    private static String JavaDoc DETAILS = "showDetailsPage";
50    private static String JavaDoc POPULATE_PROJECTS = "populateProjects";
51    private static String JavaDoc IS_PERSONAL = "isPersonal";
52    private static String JavaDoc EVENT = "event";
53
54    /**
55     * Superclass method override. Returns 1 or 2, depending on action.
56     */

57    protected int getRequiredAuthLevel() {
58       String JavaDoc isPersonal="";
59       try {
60          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
61       } catch (Exception JavaDoc ex) {}
62
63       if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
64          return 1;
65       } else {
66          return 2;
67       }
68    }
69
70    /**
71     * Default event. Just show the page for editing.
72     */

73    public XMLObject handleDefault()
74          throws HttpPresentationException {
75       return showModifyPage(null,false);
76    }
77
78    /**
79     * handle show add worksheet page event.
80     *
81     * @return html document
82     * @exception HttpPresentationException
83     */

84    public XMLObject handleShowAddPage()
85       throws HttpPresentationException {
86       return showAddPage(null);
87    }
88
89    /**
90     * handle show details worksheet page event.
91     *
92     * @return html document
93     * @exception HttpPresentationException
94     */

95    public XMLObject handleShowDetailsPage ()
96          throws HttpPresentationException {
97       return showModifyPage(null,true);
98    }
99
100    /*
101     * Modifies an existing worksheet
102     *
103     * @return html document
104     * @exception HttpPresentationException
105     */

106    public XMLObject handleModify()
107          throws HttpPresentationException {
108       String JavaDoc workSheetID = this.getComms().request.getParameter(WORK_SHEET_ID);
109       WorkSheet workSheet=null;
110       // Try to get the worksheet by its ID
111
try {
112      WorkSheetManager workSheetManager = WorkSheetManagerFactory.
113                getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
114       workSheet = workSheetManager.findWorkSheetByID(workSheetID);
115    
116       } catch(Exception JavaDoc ex) {
117          this.getSessionData().setUserMessage("Please choose a valid worksheet to edit");
118          throw new ClientPageRedirectException(CONTEXT_PAGE);
119       }
120
121       try {
122          saveWorkSheet(workSheet);
123          String JavaDoc isPersonal="";
124          try {
125             isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
126          } catch (Exception JavaDoc ex) {}
127          String JavaDoc redirectTo=CONTEXT_PAGE;
128          if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
129             redirectTo=redirectTo+"?isPersonal=true";
130          }
131          throw new ClientPageRedirectException(redirectTo);
132       } catch(Exception JavaDoc ex) {
133          return showModifyPage("To modify this worksheet, you must fill out fields properly!",false);
134       }
135    }
136
137    /*
138     * Adds a worksheet to the worksheet database
139     *
140     * @return html document
141     * @exception HttpPresentationException
142     */

143    public XMLObject handleAdd()
144          throws HttpPresentationException {
145       try {
146   WorkSheetManager workSheetManager = WorkSheetManagerFactory.
147                getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
148       WorkSheet workSheet = workSheetManager.getWorkSheet();
149       
150                saveWorkSheet(workSheet);
151
152          String JavaDoc isPersonal="";
153          try {
154             isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
155    /*
156  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
157  * We need to allow ProjectManagement_pres to be functional , response
158  * will be default HTML page
159  */

160      } catch(NullPointerException JavaDoc ex) {
161           return showAddPage("You cannot add works sheets while runing ProjectManagement_pres");
162                 
163          } catch (Exception JavaDoc ex) {}
164          String JavaDoc redirectTo=CONTEXT_PAGE;
165          if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
166             redirectTo=redirectTo+"?isPersonal=true";
167          }
168          throw new ClientPageRedirectException(redirectTo);
169
170       } catch(Exception JavaDoc ex) {
171          return showAddPage("To add this worksheet, you must fill out fields properly!");
172       }
173    }
174
175    /*
176     * Deletes a WorkSheet from the WorkSheet database
177     *
178     * @return html document
179     * @exception HttpPresentationException
180     */

181    public XMLObject handleDelete()
182          throws HttpPresentationException, ProjectManagementPresentationException {
183       String JavaDoc workSheetID = this.getComms().request.getParameter(WORK_SHEET_ID);
184
185       try {
186   WorkSheetManager workSheetManager = WorkSheetManagerFactory.
187                getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
188       WorkSheet workSheet = workSheetManager.findWorkSheetByID(workSheetID);
189         
190          String JavaDoc workSheetName = "["+workSheet.getPayRate().getEmployee().getFirstName()+" "+
191             workSheet.getPayRate().getEmployee().getLastName()+","+
192             workSheet.getPayRate().getProject().getName()+"]";
193          workSheet.delete();
194          this.getSessionData().setUserMessage("The worksheet, " + workSheetName + ", was deleted");
195          // Catch any possible database exception as well as the null pointer
196
// exception if the worksheet is not found and is null after findWorkSheetByID
197
} catch(Exception JavaDoc ex) {
198          this.getSessionData().setUserMessage("Please choose a valid worksheet to delete");
199       }
200
201       String JavaDoc isPersonal="";
202       try {
203          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
204       } catch (Exception JavaDoc ex) {}
205       String JavaDoc redirectTo=CONTEXT_PAGE;
206       if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
207          redirectTo=redirectTo+"?isPersonal=true";
208       }
209       throw new ClientPageRedirectException(redirectTo);
210
211    }
212
213    /*
214     * Populates the projects combo based on the selected value of
215     * employee combo.
216     *
217     * @return html document
218     * @exception HttpPresentationException
219     */

220    public XMLObject handlePopulateProjects ()
221          throws HttpPresentationException {
222       String JavaDoc workSheetID = this.getComms().request.getParameter(WORK_SHEET_ID);
223       XMLObject page=showAddPage(null);
224       if (workSheetID!=null && workSheetID.length()>0) {
225          ((EditHTML)page).getElementWorkSheetID().setValue(workSheetID);
226          ((EditHTML)page).getElementEvent().setValue(MODIFY);
227       }
228       return page;
229    }
230
231    /**
232     * Produce HTML for this PO, populated by the worksheet information
233     * that the user wants to edit
234     *
235     * @param errorMsg, the error messages
236     * @param disabled, if controls are disabled
237     * @return html document
238     * @exception HttpPresentationException
239     */

240    public XMLObject showModifyPage(String JavaDoc errorMsg,boolean disabled)
241          throws HttpPresentationException, ProjectManagementPresentationException {
242
243       String JavaDoc employee = this.getComms().request.getParameter(EMPLOYEE);
244       String JavaDoc project = this.getComms().request.getParameter(PROJECT);
245       String JavaDoc workingDateYYYY = this.getComms().request.getParameter(WORKING_DATE_YYYY);
246       String JavaDoc workingDateMM = this.getComms().request.getParameter(WORKING_DATE_MM);
247       String JavaDoc workingDateDD = this.getComms().request.getParameter(WORKING_DATE_DD);
248       String JavaDoc timeStartedhh = this.getComms().request.getParameter(TIME_STARTED_hh);
249       String JavaDoc timeStartedmm = this.getComms().request.getParameter(TIME_STARTED_mm);
250       String JavaDoc timeFinishedhh = this.getComms().request.getParameter(TIME_FINISHED_hh);
251       String JavaDoc timeFinishedmm = this.getComms().request.getParameter(TIME_FINISHED_mm);
252       String JavaDoc personalComment = this.getComms().request.getParameter(PERSONAL_COMMENT);
253       String JavaDoc commentForClient = this.getComms().request.getParameter(COMMENT_FOR_CLIENT);
254
255       String JavaDoc workSheetID = this.getComms().request.getParameter(WORK_SHEET_ID);
256       // Instantiate the page object
257
EditHTML page = new EditHTML();
258
259       WorkSheet workSheet = null;
260
261       try {
262   WorkSheetManager workSheetManager = WorkSheetManagerFactory.
263                getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
264         workSheet = workSheetManager.findWorkSheetByID(workSheetID);
265   /*
266  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
267  * We need to allow ProjectManagement_pres to be functional , response
268  * will be default HTML page
269  */

270  
271       } catch(NullPointerException JavaDoc ex) {
272            page.setTextErrorText("This is a default HTML page");
273            return page;
274          // Catch any possible database exception in findWorkSheetByID()
275
} catch(ProjectManagementException ex) {
276          this.getSessionData().setUserMessage("Please choose a valid worksheet to edit");
277          throw new ClientPageRedirectException(CONTEXT_PAGE);
278       }
279
280       try {
281          // If we received a valid workSheetID then try to show the worksheet's contents,
282
// otherwise try to use the HTML input parameters
283
page.getElementWorkSheetID().setValue(workSheet.getHandle());
284
285          HTMLSelectElement sel=page.getElementCboEmployee();
286          sel.setDisabled(disabled);
287
288          if (null == employee || employee.length() == 0) {
289             employee=workSheet.getPayRate().getEmployee().getHandle();
290          }
291
292          fillEmployeeSelection(page,sel,employee);
293
294          sel=page.getElementCboProject();
295          if (null == project || project.length() == 0) {
296             project=workSheet.getPayRate().getProject().getHandle();
297          }
298          fillProjectSelection(page,sel,employee,project);
299          sel.setDisabled(disabled);
300
301          HTMLInputElement el=page.getElementTxtWorkingDateYYYY();
302          el.setDisabled(disabled);
303          if (null != workingDateYYYY && workingDateYYYY.length() != 0) {
304             el.setValue(workingDateYYYY);
305          } else {
306             Calendar cal=new GregorianCalendar();
307             cal.setTime(workSheet.getWorkingDate());
308             el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
309          }
310
311          el=page.getElementTxtWorkingDateMM();
312          el.setDisabled(disabled);
313          if (null != workingDateMM && workingDateMM.length() != 0) {
314             el.setValue(workingDateMM);
315          } else {
316             Calendar cal=new GregorianCalendar();
317             cal.setTime(workSheet.getWorkingDate());
318             el.setValue(String.valueOf(cal.get(Calendar.MONTH)+1));
319          }
320
321          el=page.getElementTxtWorkingDateDD();
322          el.setDisabled(disabled);
323          if (null != workingDateDD && workingDateDD.length() != 0) {
324             el.setValue(workingDateDD);
325          } else {
326             Calendar cal=new GregorianCalendar();
327             cal.setTime(workSheet.getWorkingDate());
328             el.setValue(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
329          }
330
331          el=page.getElementTxtTimeStartedhh();
332          el.setDisabled(disabled);
333          if (null != timeStartedhh && timeStartedhh.length() != 0) {
334             el.setValue(timeStartedhh);
335          } else {
336             Calendar cal=new GregorianCalendar();
337             cal.setTime(workSheet.getTimeStarted());
338             el.setValue(String.valueOf(cal.get(Calendar.HOUR_OF_DAY)));
339          }
340
341          el=page.getElementTxtTimeStartedmm();
342          el.setDisabled(disabled);
343          if (null != timeStartedmm && timeStartedmm.length() != 0) {
344             el.setValue(timeStartedmm);
345          } else {
346             Calendar cal=new GregorianCalendar();
347             cal.setTime(workSheet.getTimeStarted());
348             el.setValue(String.valueOf(cal.get(Calendar.MINUTE)));
349          }
350
351          el=page.getElementTxtTimeFinishedhh();
352          el.setDisabled(disabled);
353          if (null != timeFinishedhh && timeFinishedhh.length() != 0) {
354             el.setValue(timeFinishedhh);
355          } else {
356             Calendar cal=new GregorianCalendar();
357             cal.setTime(workSheet.getTimeFinished());
358             el.setValue(String.valueOf(cal.get(Calendar.HOUR_OF_DAY)));
359          }
360
361          el=page.getElementTxtTimeFinishedmm();
362          el.setDisabled(disabled);
363          if (null != timeFinishedmm && timeFinishedmm.length() != 0) {
364             el.setValue(timeFinishedmm);
365          } else {
366             Calendar cal=new GregorianCalendar();
367             cal.setTime(workSheet.getTimeFinished());
368             el.setValue(String.valueOf(cal.get(Calendar.MINUTE)));
369          }
370
371          //HTMLTextAreaElement tael=page.getElementTxtPersonalComment();
372
el=page.getElementTxtPersonalComment();
373          el.setDisabled(disabled);
374          if (null != personalComment && personalComment.length() != 0) {
375             el.setValue(personalComment);
376          } else {
377             el.setValue(workSheet.getPersonalComment());
378          }
379
380          el=page.getElementTxtCommentForClient();
381          el.setDisabled(disabled);
382          if (null != commentForClient && commentForClient.length() != 0) {
383             el.setValue(commentForClient);
384          } else {
385             el.setValue(workSheet.getCommentForClient());
386          }
387
388          el=page.getElementBtnSave();
389          el.setDisabled(disabled);
390
391          if (null == errorMsg) {
392             page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
393          } else {
394             page.setTextErrorText(errorMsg);
395          }
396       } catch(ProjectManagementException ex) {
397          throw new ProjectManagementPresentationException("Error populating page for worksheet editing", ex);
398       }
399
400       page.getElementEvent().setValue(MODIFY);
401       return page;
402    }
403
404    /**
405     * Produce HTML for this PO
406     *
407     * @param errorMsg, the error messages
408     * @return html document
409     * @exception HttpPresentationException
410     */

411    public XMLObject showAddPage(String JavaDoc errorMsg)
412          throws HttpPresentationException, ProjectManagementPresentationException {
413     // Instantiate the page object
414
EditHTML page = new EditHTML();
415 try{
416       String JavaDoc employee = this.getComms().request.getParameter(EMPLOYEE);
417       String JavaDoc project = this.getComms().request.getParameter(PROJECT);
418       String JavaDoc workingDateYYYY = this.getComms().request.getParameter(WORKING_DATE_YYYY);
419       String JavaDoc workingDateMM = this.getComms().request.getParameter(WORKING_DATE_MM);
420       String JavaDoc workingDateDD = this.getComms().request.getParameter(WORKING_DATE_DD);
421       String JavaDoc timeStartedhh = this.getComms().request.getParameter(TIME_STARTED_hh);
422       String JavaDoc timeStartedmm = this.getComms().request.getParameter(TIME_STARTED_mm);
423       String JavaDoc timeFinishedhh = this.getComms().request.getParameter(TIME_FINISHED_hh);
424       String JavaDoc timeFinishedmm = this.getComms().request.getParameter(TIME_FINISHED_mm);
425       String JavaDoc personalComment = this.getComms().request.getParameter(PERSONAL_COMMENT);
426       String JavaDoc commentForClient = this.getComms().request.getParameter(COMMENT_FOR_CLIENT);
427
428      
429
430       // set the worksheet id value to empty str
431
page.getElementWorkSheetID().setValue("");
432
433
434       HTMLSelectElement sel=page.getElementCboEmployee();
435       fillEmployeeSelection(page,sel,employee);
436
437       if (employee==null) {
438          sel.setSelectedIndex(0);
439          HTMLOptionElement sopt=(HTMLOptionElement)sel.getOptions().item(0);
440          if (sopt!=null) {
441             employee=sopt.getValue();
442          }
443       }
444
445       sel=page.getElementCboProject();
446       fillProjectSelection(page,sel,employee,project);
447
448       Calendar cal=new GregorianCalendar();
449       HTMLInputElement el=page.getElementTxtWorkingDateYYYY();
450       if (null!=workingDateYYYY) {
451          el.setValue(workingDateYYYY);
452       } else {
453          el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
454       }
455
456       el=page.getElementTxtWorkingDateMM();
457       if (null!=workingDateMM) {
458          el.setValue(workingDateMM);
459       } else {
460          el.setValue(String.valueOf(cal.get(Calendar.MONTH)+1));
461       }
462
463       el=page.getElementTxtWorkingDateDD();
464       if (null!=workingDateDD) {
465          el.setValue(workingDateDD);
466       } else {
467          el.setValue(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
468       }
469
470       el=page.getElementTxtTimeStartedhh();
471       if (null != timeStartedhh) {
472          el.setValue(timeStartedhh);
473       } else {
474          el.setValue("");
475       }
476
477       el=page.getElementTxtTimeStartedmm();
478       if (null != timeStartedmm) {
479          el.setValue(timeStartedmm);
480       } else {
481          el.setValue("");
482       }
483
484       el=page.getElementTxtTimeFinishedhh();
485       if (null != timeFinishedhh) {
486          el.setValue(timeFinishedhh);
487       } else {
488          el.setValue("");
489       }
490
491       el=page.getElementTxtTimeFinishedmm();
492       if (null != timeFinishedmm) {
493          el.setValue(timeFinishedmm);
494       } else {
495          el.setValue("");
496       }
497
498       //HTMLTextAreaElement tael=page.getElementTxtPersonalComment();
499
el=page.getElementTxtPersonalComment();
500       if (null != personalComment) {
501          el.setValue(personalComment);
502       } else {
503          el.setValue("");
504       }
505       el=page.getElementTxtCommentForClient();
506       if (null != commentForClient) {
507          el.setValue(commentForClient);
508       } else {
509          el.setValue("");
510       }
511
512
513       if (null == errorMsg) {
514          page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
515       } else {
516          page.setTextErrorText(errorMsg);
517       }
518       }catch(NullPointerException JavaDoc e){page.setTextErrorText(errorMsg);}
519       return page;
520    }
521
522    /**
523     * Method to save a new or existing worksheet to the database
524     *
525     * @param workSheet, the worksheet to be saved
526     * @return html document
527     * @exception HttpPresentationException
528     */

529    protected void saveWorkSheet(WorkSheet theWorkSheet)
530          throws HttpPresentationException,NullPointerException JavaDoc {
531
532       String JavaDoc employee = this.getComms().request.getParameter(EMPLOYEE);
533       String JavaDoc project = this.getComms().request.getParameter(PROJECT);
534       String JavaDoc workingDateYYYY = this.getComms().request.getParameter(WORKING_DATE_YYYY);
535       String JavaDoc workingDateMM = this.getComms().request.getParameter(WORKING_DATE_MM);
536       String JavaDoc workingDateDD = this.getComms().request.getParameter(WORKING_DATE_DD);
537       String JavaDoc timeStartedhh = this.getComms().request.getParameter(TIME_STARTED_hh);
538       String JavaDoc timeStartedmm = this.getComms().request.getParameter(TIME_STARTED_mm);
539       String JavaDoc timeFinishedhh = this.getComms().request.getParameter(TIME_FINISHED_hh);
540       String JavaDoc timeFinishedmm = this.getComms().request.getParameter(TIME_FINISHED_mm);
541       String JavaDoc personalComment = this.getComms().request.getParameter(PERSONAL_COMMENT);
542       String JavaDoc commentForClient = this.getComms().request.getParameter(COMMENT_FOR_CLIENT);
543
544       if (isNullField(employee) || isNullField(project) ||
545           !areDateFieldsValid(workingDateYYYY,workingDateMM,workingDateDD) ||
546           !areTimeFieldsValid(timeStartedhh,timeStartedmm) ||
547           !areTimeFieldsValid(timeFinishedhh,timeFinishedmm)) {
548          throw new ProjectManagementPresentationException("Error adding worksheet",new Exception JavaDoc());
549       }
550
551       try {
552          String JavaDoc workingDate=workingDateYYYY+"-"+workingDateMM+"-"+workingDateDD;
553          String JavaDoc timeStarted=timeStartedhh+":"+timeStartedmm+":"+"00";
554          String JavaDoc timeFinished=timeFinishedhh+":"+timeFinishedmm+":"+"00";
555      
556        PayRateManager payRateManager = PayRateManagerFactory.
557           getPayRateManager("projectmanagement.business.timewage.PayRateManagerImpl");
558        PayRate payRate = payRateManager.
559           findPayRateByEmployeeProjectAndDate(employee,project,Date.valueOf(workingDate));
560      
561          theWorkSheet.setPayRate(payRate);
562          theWorkSheet.setWorkingDate(Date.valueOf(workingDate));
563          Time JavaDoc ts=Time.valueOf(timeStarted);
564          Time JavaDoc tf=Time.valueOf(timeFinished);
565          if (tf.getTime()<ts.getTime()) {
566             throw new ProjectManagementPresentationException("Error adding worksheet - times are not properly set",null);
567          }
568          theWorkSheet.setTimeStarted(ts);
569          theWorkSheet.setTimeFinished(tf);
570          theWorkSheet.setPersonalComment(personalComment);
571          theWorkSheet.setCommentForClient(commentForClient);
572
573          theWorkSheet.save();
574       } catch(NullPointerException JavaDoc ex) {
575         throw new NullPointerException JavaDoc();
576       } catch(Exception JavaDoc ex) {
577          throw new ProjectManagementPresentationException("Error adding worksheet", ex);
578       }
579    }
580
581    private void fillEmployeeSelection (EditHTML page,HTMLSelectElement cboEmployees,
582          String JavaDoc selectedEmployeeID) throws ProjectManagementPresentationException {
583
584       String JavaDoc isPersonal="";
585       try {
586          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
587       } catch (Exception JavaDoc ex) {}
588       if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
589          HTMLInputElement ip=page.getElementIsPersonal();
590          ip.setValue("true");
591          HTMLAnchorElement a=page.getElementAncContext();
592          a.setHref("Context.po?isPersonal=true");
593          try {
594             selectedEmployeeID=getUser().getHandle();
595          } catch (Exception JavaDoc ex) {}
596       }
597
598       HTMLOptionElement optEmployee = page.getElementOptEmployee();
599       // Remove the dummy storyboard text from the prototype HTML
600
optEmployee.removeChild(optEmployee.getFirstChild());
601
602       try {
603       EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
604       Employee[] employees=employeeManager.getAllEmployees();
605          if (employees!=null) {
606             for (int i=0; i<employees.length; i++) {
607                Employee e=employees[i];
608                // if this is personal, fill the combo only with that employ
609
if (isPersonal!=null && isPersonal.equalsIgnoreCase("true") &&
610                      !e.getHandle().equals(selectedEmployeeID)) {
611                   continue;
612                }
613                // Now populate the combo with employees
614
// This algorithm is obscure because options
615
// are not normal HTML elements
616
// First populate the option value (the employee database ID).
617
// Then append a text child as the option
618
// text, which is what is displayed as the text
619
// in each row of the select box
620
HTMLOptionElement clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true);
621                clonedOption.setValue(e.getHandle());
622                Node optionTextNode = clonedOption.getOwnerDocument().
623                    createTextNode(e.getFirstName()+" "+e.getLastName());
624                clonedOption.appendChild(optionTextNode);
625                if (e.getHandle().equals(selectedEmployeeID)) {
626                    clonedOption.setAttribute("selected","selected");
627                }
628                // Do only a shallow copy of the option as we don't want the text child
629
// of the node option
630
cboEmployees.appendChild(clonedOption);
631                // Alternative way to insert nodes below
632
// insertBefore(newNode, oldNode);
633
// discSelect.insertBefore(clonedOption, templateOption);
634
}
635          }
636       cboEmployees.removeChild(optEmployee);
637  
638       } catch(NullPointerException JavaDoc ex) {
639       } catch (Exception JavaDoc ex) {
640          this.writeDebugMsg("Error populating list of employees: " + ex);
641          throw new ProjectManagementPresentationException("Error populating employee list: ", ex);
642       }
643
644    }
645
646    private void fillProjectSelection (EditHTML page,HTMLSelectElement cboProjects,
647          String JavaDoc selectedEmployeeID,String JavaDoc selectedProjectID)
648          throws ProjectManagementPresentationException {
649
650       HTMLOptionElement optProject = page.getElementOptProject();
651       // Remove the dummy storyboard text from the prototype HTML
652
optProject.removeChild(optProject.getFirstChild());
653
654       try {
655          PayRate[] payRates;
656     PayRateManager payRateManager = PayRateManagerFactory.
657           getPayRateManager("projectmanagement.business.timewage.PayRateManagerImpl");
658         
659        
660          if (selectedEmployeeID==null) {
661             payRates=payRateManager.getAllPayRates();
662          } else {
663             payRates=payRateManager.getAllPayRatesForEmployee(selectedEmployeeID,true);
664          }
665          if (payRates!=null) {
666             for (int i=0; i<payRates.length; i++) {
667                Project p=payRates[i].getProject();
668                // Now populate the combo with projects
669
// This algorithm is obscure because options
670
// are not normal HTML elements
671
// First populate the option value (the project database ID).
672
// Then append a text child as the option
673
// text, which is what is displayed as the text
674
// in each row of the select box
675
HTMLOptionElement clonedOption = (HTMLOptionElement)optProject.cloneNode(true);
676                clonedOption.setValue(p.getHandle());
677                Node optionTextNode = clonedOption.getOwnerDocument().
678                    createTextNode(p.getName());
679                clonedOption.appendChild(optionTextNode);
680                if (p.getHandle().equals(selectedProjectID)) {
681                    clonedOption.setAttribute("selected","selected");
682                }
683                // Do only a shallow copy of the option as we don't want the text child
684
// of the node option
685
cboProjects.appendChild(clonedOption);
686                // Alternative way to insert nodes below
687
// insertBefore(newNode, oldNode);
688
// discSelect.insertBefore(clonedOption, templateOption);
689
}
690          }
691       cboProjects.removeChild(optProject);
692       } catch(NullPointerException JavaDoc ex) {
693       } catch (Exception JavaDoc ex) {
694 ex.printStackTrace();
695          this.writeDebugMsg("Error populating list of projects: " + ex);
696          throw new ProjectManagementPresentationException("Error populating project list: ", ex);
697       }
698
699       
700    }
701
702    private boolean areTimeFieldsValid (String JavaDoc hh,String JavaDoc mm) {
703       if (isNullField(hh) || isNullField(mm)) {
704          return false;
705       }
706       try {
707          int h=Integer.valueOf(hh).intValue();
708          int m=Integer.valueOf(mm).intValue();
709          if (h<0 || h>23 || m<0 || m>59) {
710             return false;
711          }
712       } catch (Exception JavaDoc ex) {
713          return false;
714       }
715       return true;
716    }
717 }
718
719
Popular Tags