KickJava   Java API By Example, From Geeks To Geeks.

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


1 package projectmanagement.presentation.projects;
2
3 import projectmanagement.presentation.*;
4 import projectmanagement.spec.project.*;
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 projects to administer.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

17 public class Administering extends BasePO {
18
19    /**
20     * Constants
21     */

22    private static String JavaDoc CUSTOMER = "customer";
23
24    /**
25     * Superclass method override. Returns 2.
26     */

27    protected int getRequiredAuthLevel() {
28       return 2;
29    }
30
31    /**
32     * Default event. Just show the page.
33     */

34    public XMLObject handleDefault()
35          throws HttpPresentationException {
36
37        AdministeringHTML page = new AdministeringHTML();
38
39       String JavaDoc customer = this.getComms().request.getParameter(CUSTOMER);
40       if (customer!=null && customer.length()==0) {
41          customer=null;
42       }
43
44       String JavaDoc errorMsg = this.getSessionData().getAndClearUserMessage();
45       /*if(null != errorMsg) {
46          page.setTextLblErrorText(errorMsg);
47       } else {
48          page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
49       }*/

50
51      
52       try {
53 ProjectManager projectManager = ProjectManagerFactory.getProjectManager("projectmanagement.business.project.ProjectManagerImpl");
54  Project[] projects=projectManager.getAllProjectsForCustomer(customer);
55      
56      // fetches the table element from HTML document
57
HTMLTableElement table = page.getElementTblProjects();
58
59        
60          if (projects!=null) {
61             for (int i=0; i<projects.length; i++) {
62                // creating row in HTML table which describes table properties
63
HTMLTableRowElement htmlRE=createNewRow(page,projects[i]);
64                // appending row at the end of table
65
table.appendChild(htmlRE);
66             }
67          }
68       //Remove template selection row from table
69
table.removeChild(page.getElementTemplateRow());
70       
71 /* Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
72  * We need to allow ProjectManagement_pres to be functional , response
73  * will be default HTML page
74  */

75       } catch(NullPointerException JavaDoc ex) {
76        
77       } catch(Exception JavaDoc ex) {
78          this.writeDebugMsg("Error populating list of projects: " + ex);
79          throw new ProjectManagementPresentationException("Error getting list of projects: ", ex);
80       }
81
82      
83
84       // write out HTML
85
return page;
86    }
87
88    /**
89    * Creates the new row of HTML table element, based on given parameters.
90    */

91    private HTMLTableRowElement createNewRow(AdministeringHTML administeringHTML,
92          Project project) {
93
94       String JavaDoc projectID="";
95
96       try {
97          projectID=project.getHandle();
98          administeringHTML.setTextTxtCustomer(project.getCustomer().getCompanyName());
99          administeringHTML.setTextTxtName(project.getName());
100          administeringHTML.setTextTxtMoneyPerHour(String.valueOf(project.getMoneyPerHour()));
101       } catch (Exception JavaDoc ex) {}
102
103       // image to get details on project
104
HTMLImageElement detailsImg=administeringHTML.getElementImgDetails();
105       detailsImg.setName(projectID);
106
107       // image to modify project information
108
HTMLImageElement modifyImg=administeringHTML.getElementImgModify();
109       modifyImg.setName(projectID);
110
111       // image to delete project
112
HTMLImageElement deleteImg=administeringHTML.getElementImgDelete();
113       deleteImg.setName(projectID);
114
115       HTMLTableRowElement row=(HTMLTableRowElement)administeringHTML.
116          getElementTemplateRow().cloneNode(true);
117
118       return row;
119    }
120
121 }
122
123
Popular Tags