KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > table > TableHandler


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 /*
14  * ==================================================================== Copyright (c) 2003 TONBELLER
15  * AG. All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without modification, are permitted
18  * provided that the following conditions are met:
19  *
20  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
21  * and the following disclaimer.
22  *
23  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
24  * conditions and the following disclaimer in the documentation and/or other materials provided with
25  * the distribution.
26  *
27  * 3. The end-user documentation included with the redistribution, if any, must include the
28  * following acknowledgment: "This product includes software developed by TONBELLER AG
29  * (http://www.tonbeller.com)" Alternately, this acknowledgment may appear in the software itself,
30  * if and wherever such third-party acknowledgments normally appear.
31  *
32  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34  * DISCLAIMED. IN NO EVENT SHALL THE TON BELLER AG OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  * ====================================================================
41  *
42  *
43  */

44 package com.tonbeller.wcf.table;
45
46 import javax.servlet.http.HttpSession JavaDoc;
47 import org.apache.commons.beanutils.PropertyUtils;
48 import org.w3c.dom.Element JavaDoc;
49 import com.tonbeller.wcf.controller.RequestContext;
50 import com.tonbeller.wcf.form.FormComponent;
51 import com.tonbeller.wcf.form.NodeHandlerSupport;
52 import com.tonbeller.wcf.form.XmlComponent;
53 import com.tonbeller.wcf.selection.DefaultSelectionModel;
54 import com.tonbeller.wcf.selection.SelectionChangeListener;
55 import com.tonbeller.wcf.selection.SelectionModel;
56 import com.tonbeller.wcf.ui.XoplonCtrl;
57 import com.tonbeller.wcf.utils.DomUtils;
58
59 /**
60  * Manages a TableComponent inside a FormComponent
61  *
62  * @author av
63  */

64 public class TableHandler extends NodeHandlerSupport {
65
66   TableComponent table;
67
68   FormComponent formComp;
69
70   public void initialize(RequestContext context, XmlComponent xmlComp, Element JavaDoc element)
71       throws Exception JavaDoc {
72     super.initialize(context, xmlComp, element);
73     // must access the bean, so it has to be a FormComponent
74
formComp = (FormComponent) xmlComp;
75     String JavaDoc ref = XoplonCtrl.getModelReference(element);
76     Object JavaDoc bean = formComp.getBean();
77     TableModel tm = (TableModel) PropertyUtils.getProperty(bean, ref);
78     table = createTableComp(element.getAttribute("id"), formComp, tm);
79     DefaultSelectionModel dsm = new DefaultSelectionModel();
80     String JavaDoc selmode = element.getAttribute("selmode");
81     if ("href".equals(selmode))
82       dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF);
83     else if ("single".equals(selmode))
84       dsm.setMode(SelectionModel.SINGLE_SELECTION);
85     else if ("multi".equals(selmode))
86       dsm.setMode(SelectionModel.MULTIPLE_SELECTION);
87     else
88       dsm.setMode(SelectionModel.NO_SELECTION);
89     table.setSelectionModel(dsm);
90     if (tm instanceof SelectionChangeListener)
91         dsm.addSelectionListener((SelectionChangeListener) tm);
92     table.setClosable(false);
93     String JavaDoc border = element.getAttribute("border");
94     if (border.length() > 0)
95       table.setBorder(border);
96     String JavaDoc width = element.getAttribute("width");
97     if (width.length() > 0)
98       table.setWidth(width);
99     if("false".equals(element.getAttribute("colHeaders")))
100       table.setColHeaders(false);
101     // override renderId always
102
table.setRenderId(element.getAttribute("id"));
103     table.addFormListener(formComp);
104     formComp.addFormListener(table);
105     table.initialize(context);
106   }
107
108   protected TableComponent createTableComp(String JavaDoc id, FormComponent comp, TableModel tm) {
109     return new TableComponent(id, formComp, tm);
110   }
111
112   public void destroy(HttpSession JavaDoc session) throws Exception JavaDoc {
113     table.destroy(session);
114     super.destroy(session);
115   }
116
117   public void render(RequestContext context) throws Exception JavaDoc {
118     super.render(context);
119     Element JavaDoc parent = getElement();
120     DomUtils.removeChildElements(parent);
121     Element JavaDoc child = table.render(context, parent.getOwnerDocument());
122     parent.appendChild(child);
123   }
124
125   /**
126    * @return
127    */

128   public FormComponent getFormComp() {
129     return formComp;
130   }
131
132   /**
133    * @return
134    */

135   public TableComponent getTable() {
136     return table;
137   }
138 }
Popular Tags