001: /*
002: * projectManagement
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package projectmanagement.presentation.worksheets;
009:
010: import projectmanagement.spec.employee.*;
011: import projectmanagement.spec.project.*;
012: import projectmanagement.presentation.*;
013:
014: import org.w3c.dom.*;
015: import org.w3c.dom.html.*;
016:
017: // Enhydra SuperServlet imports
018: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
019: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
020: import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
021: import org.enhydra.xml.xmlc.XMLObject;
022:
023: // Standard imports
024: import java.io.IOException;
025: import java.util.Calendar;
026:
027: /**
028: * Generates the blank HTML page.
029: */
030: public class Search extends BasePO {
031:
032: private static String EMPLOYEE = "employee";
033: private static String PROJECT = "project";
034: private static String FROMYEAR = "fromyear";
035: private static String FROMMONTH = "frommonth";
036: private static String FROMDAY = "fromday";
037: private static String TOYEAR = "toyear";
038: private static String TOMONTH = "tomonth";
039: private static String TODAY = "today";
040:
041: private static String IS_PERSONAL = "isPersonal";
042:
043: /**
044: * Superclass method override. Returns 1 or 2, depending on action.
045: */
046: protected int getRequiredAuthLevel() {
047: String isPersonal = "";
048: try {
049: isPersonal = this .getComms().request
050: .getParameter(IS_PERSONAL);
051: } catch (Exception ex) {
052: }
053:
054: if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
055: return 1;
056: } else {
057: return 2;
058: }
059: }
060:
061: /**
062: * Default event. Just show the page.
063: */
064: public XMLObject handleDefault() throws HttpPresentationException {
065: SearchHTML page = new SearchHTML();
066:
067: String employee = this .getComms().request
068: .getParameter(EMPLOYEE);
069: HTMLSelectElement sel = page.getElementCboEmployee();
070:
071: fillEmployeeSelection(page, sel, employee);
072:
073: String project = this .getComms().request.getParameter(PROJECT);
074: sel = page.getElementCboProject();
075: fillProjectSelection(page, sel, project);
076:
077: fillFromDays(page);
078: fillFromMonths(page);
079: fillFromYears(page);
080:
081: fillToDays(page);
082: fillToMonths(page);
083: fillToYears(page);
084:
085: return page;
086: }
087:
088: private void fillEmployeeSelection(SearchHTML page,
089: HTMLSelectElement cboEmployees, String selectedEmployeeID)
090: throws ProjectManagementPresentationException {
091: HTMLOptionElement optEmployee = page.getElementOptEmployee();
092: try {
093: EmployeeManager employeeManager = EmployeeManagerFactory
094: .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
095: Employee[] employees = employeeManager.getAllEmployees();
096:
097: // Remove the dummy storyboard text from the prototype HTML
098: optEmployee.removeChild(optEmployee.getFirstChild());
099:
100: String isPersonal = "";
101:
102: isPersonal = this .getComms().request
103: .getParameter(IS_PERSONAL);
104:
105: if (isPersonal != null
106: && isPersonal.equalsIgnoreCase("true")) {
107: try {
108: selectedEmployeeID = getUser().getHandle();
109: } catch (Exception ex) {
110: }
111: }
112:
113: // set the text to select all employees - default option
114: HTMLOptionElement clonedOption = null;
115: Node optionTextNode = null;
116: if (isPersonal == null
117: || !isPersonal.equalsIgnoreCase("true")) {
118: clonedOption = (HTMLOptionElement) optEmployee
119: .cloneNode(true);
120: clonedOption.setValue("");
121: String all = "All";
122: optionTextNode = clonedOption.getOwnerDocument()
123: .createTextNode(all);
124: clonedOption.appendChild(optionTextNode);
125: clonedOption.setAttribute("selected", "selected");
126: // Do only a shallow copy of the option as we don't want the text child
127: // of the node option
128: cboEmployees.appendChild(clonedOption);
129: }
130:
131: // set all employees
132:
133: if (employees != null) {
134: for (int i = 0; i < employees.length; i++) {
135: Employee e = employees[i];
136: // if this is personal, fill the combo only with that employ
137: if (isPersonal != null
138: && isPersonal.equalsIgnoreCase("true")
139: && !e.getHandle()
140: .equals(selectedEmployeeID)) {
141: continue;
142: }
143:
144: // Now populate the combo with employees
145: // This algorithm is obscure because options
146: // are not normal HTML elements
147: // First populate the option value (the employee database ID).
148: // Then append a text child as the option
149: // text, which is what is displayed as the text
150: // in each row of the select box
151: clonedOption = (HTMLOptionElement) optEmployee
152: .cloneNode(true);
153: clonedOption.setValue(e.getHandle());
154: optionTextNode = clonedOption.getOwnerDocument()
155: .createTextNode(
156: e.getFirstName() + " "
157: + e.getLastName());
158: clonedOption.appendChild(optionTextNode);
159: if (selectedEmployeeID != null
160: && e.getHandle().equals(selectedEmployeeID)) {
161: clonedOption.setAttribute("selected",
162: "selected");
163: }
164: // Do only a shallow copy of the option as we don't want the text child
165: // of the node option
166: cboEmployees.appendChild(clonedOption);
167: }
168: }
169: if (this .getComms().request.getParameter("checkFromDate") != null
170: && this .getComms().request.getParameter(
171: "checkFromDate").equals("false")) {
172: ((HTMLElement) page.getElementColorFrom())
173: .setAttribute("color", "red");
174: }
175: if (this .getComms().request.getParameter("checkToDate") != null
176: && this .getComms().request.getParameter(
177: "checkToDate").equals("false")) {
178: ((HTMLElement) page.getElementColorTo()).setAttribute(
179: "color", "red");
180: }
181: } catch (NullPointerException ex) {
182: } catch (Exception ex) {
183: this .writeDebugMsg("Error populating list of employees: "
184: + ex);
185: throw new ProjectManagementPresentationException(
186: "Error populating employee list: ", ex);
187: }
188:
189: cboEmployees.removeChild(optEmployee);
190: }
191:
192: private void fillProjectSelection(SearchHTML page,
193: HTMLSelectElement cboProjects, String selectedProjectID)
194: throws ProjectManagementPresentationException {
195: HTMLOptionElement optProject = page.getElementOptProject();
196: try {
197: Project[] projects = null;
198: ProjectManager projectManager = ProjectManagerFactory
199: .getProjectManager("projectmanagement.business.project.ProjectManagerImpl");
200:
201: // Remove the dummy storyboard text from the prototype HTML
202: optProject.removeChild(optProject.getFirstChild());
203:
204: String isPersonal = "";
205:
206: isPersonal = this .getComms().request
207: .getParameter(IS_PERSONAL);
208:
209: // set the text to select all projects - default option
210: HTMLOptionElement clonedOption = (HTMLOptionElement) optProject
211: .cloneNode(true);
212: clonedOption.setValue("");
213: String all = "All";
214: Node optionTextNode = clonedOption.getOwnerDocument()
215: .createTextNode(all);
216: clonedOption.appendChild(optionTextNode);
217: clonedOption.setAttribute("selected", "selected");
218: // Do only a shallow copy of the option as we don't want the text child
219: // of the node option
220: cboProjects.appendChild(clonedOption);
221:
222: // set all projects
223:
224: if (isPersonal != null
225: && isPersonal.equalsIgnoreCase("true")) {
226: // IMPLEMENT ME!!!
227: projects = projectManager.getAllProjects();
228: } else {
229: projects = projectManager.getAllProjects();
230: }
231: if (projects != null) {
232: for (int i = 0; i < projects.length; i++) {
233: Project p = projects[i];
234: // Now populate the combo with projects
235: // This algorithm is obscure because options
236: // are not normal HTML elements
237: // First populate the option value (the project database ID).
238: // Then append a text child as the option
239: // text, which is what is displayed as the text
240: // in each row of the select box
241: clonedOption = (HTMLOptionElement) optProject
242: .cloneNode(true);
243: clonedOption.setValue(p.getHandle());
244: optionTextNode = clonedOption.getOwnerDocument()
245: .createTextNode(p.getName());
246: clonedOption.appendChild(optionTextNode);
247: if (selectedProjectID != null
248: && p.getHandle().equals(selectedProjectID)) {
249: clonedOption.setAttribute("selected",
250: "selected");
251: }
252: // Do only a shallow copy of the option as we don't want the text child
253: // of the node option
254: cboProjects.appendChild(clonedOption);
255: }
256: }
257: cboProjects.removeChild(optProject);
258: } catch (NullPointerException ex) {
259: } catch (Exception ex) {
260: ex.printStackTrace();
261: this .writeDebugMsg("Error populating list of projects: "
262: + ex);
263: throw new ProjectManagementPresentationException(
264: "Error populating project list: ", ex);
265: }
266:
267: }
268:
269: private void fillFromDays(SearchHTML page)
270: throws ProjectManagementPresentationException {
271: HTMLSelectElement cboFromDay = page.getElementCboFromDay();
272: HTMLOptionElement optFromDay = page.getElementOptFromDay();
273: // Remove the dummy storyboard text from the prototype HTML
274: optFromDay.removeChild(optFromDay.getFirstChild());
275: try {
276: // set all days
277: HTMLOptionElement clonedOption = (HTMLOptionElement) optFromDay
278: .cloneNode(true);
279: Node optionTextNode;
280: /*
281: String all="All";
282: clonedOption.setValue("");
283: Node optionTextNode = clonedOption.getOwnerDocument().
284: createTextNode(all);
285: clonedOption.appendChild(optionTextNode);
286: cboFromDay.appendChild(clonedOption);
287: */
288:
289: for (int i = 1; i <= 31; i++) {
290: // Now populate the combo with days
291: // This algorithm is obscure because options
292: // are not normal HTML elements
293: // First populate the option value (the day database ID).
294: // Then append a text child as the option
295: // text, which is what is displayed as the text
296: // in each row of the select box
297: clonedOption = (HTMLOptionElement) optFromDay
298: .cloneNode(true);
299: String curDay = String.valueOf(i);
300: clonedOption.setValue(curDay);
301: optionTextNode = clonedOption.getOwnerDocument()
302: .createTextNode(curDay);
303: clonedOption.appendChild(optionTextNode);
304: if (i == Calendar.getInstance().get(
305: Calendar.DAY_OF_MONTH)) {
306: clonedOption.setAttribute("selected", "selected");
307: }
308:
309: // Do only a shallow copy of the option as we don't want the text child
310: // of the node option
311: cboFromDay.appendChild(clonedOption);
312:
313: }
314: cboFromDay.removeChild(optFromDay);
315: } catch (NullPointerException ex) {
316: } catch (Exception ex) {
317: this .writeDebugMsg("Error populating list of days: " + ex);
318: throw new ProjectManagementPresentationException(
319: "Error populating day list: ", ex);
320: }
321:
322: }
323:
324: private void fillFromMonths(SearchHTML page)
325: throws ProjectManagementPresentationException {
326: HTMLSelectElement cboFromMonth = page.getElementCboFromMonth();
327: HTMLOptionElement optFromMonth = page.getElementOptFromMonth();
328: // Remove the dummy storyboard text from the prototype HTML
329: optFromMonth.removeChild(optFromMonth.getFirstChild());
330: try {
331:
332: // set all months
333: HTMLOptionElement clonedOption = (HTMLOptionElement) optFromMonth
334: .cloneNode(true);
335: Node optionTextNode;
336: /*
337: String all="All";
338: clonedOption.setValue("");
339: Node optionTextNode = clonedOption.getOwnerDocument().
340: createTextNode(all);
341: clonedOption.appendChild(optionTextNode);
342: cboFromMonth.appendChild(clonedOption);
343: */
344:
345: for (int i = 1; i <= 12; i++) {
346: // Now populate the combo with months
347: // This algorithm is obscure because options
348: // are not normal HTML elements
349: // First populate the option value (the month database ID).
350: // Then append a text child as the option
351: // text, which is what is displayed as the text
352: // in each row of the select box
353: clonedOption = (HTMLOptionElement) optFromMonth
354: .cloneNode(true);
355: String curMonth = String.valueOf(i);
356: clonedOption.setValue(curMonth);
357: optionTextNode = clonedOption.getOwnerDocument()
358: .createTextNode(curMonth);
359: clonedOption.appendChild(optionTextNode);
360: if (i == Calendar.getInstance().get(Calendar.MONTH) + 1) {
361: clonedOption.setAttribute("selected", "selected");
362: }
363:
364: // Do only a shallow copy of the option as we don't want the text child
365: // of the node option
366: cboFromMonth.appendChild(clonedOption);
367: }
368: cboFromMonth.removeChild(optFromMonth);
369: } catch (NullPointerException ex) {
370: } catch (Exception ex) {
371: this
372: .writeDebugMsg("Error populating list of months: "
373: + ex);
374: throw new ProjectManagementPresentationException(
375: "Error populating month list: ", ex);
376: }
377: }
378:
379: private void fillFromYears(SearchHTML page)
380: throws ProjectManagementPresentationException {
381: HTMLSelectElement cboFromYear = page.getElementCboFromYear();
382: HTMLOptionElement optFromYear = page.getElementOptFromYear();
383: // Remove the dummy storyboard text from the prototype HTML
384: optFromYear.removeChild(optFromYear.getFirstChild());
385: try {
386: // set all years
387: HTMLOptionElement clonedOption = (HTMLOptionElement) optFromYear
388: .cloneNode(true);
389: Node optionTextNode;
390: /*
391: String all="All";
392: clonedOption.setValue("");
393: Node optionTextNode = clonedOption.getOwnerDocument().
394: createTextNode(all);
395: clonedOption.appendChild(optionTextNode);
396: cboFromYear.appendChild(clonedOption);
397: */
398:
399: for (int i = 1998; i <= 2008; i++) {
400: // Now populate the combo with years
401: // This algorithm is obscure because options
402: // are not normal HTML elements
403: // First populate the option value (the year database ID).
404: // Then append a text child as the option
405: // text, which is what is displayed as the text
406: // in each row of the select box
407: clonedOption = (HTMLOptionElement) optFromYear
408: .cloneNode(true);
409: String curYear = String.valueOf(i);
410: clonedOption.setValue(curYear);
411: optionTextNode = clonedOption.getOwnerDocument()
412: .createTextNode(curYear);
413: clonedOption.appendChild(optionTextNode);
414: if (i == Calendar.getInstance().get(Calendar.YEAR)) {
415: clonedOption.setAttribute("selected", "selected");
416: }
417:
418: // Do only a shallow copy of the option as we don't want the text child
419: // of the node option
420: cboFromYear.appendChild(clonedOption);
421: }
422: cboFromYear.removeChild(optFromYear);
423:
424: } catch (NullPointerException ex) {
425: } catch (Exception ex) {
426: this .writeDebugMsg("Error populating list of years: " + ex);
427: throw new ProjectManagementPresentationException(
428: "Error populating year list: ", ex);
429: }
430:
431: }
432:
433: private void fillToDays(SearchHTML page)
434: throws ProjectManagementPresentationException {
435: HTMLSelectElement cboToDay = page.getElementCboToDay();
436: HTMLOptionElement optToDay = page.getElementOptToDay();
437: // Remove the dummy storyboard text to the prototype HTML
438: optToDay.removeChild(optToDay.getFirstChild());
439: try {
440: // set all days
441: HTMLOptionElement clonedOption = (HTMLOptionElement) optToDay
442: .cloneNode(true);
443: Node optionTextNode;
444: /*
445: String all="All";
446: clonedOption.setValue("");
447: Node optionTextNode = clonedOption.getOwnerDocument().
448: createTextNode(all);
449: clonedOption.appendChild(optionTextNode);
450: cboToDay.appendChild(clonedOption);
451: */
452:
453: for (int i = 1; i <= 31; i++) {
454: // Now populate the combo with days
455: // This algorithm is obscure because options
456: // are not normal HTML elements
457: // First populate the option value (the day database ID).
458: // Then append a text child as the option
459: // text, which is what is displayed as the text
460: // in each row of the select box
461: clonedOption = (HTMLOptionElement) optToDay
462: .cloneNode(true);
463: String curDay = String.valueOf(i);
464: clonedOption.setValue(curDay);
465: optionTextNode = clonedOption.getOwnerDocument()
466: .createTextNode(curDay);
467: clonedOption.appendChild(optionTextNode);
468: if (i == Calendar.getInstance().get(
469: Calendar.DAY_OF_MONTH)) {
470: clonedOption.setAttribute("selected", "selected");
471: }
472:
473: // Do only a shallow copy of the option as we don't want the text child
474: // of the node option
475: cboToDay.appendChild(clonedOption);
476: }
477: cboToDay.removeChild(optToDay);
478: } catch (NullPointerException ex) {
479: } catch (Exception ex) {
480: this .writeDebugMsg("Error populating list of days: " + ex);
481: throw new ProjectManagementPresentationException(
482: "Error populating day list: ", ex);
483: }
484:
485: }
486:
487: private void fillToMonths(SearchHTML page)
488: throws ProjectManagementPresentationException {
489: HTMLSelectElement cboToMonth = page.getElementCboToMonth();
490: HTMLOptionElement optToMonth = page.getElementOptToMonth();
491: // Remove the dummy storyboard text to the prototype HTML
492: optToMonth.removeChild(optToMonth.getFirstChild());
493: try {
494: // set all months
495: HTMLOptionElement clonedOption = (HTMLOptionElement) optToMonth
496: .cloneNode(true);
497: Node optionTextNode;
498: /*
499: String all="All";
500: clonedOption.setValue("");
501: Node optionTextNode = clonedOption.getOwnerDocument().
502: createTextNode(all);
503: clonedOption.appendChild(optionTextNode);
504: cboToMonth.appendChild(clonedOption);
505: */
506:
507: for (int i = 1; i <= 12; i++) {
508: // Now populate the combo with months
509: // This algorithm is obscure because options
510: // are not normal HTML elements
511: // First populate the option value (the month database ID).
512: // Then append a text child as the option
513: // text, which is what is displayed as the text
514: // in each row of the select box
515: clonedOption = (HTMLOptionElement) optToMonth
516: .cloneNode(true);
517: String curMonth = String.valueOf(i);
518: clonedOption.setValue(curMonth);
519: optionTextNode = clonedOption.getOwnerDocument()
520: .createTextNode(curMonth);
521: clonedOption.appendChild(optionTextNode);
522: if (i == Calendar.getInstance().get(Calendar.MONTH) + 1) {
523: clonedOption.setAttribute("selected", "selected");
524: }
525: // Do only a shallow copy of the option as we don't want the text child
526: // of the node option
527: cboToMonth.appendChild(clonedOption);
528: }
529: cboToMonth.removeChild(optToMonth);
530: } catch (NullPointerException ex) {
531: } catch (Exception ex) {
532: this
533: .writeDebugMsg("Error populating list of months: "
534: + ex);
535: throw new ProjectManagementPresentationException(
536: "Error populating month list: ", ex);
537: }
538:
539: }
540:
541: private void fillToYears(SearchHTML page)
542: throws ProjectManagementPresentationException {
543: HTMLSelectElement cboToYear = page.getElementCboToYear();
544: HTMLOptionElement optToYear = page.getElementOptToYear();
545: // Remove the dummy storyboard text to the prototype HTML
546: optToYear.removeChild(optToYear.getFirstChild());
547: try {
548: // set all years
549: HTMLOptionElement clonedOption = (HTMLOptionElement) optToYear
550: .cloneNode(true);
551: Node optionTextNode;
552: /*
553: String all="All";
554: clonedOption.setValue("");
555: Node optionTextNode = clonedOption.getOwnerDocument().
556: createTextNode(all);
557: clonedOption.appendChild(optionTextNode);
558: cboToYear.appendChild(clonedOption);
559: */
560:
561: for (int i = 1998; i <= 2008; i++) {
562: // Now populate the combo with years
563: // This algorithm is obscure because options
564: // are not normal HTML elements
565: // First populate the option value (the year database ID).
566: // Then append a text child as the option
567: // text, which is what is displayed as the text
568: // in each row of the select box
569: clonedOption = (HTMLOptionElement) optToYear
570: .cloneNode(true);
571: String curYear = String.valueOf(i);
572: clonedOption.setValue(curYear);
573: optionTextNode = clonedOption.getOwnerDocument()
574: .createTextNode(curYear);
575: clonedOption.appendChild(optionTextNode);
576: if (i == Calendar.getInstance().get(Calendar.YEAR)) {
577: clonedOption.setAttribute("selected", "selected");
578: }
579: // Do only a shallow copy of the option as we don't want the text child
580: // of the node option
581: cboToYear.appendChild(clonedOption);
582: }
583: cboToYear.removeChild(optToYear);
584: } catch (NullPointerException ex) {
585: } catch (Exception ex) {
586: this .writeDebugMsg("Error populating list of years: " + ex);
587: throw new ProjectManagementPresentationException(
588: "Error populating year list: ", ex);
589: }
590:
591: }
592:
593: }
|