001: package projectmanagement.presentation.customers;
002:
003: import projectmanagement.presentation.*;
004: import projectmanagement.spec.customer.*;
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 customers 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 2.
021: */
022: protected int getRequiredAuthLevel() {
023: return 2;
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()
034: .getAndClearUserMessage();
035: /*if(null != errorMsg) {
036: page.setTextLblErrorText(errorMsg);
037: } else {
038: page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
039: }*/
040:
041: try {
042:
043: CustomerManager customerManager = CustomerManagerFactory
044: .getCustomerManager("projectmanagement.business.customer.CustomerManagerImpl");
045: Customer[] customers = customerManager.getAllCustomers();
046:
047: // fetches the table element from HTML document
048: HTMLTableElement table = page.getElementTblCustomers();
049:
050: if (customers != null) {
051: for (int i = 0; i < customers.length; i++) {
052: // creating row in HTML table which describes table properties
053: HTMLTableRowElement htmlRE = createNewRow(page,
054: customers[i]);
055: // appending row at the end of table
056: table.appendChild(htmlRE);
057: }
058: }
059: //Remove template selection row from table
060: table.removeChild(page.getElementTemplateRow());
061:
062: /*
063: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
064: * We need to allow ProjectManagement_pres to be functional , response
065: * will be default HTML page
066: */
067: } catch (NullPointerException ex) {
068: } catch (Exception ex) {
069: this .writeDebugMsg("Error populating list of customers: "
070: + ex);
071: throw new ProjectManagementPresentationException(
072: "Error getting list of customers: ", ex);
073: }
074:
075: // write out HTML
076: return page;
077: }
078:
079: /**
080: * Creates the new row of HTML table element, based on given parameters.
081: */
082: private HTMLTableRowElement createNewRow(
083: AdministeringHTML administeringHTML, Customer customer) {
084:
085: String customerID = "";
086:
087: try {
088: customerID = customer.getHandle();
089: administeringHTML.setTextTxtCompanyName(customer
090: .getCompanyName());
091: administeringHTML.setTextTxtContactName(customer
092: .getContactName());
093: administeringHTML.setTextTxtPhone(customer.getPhone());
094: administeringHTML.setTextTxtEmail(customer.getEmail());
095: } catch (Exception ex) {
096: }
097:
098: // image to get details on customer
099: HTMLImageElement detailsImg = administeringHTML
100: .getElementImgDetails();
101: detailsImg.setName(customerID);
102:
103: // image to modify customer information
104: HTMLImageElement modifyImg = administeringHTML
105: .getElementImgModify();
106: modifyImg.setName(customerID);
107:
108: // image to delete customer
109: HTMLImageElement deleteImg = administeringHTML
110: .getElementImgDelete();
111: deleteImg.setName(customerID);
112:
113: // image to show customer projects
114: HTMLImageElement projectImg = administeringHTML
115: .getElementImgProject();
116: projectImg.setName(customerID);
117:
118: HTMLTableRowElement row = (HTMLTableRowElement) administeringHTML
119: .getElementTemplateRow().cloneNode(true);
120:
121: return row;
122: }
123:
124: }
|