KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * projectManagement
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package projectmanagement.presentation.worksheets;
9
10 import projectmanagement.spec.employee.*;
11 import projectmanagement.spec.project.*;
12 import projectmanagement.presentation.*;
13
14 import org.w3c.dom.*;
15 import org.w3c.dom.html.*;
16
17 // Enhydra SuperServlet imports
18
import com.lutris.appserver.server.httpPresentation.HttpPresentation;
19 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
20 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
21 import org.enhydra.xml.xmlc.XMLObject;
22
23 // Standard imports
24
import java.io.IOException JavaDoc;
25 import java.util.Calendar JavaDoc;
26
27 /**
28 * Generates the blank HTML page.
29 */

30 public class Search extends BasePO {
31
32    private static String JavaDoc EMPLOYEE = "employee";
33    private static String JavaDoc PROJECT = "project";
34    private static String JavaDoc FROMYEAR = "fromyear";
35    private static String JavaDoc FROMMONTH = "frommonth";
36    private static String JavaDoc FROMDAY = "fromday";
37    private static String JavaDoc TOYEAR = "toyear";
38    private static String JavaDoc TOMONTH = "tomonth";
39    private static String JavaDoc TODAY = "today";
40
41    private static String JavaDoc IS_PERSONAL = "isPersonal";
42
43     /**
44     * Superclass method override. Returns 1 or 2, depending on action.
45     */

46    protected int getRequiredAuthLevel() {
47       String JavaDoc isPersonal="";
48       try {
49          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
50       } catch (Exception JavaDoc ex) {}
51
52       if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
53          return 1;
54       } else {
55          return 2;
56       }
57    }
58
59    /**
60     * Default event. Just show the page.
61     */

62    public XMLObject handleDefault()
63          throws HttpPresentationException {
64       SearchHTML page=new SearchHTML();
65
66       String JavaDoc employee = this.getComms().request.getParameter(EMPLOYEE);
67       HTMLSelectElement sel=page.getElementCboEmployee();
68       
69   
70       fillEmployeeSelection(page,sel,employee);
71      
72       String JavaDoc project = this.getComms().request.getParameter(PROJECT);
73       sel=page.getElementCboProject();
74       fillProjectSelection(page,sel,project);
75
76       fillFromDays(page);
77       fillFromMonths(page);
78       fillFromYears(page);
79
80       fillToDays(page);
81       fillToMonths(page);
82       fillToYears(page);
83
84
85       return page;
86    }
87
88    private void fillEmployeeSelection (SearchHTML page,HTMLSelectElement cboEmployees,
89          String JavaDoc selectedEmployeeID) throws ProjectManagementPresentationException {
90       HTMLOptionElement optEmployee = page.getElementOptEmployee();
91   try {
92       EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
93       Employee[] employees=employeeManager.getAllEmployees();
94  
95       // Remove the dummy storyboard text from the prototype HTML
96
optEmployee.removeChild(optEmployee.getFirstChild());
97
98       String JavaDoc isPersonal="";
99      
100          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
101       
102       if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
103          try {
104             selectedEmployeeID=getUser().getHandle();
105          } catch (Exception JavaDoc ex) {}
106       }
107
108      
109          // set the text to select all employees - default option
110
HTMLOptionElement clonedOption=null;
111          Node optionTextNode=null;
112          if (isPersonal==null || !isPersonal.equalsIgnoreCase("true")) {
113             clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true);
114             clonedOption.setValue("");
115             String JavaDoc all="All";
116             optionTextNode = clonedOption.getOwnerDocument().
117                createTextNode(all);
118             clonedOption.appendChild(optionTextNode);
119              clonedOption.setAttribute("selected","selected");
120             // Do only a shallow copy of the option as we don't want the text child
121
// of the node option
122
cboEmployees.appendChild(clonedOption);
123          }
124
125          // set all employees
126

