KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > customers > Administering


1 package projectmanagement.presentation.customers;
2
3 import projectmanagement.presentation.*;
4 import projectmanagement.spec.customer.*;
5 import com.lutris.appserver.server.httpPresentation.*;
6 import org.enhydra.xml.xmlc.XMLObject;
7
8 import org.w3c.dom.*;
9 import org.w3c.dom.html.*;
10
11 /**
12  * Shows a list of customers to administer.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

17 public class Administering extends BasePO {
18
19    /**
20     * Superclass method override. Returns 2.
21     */

22    protected int getRequiredAuthLevel() {
23       return 2;
24    }
25
26    /**
27     * Default event. Just show the page.
28     */

29    public XMLObject handleDefault()
30          throws HttpPresentationException {
31
32        AdministeringHTML page = new AdministeringHTML();
33
34       String JavaDoc errorMsg = this.getSessionData().getAndClearUserMessage();
35       /*if(null != errorMsg) {
36          page.setTextLblErrorText(errorMsg);
37       } else {
38          page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
39       }*/

40
41     
42       try {
43        
44      CustomerManager customerManager = CustomerManagerFactory.getCustomerManager("projectmanagement.business.customer.CustomerManagerImpl");
45      Customer[] customers = customerManager.getAllCustomers();
46
47   
48     // fetches the table element from HTML document
49
HTMLTableElement table = page.getElementTblCustomers();
50
51   
52       if (customers!=null) {
53             for (int i=0; i<customers.length; i++) {
54                // creating row in HTML table which describes table properties
55
HTMLTableRowElement htmlRE=createNewRow(page,customers[i]);
56                // appending row at the end of table
57
table.appendChild(htmlRE);
58             }
59          }
60       //Remove template selection row from table
61
table.removeChild(page.getElementTemplateRow());
62       
63       
64       /*
65  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
66  * We need to allow ProjectManagement_pres to be functional , response
67  * will be default HTML page
68  */

69       } catch(NullPointerException JavaDoc ex) {
70       } catch(Exception JavaDoc ex) {
71          this.writeDebugMsg("Error populating list of customers: " + ex);
72          throw new ProjectManagementPresentationException("Error getting list of customers: ", ex);
73       }
74
75       
76
77       // write out HTML
78
return page;
79    }
80
81    /**
82    * Creates the new row of HTML table element, based on given parameters.
83    */

84    private HTMLTableRowElement createNewRow(AdministeringHTML administeringHTML,
85          Customer customer) {
86
87       String JavaDoc customerID="";
88
89       try {
90          customerID=customer.getHandle();
91          administeringHTML.setTextTxtCompanyName(customer.getCompanyName());
92          administeringHTML.setTextTxtContactName(customer.getContactName());
93          administeringHTML.setTextTxtPhone(customer.getPhone());
94          administeringHTML.setTextTxtEmail(customer.getEmail());
95       } catch (Exception JavaDoc ex) {}
96
97       // image to get details on customer
98
HTMLImageElement detailsImg=administeringHTML.getElementImgDetails();
99       detailsImg.setName(customerID);
100
101       // image to modify customer information
102
HTMLImageElement modifyImg=administeringHTML.getElementImgModify();
103       modifyImg.setName(customerID);
104
105       // image to delete customer
106
HTMLImageElement deleteImg=administeringHTML.getElementImgDelete();
107       deleteImg.setName(customerID);
108
109       // image to show customer projects
110
HTMLImageElement projectImg=administeringHTML.getElementImgProject();
111       projectImg.setName(customerID);
112
113       HTMLTableRowElement row=(HTMLTableRowElement)administeringHTML.
114          getElementTemplateRow().cloneNode(true);
115
116       return row;
117    }
118
119 }
120
121
Popular Tags