KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.tonbeller.wcf.table;
14
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.MissingResourceException JavaDoc;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20
21 import org.apache.log4j.Logger;
22 import org.w3c.dom.Document JavaDoc;
23
24 import com.tonbeller.wcf.component.Component;
25 import com.tonbeller.wcf.component.ComponentTag;
26 import com.tonbeller.wcf.controller.RequestContext;
27 import com.tonbeller.wcf.selection.DefaultSelectionModel;
28 import com.tonbeller.wcf.selection.SelectionModel;
29 import com.tonbeller.wcf.utils.ResourceLocator;
30 import com.tonbeller.wcf.utils.XmlUtils;
31
32 /**
33  * Created on 15.11.2002
34  *
35  * @author av
36  */

37 public class TableComponentTag extends ComponentTag {
38   
39   private static Logger logger = Logger.getLogger(TableComponentTag.class);
40   
41   String JavaDoc model = null;
42   String JavaDoc selmode = "multi";
43   boolean closable = true;
44   boolean pagable = true;
45   boolean sortable = true;
46   int pagesize = 10;
47   String JavaDoc editForm = null;
48   boolean editable = false;
49   boolean colHeaders = true;
50   
51   /**
52    * @see com.tonbeller.wcf.tags.UiComponentTag#createComponent()
53    */

54   public Component createComponent(RequestContext context) throws JspException JavaDoc {
55     try {
56       TableModel tm = EmptyTableModel.instance();
57       if (model != null) {
58         tm = (TableModel)context.getModelReference(model);
59         if (tm == null)
60           throw new JspException JavaDoc("table " + model + " not found");
61       }
62
63       String JavaDoc tableId = editForm == null ? id : id + ".table";
64       TableComponent tableComp = createTable(tableId, tm);
65       tableComp.setPageable(pagable);
66       tableComp.setSortable(sortable);
67       tableComp.setClosable(closable);
68       tableComp.setColHeaders(colHeaders);
69       
70       DefaultSelectionModel dsm = new DefaultSelectionModel();
71       if ("href".equals(selmode))
72         dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF);
73       else if ("single".equals(selmode))
74         dsm.setMode(SelectionModel.SINGLE_SELECTION);
75       else if ("multi".equals(selmode))
76         dsm.setMode(SelectionModel.MULTIPLE_SELECTION);
77       else
78         dsm.setMode(SelectionModel.NO_SELECTION);
79       tableComp.setSelectionModel(dsm);
80       tableComp.setPageSize(pagesize);
81       
82       if (editForm != null) {
83         // @DEPRECATED - use editable instead
84
URL JavaDoc url = ResourceLocator.getResource(context.getServletContext(), context.getLocale(), editForm);
85         Document JavaDoc doc = XmlUtils.parse(url);
86         TablePropertiesFormComponent formComp = new TablePropertiesFormComponent(id + ".form", null, doc, tableComp);
87         formComp.setVisible(false);
88         formComp.setCloseable(true);
89         return new EditableTableComponent(id, null, tableComp, formComp);
90       }
91       else if (editable)
92         return EditableTableComponent.instance(context, id, tableComp);
93       return tableComp;
94
95     } catch (MalformedURLException JavaDoc e) {
96       logger.error(id, e);
97       throw new JspException JavaDoc(e);
98     } catch (MissingResourceException JavaDoc e) {
99       logger.error(id, e);
100       throw new JspException JavaDoc(e);
101     }
102   }
103
104   protected TableComponent createTable(String JavaDoc tableId, TableModel tm) {
105     return new TableComponent(tableId, null, tm);
106   }
107
108   public void setModel(String JavaDoc model) {
109     this.model = model;
110   }
111
112   public void setSelmode(String JavaDoc string) {
113     selmode = string;
114   }
115
116   public void setClosable(boolean b) {
117     closable = b;
118   }
119
120   public void setPagable(boolean b) {
121     pagable = b;
122   }
123
124   public void setSortable(boolean b) {
125     sortable = b;
126   }
127
128   public void setPagesize(int i) {
129     pagesize = i;
130   }
131
132   public String JavaDoc getModel() {
133     return model;
134   }
135
136   public void setEditForm(String JavaDoc string) {
137     editForm = string;
138   }
139
140   public void setEditable(boolean editable) {
141     this.editable = editable;
142   }
143   
144   public boolean isColHeaders() {
145     return colHeaders;
146   }
147   
148   public void setColHeaders(boolean colHeaders) {
149     this.colHeaders = colHeaders;
150   }
151 }
152
Popular Tags