001: package projectmanagement.presentation.payrates;
002:
003: import projectmanagement.presentation.*;
004: import projectmanagement.spec.timewage.*;
005: import projectmanagement.spec.project.*;
006:
007: import com.lutris.appserver.server.httpPresentation.*;
008: import org.enhydra.xml.xmlc.XMLObject;
009:
010: import org.w3c.dom.*;
011: import org.w3c.dom.html.*;
012:
013: /**
014: * Shows a list of pay rates to administer.
015: *
016: * @author Sasa Bojanic
017: * @version 1.0
018: */
019: public class Administering extends BasePO {
020:
021: /**
022: * Constants
023: */
024: private static String EMPLOYEE = "employee";
025: private static String PROJECT = "project";
026:
027: /**
028: * Superclass method override. Returns 2.
029: */
030: protected int getRequiredAuthLevel() {
031: return 2;
032: }
033:
034: /**
035: * Default event. Just show the page.
036: */
037: public XMLObject handleDefault() throws HttpPresentationException {
038:
039: AdministeringHTML page = new AdministeringHTML();
040: try {
041: String employee = this .getComms().request
042: .getParameter(EMPLOYEE);
043: if (employee != null && employee.length() == 0) {
044: employee = null;
045: }
046: String project = this .getComms().request
047: .getParameter(PROJECT);
048: if (project != null && project.length() == 0) {
049: project = null;
050: }
051:
052: String errorMsg = this .getSessionData()
053: .getAndClearUserMessage();
054: /*if(null != errorMsg) {
055: page.setTextLblErrorText(errorMsg);
056: } else {
057: page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
058: }*/
059:
060: PayRateManager payRateManager = PayRateManagerFactory
061: .getPayRateManager("projectmanagement.business.timewage.PayRateManagerImpl");
062: PayRate[] payRates = payRateManager
063: .getAllPayRatesForEmployeeProjectPair(employee,
064: project);
065:
066: // fetches the table element from HTML document
067: HTMLTableElement table = page.getElementTblPayRates();
068:
069: if (payRates != null) {
070: for (int i = 0; i < payRates.length; i++) {
071: // creating row in HTML table which describes table properties
072: HTMLTableRowElement htmlRE = createNewRow(page,
073: payRates[i]);
074: // appending row at the end of table
075: table.appendChild(htmlRE);
076: }
077: }
078:
079: //Remove template selection row from table
080: table.removeChild(page.getElementTemplateRow());
081:
082: /* Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
083: * We need to allow ProjectManagement_pres to be functional , response
084: * will be default HTML page
085: */
086: } catch (NullPointerException ex) {
087:
088: } catch (Exception ex) {
089: this .writeDebugMsg("Error populating list of pay rates: "
090: + ex);
091: throw new ProjectManagementPresentationException(
092: "Error getting list of pay rates: ", ex);
093: }
094:
095: // write out HTML
096: return page;
097: }
098:
099: /**
100: * Creates the new row of HTML table element, based on given parameters.
101: */
102: private HTMLTableRowElement createNewRow(
103: AdministeringHTML administeringHTML, PayRate payRate) {
104:
105: String payRateID = "";
106:
107: try {
108: payRateID = payRate.getHandle();
109: administeringHTML.setTextTxtEmployee(payRate.getEmployee()
110: .getFirstName()
111: + " " + payRate.getEmployee().getLastName());
112: administeringHTML.setTextTxtProject(payRate.getProject()
113: .getName());
114: administeringHTML.setTextTxtPayRate(String.valueOf(payRate
115: .getRate()));
116: administeringHTML.setTextTxtValidFrom(payRate
117: .getValidFrom().toString());
118: } catch (Exception ex) {
119: }
120:
121: // image to get details on pay rate
122: HTMLImageElement detailsImg = administeringHTML
123: .getElementImgDetails();
124: detailsImg.setName(payRateID);
125:
126: // image to modify pay rate information
127: HTMLImageElement modifyImg = administeringHTML
128: .getElementImgModify();
129: modifyImg.setName(payRateID);
130:
131: // image to delete pay rate
132: HTMLImageElement deleteImg = administeringHTML
133: .getElementImgDelete();
134: deleteImg.setName(payRateID);
135:
136: HTMLTableRowElement row = (HTMLTableRowElement) administeringHTML
137: .getElementTemplateRow().cloneNode(true);
138:
139: return row;
140: }
141:
142: }
|