KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > presentation > enhydrapim > Detail


1 /*
2  * Created on May 6, 2005
3  *
4  * TODO To change the template for this generated file go to Window -
5  * Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.pim.presentation.enhydrapim;
8
9 import java.math.BigDecimal JavaDoc;
10 import java.util.Vector JavaDoc;
11
12 import org.enhydra.pim.business.PersonManagerI;
13 import org.enhydra.pim.business.api.ContactI;
14 import org.enhydra.pim.business.api.PersonI;
15 import org.enhydra.pim.exception.EnhydraPimException;
16 import org.enhydra.pim.presentation.BasePO;
17 import org.enhydra.pim.spec.ContactManagerFactory;
18 import org.enhydra.pim.spec.PersonManagerFactory;
19 import org.enhydra.xml.xmlc.XMLObject;
20 import org.w3c.dom.Node JavaDoc;
21 import org.w3c.dom.html.HTMLTableRowElement;
22
23 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
24
25 /**
26  * @author P.Djojic May 6, 2005 1:21:35 AM
27  *
28  * TODO Detail
29  */

30 public class Detail extends BasePO {
31
32     final String JavaDoc ID_ITEMID = "itemId";
33
34     final String JavaDoc ID_FIRSTNAME = "firstName";
35
36     final String JavaDoc ID_LASTNAME = "lastName";
37
38     final String JavaDoc ID_NICKNAME = "nickName";
39
40     final String JavaDoc ID_NOTE = "note";
41
42     final String JavaDoc ID_CONTACTTYPE = "contactType";
43
44     final String JavaDoc ID_CONTACTDATA = "contactData";
45
46     /**
47      * @return
48      * @throws HttpPresentationException
49      * @throws EnhydraPimException
50      */

51     private PersonI getPersonId() throws HttpPresentationException, EnhydraPimException {
52         try {
53             String JavaDoc itemID = this.getComms().request.getParameter(ID_ITEMID);
54             PersonManagerI personManager = PersonManagerFactory.getPersonManager();
55             PersonI person = personManager.findPerson(new BigDecimal JavaDoc(itemID));
56             this.getSessionData().setPersonSessionHandle(person);
57             return person;
58         }catch(Exception JavaDoc ex) {
59             throw new EnhydraPimException(ex.getMessage());
60         }
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
67      */

68     public XMLObject handleDefault() throws HttpPresentationException {
69         
70         
71         
72         return showErrorPage("Unknown or Unexisting Person");
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
79      */

80     public XMLObject handleViewDetailItem() throws HttpPresentationException {
81         try {
82             PersonI person = null;
83             try {
84                 person = getPersonId();
85                 if (person != null) {
86                     return showPage(person);
87                 } else {
88                     return showErrorPage("Person don't exists");
89                 }
90             } catch (EnhydraPimException ex) {
91                 return showErrorPage("Unknown person");
92             }
93         } catch (Exception JavaDoc ex) {
94             return showErrorPage("Application Error :" + ex.getMessage());
95         }
96     }
97
98     /*
99      * (non-Javadoc)
100      *
101      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#loggedInUserRequired()
102      */

103     protected boolean loggedInUserRequired() {
104         // TODO Auto-generated method stub
105
return true;
106     }
107
108     /*
109      * (non-Javadoc)
110      *
111      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
112      */

113     public XMLObject showPage(PersonI person) throws HttpPresentationException {
114
115         DetailHTML page = (DetailHTML) myComms.xmlcFactory.create(DetailHTML.class);
116         try {
117
118             HTMLTableRowElement listRow = page.getElementDetailTableRow();
119             Node JavaDoc listTable = listRow.getParentNode();
120
121             // Remove ids to prevent duplicates
122
listRow.removeAttribute("id");
123
124             page.setTextFirstName(person.getFirstname());
125             page.setTextLastName(person.getLastname());
126             page.setTextNickName(person.getNicname());
127             page.setTextNote(person.getNote());
128             page.getElementUpdatePerson().setAttribute("onClick", "UpdateItem('" + person.getHandle().toString() + "')");
129             page.getElementDeletePerson().setAttribute("onClick", "DeleteItem('" + person.getHandle().toString() + "')");
130
131             // Get collection of Discs and loop through collection
132
// to add each disc as a row in the table.
133
Vector JavaDoc contacts = ContactManagerFactory.getContactManager().getPersonContacts(person);
134             for (int i = 0; i < contacts.size(); i++) {
135                 ContactI contact = (ContactI)contacts.elementAt(i);
136                 page.setTextContactType(contact.getContact_type().getContact_type());
137                 page.setTextContactData(contact.getContact_data());
138                 // Add a deep clone of the row to the DOM
139
Node JavaDoc clonedListRow = listRow.cloneNode(true);
140                 listTable.appendChild(clonedListRow);
141                 // Alternative way to insert nodes below
142
// insertBefore(newNode, oldNode);
143
// discTable.insertBefore(clonedNode, templateRow);
144
}
145
146             // Finally remove the template row and template select option
147
// from the page
148
listRow.getParentNode().removeChild(listRow);
149         } catch (Exception JavaDoc ex) {
150             return showErrorPage("Error during detail view:" + ex.getMessage());
151         }
152         // write out HTML
153
return page;
154
155     }
156
157 }
Popular Tags