KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > albel > tags > table > ColumnTag


1 package albel.tags.table;
2
3 import albel.tags.table.controll.Manager;
4 import albel.tags.table.model.Column;
5 import albel.tags.table.model.ColumnType;
6 import albel.tags.table.model.Table;
7 import albel.tags.table.model.TableTagException;
8 import albel.tags.table.utils.HttpSessionAttributesMap;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.jsp.JspException JavaDoc;
11 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
12
13 /**
14  * @author albel
15  *Column definition tag
16  */

17 public class ColumnTag extends BodyTagSupport JavaDoc
18 {
19     
20     public ColumnTag()
21     {
22         super();
23     }
24     
25     private String JavaDoc property;
26     
27     /**
28      * Holds value of property type.
29      */

30     private String JavaDoc type;
31     
32     /**
33      * Holds value of property width.
34      */

35     private int width;
36     
37     ////////////////////////////////////////////////////////////////
38
/// ///
39
/// User methods. ///
40
/// ///
41
/// Modify these methods to customize your tag handler. ///
42
/// ///
43
////////////////////////////////////////////////////////////////
44

45     
46     //
47
// methods called from doStartTag()
48
//
49
/**
50      *
51      * Fill in this method to perform other operations from doStartTag().
52      *
53      */

54     public void otherDoStartTagOperations()
55     {
56         
57         //
58
// TODO: code that performs other operations in doStartTag
59
// should be placed here.
60
// It will be called after initializing variables,
61
// finding the parent, setting IDREFs, etc, and
62
// before calling theBodyShouldBeEvaluated().
63
//
64
// For example, to print something out to the JSP, use the following:
65
//
66
// try {
67
// JspWriter out = pageContext.getOut();
68
// out.println("something");
69
// } catch (java.io.IOException ex) {
70
// // do something
71
// }
72
//
73
//
74

75         
76     }
77     
78     /**
79      *
80      * Fill in this method to determine if the tag body should be evaluated
81      * Called from doStartTag().
82      *
83      */

84     public boolean theBodyShouldBeEvaluated()
85     {
86         
87         //
88
// TODO: code that determines whether the body should be
89
// evaluated should be placed here.
90
// Called from the doStartTag() method.
91
//
92
return true;
93         
94     }
95     
96     
97     //
98
// methods called from doEndTag()
99
//
100
/**
101      *
102      * Fill in this method to perform other operations from doEndTag().
103      *
104      */

105     public void otherDoEndTagOperations()
106     {
107         
108         //
109
// TODO: code that performs other operations in doEndTag
110
// should be placed here.
111
// It will be called after initializing variables,
112
// finding the parent, setting IDREFs, etc, and
113
// before calling shouldEvaluateRestOfPageAfterEndTag().
114
//
115

116         
117     }
118     
119     /**
120      *
121      * Fill in this method to determine if the rest of the JSP page
122      * should be generated after this tag is finished.
123      * Called from doEndTag().
124      *
125      */

126     public boolean shouldEvaluateRestOfPageAfterEndTag()
127     {
128         
129         //
130
// TODO: code that determines whether the rest of the page
131
// should be evaluated after the tag is processed
132
// should be placed here.
133
// Called from the doEndTag() method.
134
//
135
return true;
136         
137     }
138     
139     
140     ////////////////////////////////////////////////////////////////
141
/// ///
142
/// Tag Handler interface methods. ///
143
/// ///
144
/// Do not modify these methods; instead, modify the ///
145
/// methods that they call. ///
146
/// ///
147
////////////////////////////////////////////////////////////////
148

149     
150     /**
151      * Dummy javadoc comment to get things started.
152      */

153     public int doStartTag() throws JspException JavaDoc
154     {
155         try
156         {
157             if(this.getParent() instanceof albel.tags.table.RowsTag)
158             {
159                 doContextRows();
160             }
161             else
162                 if(this.getParent() instanceof albel.tags.table.NewRowColumnsTag)
163                     doContextNewRow();
164         }
165         catch (TableTagException tex)
166         {
167             throw new JspException JavaDoc(tex);
168         }
169         return this.EVAL_BODY_INCLUDE;
170     }
171     /**
172      *Sets up columns displayable in table rows
173      */

174     private void doContextRows()throws TableTagException
175     {
176         HttpServletRequest JavaDoc request=(HttpServletRequest JavaDoc)pageContext.getRequest();
177         HttpSessionAttributesMap attrs=new HttpSessionAttributesMap(request.getSession());
178         TableTag tableTag=(TableTag)this.getParent().getParent();
179         Table table=Manager.getTable(attrs, tableTag.getId());
180         boolean has=table.hasColumn(getProperty());
181         if(!has)
182         {
183             Column col=new Column(table);
184             col.setProperty(getProperty());
185             col.setType(ColumnType.getInstance(getType()));
186             col.setWidth(getWidth());
187             table.addColumn(col);
188         }
189     }
190     /**
191      *Sets up columns displayable in new row block
192      */

193     private void doContextNewRow()throws TableTagException
194     {
195         HttpServletRequest JavaDoc request=(HttpServletRequest JavaDoc)pageContext.getRequest();
196         HttpSessionAttributesMap attrs=new HttpSessionAttributesMap(request.getSession());
197         TableTag tableTag=(TableTag)this.getParent().getParent();
198         Table table=Manager.getTable(attrs, tableTag.getId());
199         boolean has=table.getNewRowColumns().hasColumn(getProperty());
200         if(!has)
201         {
202             Column col=new Column(table);
203             col.setProperty(getProperty());
204             col.setType(ColumnType.getInstance(getType()));
205             col.setWidth(getWidth());
206             table.getNewRowColumns().addColumn(col);
207         }
208     }
209     
210     /**
211      * Dummy javadoc comment to get things started.
212      */

213     public int doEndTag() throws JspException JavaDoc
214     {
215         // Dummy body to get things going.
216
return EVAL_PAGE;
217     }
218     
219     /** Getter for property property.
220      * @return Value of property property.
221      *
222      */

223     public String JavaDoc getProperty()
224     {
225         return property;
226     }
227     
228     /** Setter for property property.
229      * @param property New value of property property.
230      *
231      */

232     public void setProperty(String JavaDoc property)
233     {
234         this.property=property;
235     }
236     
237     /**
238      * Getter for property type.
239      * @return Value of property type.
240      */

241     public String JavaDoc getType()
242     {
243         return this.type;
244     }
245     
246     /**
247      * Setter for property type.
248      * @param type New value of property type.
249      */

250     public void setType(String JavaDoc type)
251     {
252         this.type = type;
253     }
254     
255     /**
256      * Getter for property width.
257      * @return Value of property width.
258      */

259     public int getWidth()
260     {
261         return this.width;
262     }
263     
264     /**
265      * Setter for property width.
266      * @param width New value of property width.
267      */

268     public void setWidth(int width)
269     {
270         this.width = width;
271     }
272     
273 }
274
Popular Tags