127           if (employees!=null) {
128             for (int i=0; i<employees.length; i++) {
129                Employee e=employees[i];
130                // if this is personal, fill the combo only with that employ
131
if (isPersonal!=null && isPersonal.equalsIgnoreCase("true") &&
132                      !e.getHandle().equals(selectedEmployeeID)) {
133                   continue;
134                }
135
136                // Now populate the combo with employees
137
// This algorithm is obscure because options
138
// are not normal HTML elements
139
// First populate the option value (the employee database ID).
140
// Then append a text child as the option
141
// text, which is what is displayed as the text
142
// in each row of the select box
143
clonedOption = (HTMLOptionElement)optEmployee.cloneNode(true);
144                clonedOption.setValue(e.getHandle());
145                optionTextNode = clonedOption.getOwnerDocument().
146                    createTextNode(e.getFirstName()+" "+e.getLastName());
147                clonedOption.appendChild(optionTextNode);
148                if (selectedEmployeeID!=null && e.getHandle().equals(selectedEmployeeID)) {
149                   clonedOption.setAttribute("selected","selected");
150                }
151                // Do only a shallow copy of the option as we don't want the text child
152
// of the node option
153
cboEmployees.appendChild(clonedOption);
154             }
155          }
156          if ( this.getComms().request.getParameter("checkFromDate") != null && this.getComms().request.getParameter("checkFromDate").equals("false") ) {
157             ( (HTMLElement)page.getElementColorFrom() ).setAttribute("color","red");
158           }
159           if ( this.getComms().request.getParameter("checkToDate") != null && this.getComms().request.getParameter("checkToDate").equals("false") ) {
160             ( (HTMLElement)page.getElementColorTo() ).setAttribute("color","red");
161           }
162       } catch(NullPointerException JavaDoc ex) {
163       } catch (Exception JavaDoc ex) {
164          this.writeDebugMsg("Error populating list of employees: " + ex);
165          throw new ProjectManagementPresentationException("Error populating employee list: ", ex);
166       }
167
168       cboEmployees.removeChild(optEmployee);
169    }
170
171    private void fillProjectSelection (SearchHTML page,HTMLSelectElement cboProjects,
172          String JavaDoc selectedProjectID) throws ProjectManagementPresentationException {
173       HTMLOptionElement optProject = page.getElementOptProject();
174       try {
175          Project[] projects=null;
176        ProjectManager projectManager = ProjectManagerFactory.getProjectManager("projectmanagement.business.project.ProjectManagerImpl");
177
178       // Remove the dummy storyboard text from the prototype HTML
179
optProject.removeChild(optProject.getFirstChild());
180      
181       String JavaDoc isPersonal="";
182       
183          isPersonal=this.getComms().request.getParameter(IS_PERSONAL);
184     
185
186      
187          // set the text to select all projects - default option
188
HTMLOptionElement clonedOption = (HTMLOptionElement)optProject.cloneNode(true);
189          clonedOption.setValue("");
190          String JavaDoc all="All";
191          Node optionTextNode = clonedOption.getOwnerDocument().
192             createTextNode(all);
193          clonedOption.appendChild(optionTextNode);
194           clonedOption.setAttribute("selected","selected");
195          // Do only a shallow copy of the option as we don't want the text child
196
// of the node option
197
cboProjects.appendChild(clonedOption);
198
199          // set all projects
200

201          if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) {
202             // IMPLEMENT ME!!!
203
projects=projectManager.getAllProjects();
204          } else {
205             projects=projectManager.getAllProjects();
206          }
207          if (projects!=null) {
208             for (int i=0; i<projects.length; i++) {
209                Project p=projects[i];
210                // Now populate the combo with projects
211
// This algorithm is obscure because options
212
// are not normal HTML elements
213
// First populate the option value (the project database ID).
214
// Then append a text child as the option
215
// text, which is what is displayed as the text
216
// in each row of the select box
217
clonedOption = (HTMLOptionElement)optProject.cloneNode(true);
218                clonedOption.setValue(p.getHandle());
219                optionTextNode = clonedOption.getOwnerDocument().
220                    createTextNode(p.getName());
221                clonedOption.appendChild(optionTextNode);
222                if (selectedProjectID!=null && p.getHandle().equals(selectedProjectID)) {
223                    clonedOption.setAttribute("selected","selected");
224                }
225                // Do only a shallow copy of the option as we don't want the text child
226
// of the node option
227
cboProjects.appendChild(clonedOption);
228             }
229           }
230          cboProjects.removeChild(optProject);
231       } catch(NullPointerException JavaDoc ex) {
232       } catch (Exception JavaDoc ex) {
233         ex.printStackTrace();
234          this.writeDebugMsg("Error populating list of projects: " + ex);
235          throw new ProjectManagementPresentationException("Error populating project list: ", ex);
236       }
237
238       
239    }
240
241    private void fillFromDays(SearchHTML page)
242          throws ProjectManagementPresentationException {
243       HTMLSelectElement cboFromDay=page.getElementCboFromDay();
244       HTMLOptionElement optFromDay = page.getElementOptFromDay();
245       // Remove the dummy storyboard text from the prototype HTML
246
optFromDay.removeChild(optFromDay.getFirstChild());
247       try {
248          // set all days
249
HTMLOptionElement clonedOption = (HTMLOptionElement)optFromDay.cloneNode(true);
250          Node optionTextNode;
251          /*
252          String all="All";
253          clonedOption.setValue("");
254          Node optionTextNode = clonedOption.getOwnerDocument().
255             createTextNode(all);
256          clonedOption.appendChild(optionTextNode);
257          cboFromDay.appendChild(clonedOption);
258          */

259
260          for (int i=1; i<=31; i++) {
261             // Now populate the combo with days
262
// This algorithm is obscure because options
263
// are not normal HTML elements
264
// First populate the option value (the day database ID).
265
// Then append a text child as the option
266
// text, which is what is displayed as the text
267
// in each row of the select box
268
clonedOption = (HTMLOptionElement)optFromDay.cloneNode(true);
269             String JavaDoc curDay=String.valueOf(i);
270             clonedOption.setValue(curDay);
271             optionTextNode = clonedOption.getOwnerDocument().
272                createTextNode(curDay);
273             clonedOption.appendChild(optionTextNode);
274             if ( i==Calendar.getInstance().get(Calendar.DAY_OF_MONTH) ) {
275                 clonedOption.setAttribute("selected","selected");
276             }
277
278             // Do only a shallow copy of the option as we don't want the text child
279
// of the node option
280
cboFromDay.appendChild(clonedOption);
281            
282          }
283        cboFromDay.removeChild(optFromDay);
284       } catch(NullPointerException JavaDoc ex) {
285       } catch (Exception JavaDoc ex) {
286          this.writeDebugMsg("Error populating list of days: " + ex);
287          throw new ProjectManagementPresentationException("Error populating day list: ", ex);
288       }
289
290       
291    }
292
293    private void fillFromMonths(SearchHTML page)
294          throws ProjectManagementPresentationException {
295       HTMLSelectElement cboFromMonth=page.getElementCboFromMonth();
296       HTMLOptionElement optFromMonth = page.getElementOptFromMonth();
297       // Remove the dummy storyboard text from the prototype HTML
298
optFromMonth.removeChild(optFromMonth.getFirstChild());
299       try {
300  
301          // set all months
302
HTMLOptionElement clonedOption = (HTMLOptionElement)optFromMonth.cloneNode(true);
303          Node optionTextNode;
304          /*
305          String all="All";
306          clonedOption.setValue("");
307          Node optionTextNode = clonedOption.getOwnerDocument().
308             createTextNode(all);
309          clonedOption.appendChild(optionTextNode);
310          cboFromMonth.appendChild(clonedOption);
311          */

312
313          for (int i=1; i<=12; i++) {
314             // Now populate the combo with months
315
// This algorithm is obscure because options
316
// are not normal HTML elements
317
// First populate the option value (the month database ID).
318
// Then append a text child as the option
319
// text, which is what is displayed as the text
320
// in each row of the select box
321
clonedOption = (HTMLOptionElement)optFromMonth.cloneNode(true);
322             String JavaDoc curMonth=String.valueOf(i);
323             clonedOption.setValue(curMonth);
324             optionTextNode = clonedOption.getOwnerDocument().
325                createTextNode(curMonth);
326             clonedOption.appendChild(optionTextNode);
327             if( i==Calendar.getInstance().get(Calendar.MONTH)+1 ) {
328                 clonedOption.setAttribute("selected","selected");
329             }
330
331             // Do only a shallow copy of the option as we don't want the text child
332
// of the node option
333
cboFromMonth.appendChild(clonedOption);
334          }
335      cboFromMonth.removeChild(optFromMonth);
336       } catch(NullPointerException JavaDoc ex) {
337       } catch (Exception JavaDoc ex) {
338          this.writeDebugMsg("Error populating list of months: " + ex);
339          throw new ProjectManagementPresentationException("Error populating month list: ", ex);
340       }
341    }
342
343    private void fillFromYears(SearchHTML page)
344          throws ProjectManagementPresentationException {
345       HTMLSelectElement cboFromYear=page.getElementCboFromYear();
346       HTMLOptionElement optFromYear = page.getElementOptFromYear();
347       // Remove the dummy storyboard text from the prototype HTML
348
optFromYear.removeChild(optFromYear.getFirstChild());
349       try {
350          // set all years
351
HTMLOptionElement clonedOption = (HTMLOptionElement)optFromYear.cloneNode(true);
352          Node optionTextNode;
353          /*
354          String all="All";
355          clonedOption.setValue("");
356          Node optionTextNode = clonedOption.getOwnerDocument().
357             createTextNode(all);
358          clonedOption.appendChild(optionTextNode);
359          cboFromYear.appendChild(clonedOption);
360          */

361
362          for (int i=1998; i<=2008; i++) {
363             // Now populate the combo with years
364
// This algorithm is obscure because options
365
// are not normal HTML elements
366
// First populate the option value (the year database ID).
367
// Then append a text child as the option
368
// text, which is what is displayed as the text
369
// in each row of the select box
370
clonedOption = (HTMLOptionElement)optFromYear.cloneNode(true);
371             String JavaDoc curYear=String.valueOf(i);
372             clonedOption.setValue(curYear);
373             optionTextNode = clonedOption.getOwnerDocument().
374                createTextNode(curYear);
375             clonedOption.appendChild(optionTextNode);
376             if( i==Calendar.getInstance().get(Calendar.YEAR) ) {
377                 clonedOption.setAttribute("selected","selected");
378             }
379
380             // Do only a shallow copy of the option as we don't want the text child
381
// of the node option
382
cboFromYear.appendChild(clonedOption);
383          }
384          cboFromYear.removeChild(optFromYear);
385  
386       } catch(NullPointerException JavaDoc ex) {
387       } catch (Exception JavaDoc ex) {
388          this.writeDebugMsg("Error populating list of years: " + ex);
389          throw new ProjectManagementPresentationException("Error populating year list: ", ex);
390       }
391
392       
393    }
394
395
396    private void fillToDays(SearchHTML page)
397          throws ProjectManagementPresentationException {
398       HTMLSelectElement cboToDay=page.getElementCboToDay();
399       HTMLOptionElement optToDay = page.getElementOptToDay();
400       // Remove the dummy storyboard text to the prototype HTML
401
optToDay.removeChild(optToDay.getFirstChild());
402       try {
403          // set all days
404
HTMLOptionElement clonedOption = (HTMLOptionElement)optToDay.cloneNode(true);
405          Node optionTextNode;
406          /*
407          String all="All";
408          clonedOption.setValue("");
409          Node optionTextNode = clonedOption.getOwnerDocument().
410             createTextNode(all);
411          clonedOption.appendChild(optionTextNode);
412          cboToDay.appendChild(clonedOption);
413          */

414
415          for (int i=1; i<=31; i++) {
416             // Now populate the combo with days
417
// This algorithm is obscure because options
418
// are not normal HTML elements
419
// First populate the option value (the day database ID).
420
// Then append a text child as the option
421
// text, which is what is displayed as the text
422
// in each row of the select box
423
clonedOption = (HTMLOptionElement)optToDay.cloneNode(true);
424             String JavaDoc curDay=String.valueOf(i);
425             clonedOption.setValue(curDay);
426             optionTextNode = clonedOption.getOwnerDocument().
427                createTextNode(curDay);
428             clonedOption.appendChild(optionTextNode);
429             if( i==Calendar.getInstance().get(Calendar.DAY_OF_MONTH) ) {
430                 clonedOption.setAttribute("selected","selected");
431             }
432
433             // Do only a shallow copy of the option as we don't want the text child
434
// of the node option
435
cboToDay.appendChild(clonedOption);
436          }
437           cboToDay.removeChild(optToDay);
438       } catch(NullPointerException JavaDoc ex) {
439       } catch (Exception JavaDoc ex) {
440          this.writeDebugMsg("Error populating list of days: " + ex);
441          throw new ProjectManagementPresentationException("Error populating day list: ", ex);
442       }
443
444      
445    }
446
447    private void fillToMonths(SearchHTML page)
448          throws ProjectManagementPresentationException {
449       HTMLSelectElement cboToMonth=page.getElementCboToMonth();
450       HTMLOptionElement optToMonth = page.getElementOptToMonth();
451       // Remove the dummy storyboard text to the prototype HTML
452
optToMonth.removeChild(optToMonth.getFirstChild());
453       try {
454          // set all months
455
HTMLOptionElement clonedOption = (HTMLOptionElement)optToMonth.cloneNode(true);
456          Node optionTextNode;
457          /*
458          String all="All";
459          clonedOption.setValue("");
460          Node optionTextNode = clonedOption.getOwnerDocument().
461             createTextNode(all);
462          clonedOption.appendChild(optionTextNode);
463          cboToMonth.appendChild(clonedOption);
464          */

465
466          for (int i=1; i<=12; i++) {
467             // Now populate the combo with months
468
// This algorithm is obscure because options
469
// are not normal HTML elements
470
// First populate the option value (the month database ID).
471
// Then append a text child as the option
472
// text, which is what is displayed as the text
473
// in each row of the select box
474
clonedOption = (HTMLOptionElement)optToMonth.cloneNode(true);
475             String JavaDoc curMonth=String.valueOf(i);
476             clonedOption.setValue(curMonth);
477             optionTextNode = clonedOption.getOwnerDocument().
478                createTextNode(curMonth);
479             clonedOption.appendChild(optionTextNode);
480             if( i==Calendar.getInstance().get(Calendar.MONTH)+1 ) {
481                 clonedOption.setAttribute("selected","selected");
482             }
483             // Do only a shallow copy of the option as we don't want the text child
484
// of the node option
485
cboToMonth.appendChild(clonedOption);
486          }
487       cboToMonth.removeChild(optToMonth);
488       } catch(NullPointerException JavaDoc ex) {
489       } catch (Exception JavaDoc ex) {
490          this.writeDebugMsg("Error populating list of months: " + ex);
491          throw new ProjectManagementPresentationException("Error populating month list: ", ex);
492       }
493
494       
495    }
496
497    private void fillToYears(SearchHTML page)
498          throws ProjectManagementPresentationException {
499       HTMLSelectElement cboToYear=page.getElementCboToYear();
500       HTMLOptionElement optToYear = page.getElementOptToYear();
501       // Remove the dummy storyboard text to the prototype HTML
502
optToYear.removeChild(optToYear.getFirstChild());
503       try {
504          // set all years
505
HTMLOptionElement clonedOption = (HTMLOptionElement)optToYear.cloneNode(true);
506          Node optionTextNode;
507          /*
508          String all="All";
509          clonedOption.setValue("");
510          Node optionTextNode = clonedOption.getOwnerDocument().
511             createTextNode(all);
512          clonedOption.appendChild(optionTextNode);
513          cboToYear.appendChild(clonedOption);
514          */

515
516          for (int i=1998; i<=2008; i++) {
517             // Now populate the combo with years
518
// This algorithm is obscure because options
519
// are not normal HTML elements
520
// First populate the option value (the year database ID).
521
// Then append a text child as the option
522
// text, which is what is displayed as the text
523
// in each row of the select box
524
clonedOption = (HTMLOptionElement)optToYear.cloneNode(true);
525             String JavaDoc curYear=String.valueOf(i);
526             clonedOption.setValue(curYear);
527             optionTextNode = clonedOption.getOwnerDocument().
528                createTextNode(curYear);
529             clonedOption.appendChild(optionTextNode);
530             if ( i==Calendar.getInstance().get(Calendar.YEAR) ) {
531                clonedOption.setAttribute("selected","selected");
532             }
533             // Do only a shallow copy of the option as we don't want the text child
534
// of the node option
535
cboToYear.appendChild(clonedOption);
536          }
537           cboToYear.removeChild(optToYear);
538        } catch(NullPointerException JavaDoc ex) {
539       } catch (Exception JavaDoc ex) {
540          this.writeDebugMsg("Error populating list of years: " + ex);
541          throw new ProjectManagementPresentationException("Error populating year list: ", ex);
542       }
543
544      
545    }
546
547
548 }
Popular Tags