001: package projectmanagement.presentation.employees;
002:
003: import projectmanagement.presentation.*;
004: import projectmanagement.spec.employee.*;
005: import com.lutris.appserver.server.httpPresentation.*;
006: import org.enhydra.xml.xmlc.XMLObject;
007:
008: import org.w3c.dom.*;
009: import org.w3c.dom.html.*;
010:
011: /**
012: * Shows a list of employees to administer.
013: *
014: * @author Sasa Bojanic
015: * @version 1.0
016: */
017: public class Administering extends BasePO {
018:
019: /**
020: * Superclass method override. Returns 1.
021: */
022: protected int getRequiredAuthLevel() {
023: return 1;
024: }
025:
026: /**
027: * Default event. Just show the page.
028: */
029: public XMLObject handleDefault() throws HttpPresentationException {
030:
031: AdministeringHTML page = new AdministeringHTML();
032:
033: /*String errorMsg = this.getSessionData().getAndClearUserMessage();
034: if(null != errorMsg) {
035: page.setTextLblErrorText(errorMsg);
036: } else {
037: page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
038: }*/
039:
040: try {
041: EmployeeManager employeeManager = EmployeeManagerFactory
042: .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
043: Employee[] employees = employeeManager.getAllEmployees();
044:
045: // fetches the table element from HTML document
046: HTMLTableElement table = page.getElementTblEmployees();
047:
048: if (employees != null) {
049: for (int i = 0; i < employees.length; i++) {
050: // creating row in HTML table which describes table properties
051: HTMLTableRowElement htmlRE = createNewRow(page,
052: employees[i]);
053: // appending row at the end of table
054: table.appendChild(htmlRE);
055:
056: }
057: }
058:
059: //Remove template selection row from table
060: table.removeChild(page.getElementTemplateRow());
061: /*
062: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
063: * We need to allow ProjectManagement_pres to be functional , response
064: * will be default HTML page
065: */
066: } catch (NullPointerException ex) {
067: } catch (Exception ex) {
068: this .writeDebugMsg("Error populating list of employees: "
069: + ex);
070: throw new ProjectManagementPresentationException(
071: "Error getting list of employees: ", ex);
072: }
073:
074: // write out HTML
075: return page;
076: }
077:
078: /**
079: * Creates the new row of HTML table element, based on given parameters.
080: */
081: private HTMLTableRowElement createNewRow(
082: AdministeringHTML administeringHTML, Employee employee) {
083:
084: String employeeID = "";
085:
086: try {
087: employeeID = employee.getHandle();
088: administeringHTML.setTextTxtFirstName(employee
089: .getFirstName());
090: administeringHTML
091: .setTextTxtLastName(employee.getLastName());
092: administeringHTML.setTextTxtMobilePhone(employee
093: .getMobilePhone());
094: administeringHTML.setTextTxtEmail(employee.getEmail());
095: } catch (Exception ex) {
096: }
097:
098: // image to get details on employee
099: HTMLImageElement detailsImg = administeringHTML
100: .getElementImgDetails();
101: detailsImg.setName(employeeID);
102:
103: // image to modify employee information
104: HTMLImageElement modifyImg = administeringHTML
105: .getElementImgModify();
106: modifyImg.setName(employeeID);
107:
108: // image to delete employee
109: HTMLImageElement deleteImg = administeringHTML
110: .getElementImgDelete();
111: deleteImg.setName(employeeID);
112:
113: HTMLTableRowElement row = (HTMLTableRowElement) administeringHTML
114: .getElementTemplateRow().cloneNode(true);
115:
116: return row;
117: }
118:
119: }
|