KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > TableModel


1 package org.tigris.scarab.util;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // JDK classes
50
import java.util.List JavaDoc;
51 import java.util.Date JavaDoc;
52
53
54 /**
55  * A model that provides for an application to present a set of tabular data.
56  * Can be used along with a velocity macro to create a table.
57  *
58  *
59  * @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
60  * @version $Id: TableModel.java 7502 2003-03-28 00:02:24Z jon $
61  */

62 public abstract class TableModel
63     // implements Retrievable
64
{
65     private List JavaDoc headings;
66     private List JavaDoc rows;
67     
68     public static boolean isDate(Object JavaDoc obj)
69     {
70         return obj instanceof Date JavaDoc;
71     }
72
73     public static boolean isHeading(Object JavaDoc obj)
74     {
75         return obj instanceof Heading;
76     }
77
78     public static boolean isColumnHeading(Object JavaDoc obj)
79     {
80         return obj instanceof ColumnHeading;
81     }
82
83     public abstract int getColumnCount();
84     public abstract int getRowCount();
85     public abstract Object JavaDoc getValueAt(int row, int column)
86     throws Exception JavaDoc;
87     
88     /**
89      * Get the value of headings.
90      * @return value of headings.
91      */

92     public List JavaDoc getHeadings()
93     {
94         return headings;
95     }
96     
97     /**
98      * Set the value of headings.
99      * @param v Value to assign to headings.
100      */

101     public void setHeadings(List JavaDoc v)
102     {
103         this.headings = v;
104     }
105     
106     /**
107      * Get the value of rows.
108      * @return value of rows.
109      */

110     public List JavaDoc getRows()
111     {
112         return rows;
113     }
114     
115     /**
116      * Set the value of rows.
117      * @param v Value to assign to rows.
118      */

119     public void setRows(List JavaDoc v)
120     {
121         this.rows = v;
122     }
123
124     public class ColumnHeading
125         extends Heading
126     {
127         /**
128          * Get the value of colspan. This method only works with one
129          * level of subheadings
130          * @return value of colspan.
131          */

132         public int getColspan()
133         {
134             int colspan = 1;
135             List JavaDoc subHeadings = getSubHeadings();
136             if (subHeadings != null && subHeadings.size() > 0)
137             {
138                 colspan = subHeadings.size();
139             }
140         
141             return colspan;
142         }
143     }
144
145     public class RowHeading
146         extends Heading
147     {
148         /**
149          * Get the value of rowspan. This method only works with one
150          * level of subheadings
151          * @return value of rowspan.
152          */

153         public int getRowspan()
154         {
155             int rowspan = 1;
156             List JavaDoc subHeadings = getSubHeadings();
157             if (subHeadings != null && subHeadings.size() > 0)
158             {
159                 rowspan = subHeadings.size();
160             }
161         
162             /*
163             while (subHeadings != null || subHeadings.size() > 0)
164             {
165                 subHeadings = recurseHeadings
166                 
167                 int size = subHeadings.size();
168                 for (int i=0; i<size; i++)
169                 {
170                     int max = 1;
171                     List recurseHeadings =
172                         ((Heading)subHeadings.get(i)).getSubHeadings();
173                     while (recurseHeadings != null
174                             && recurseHeadings.size() > 0)
175                     {
176                         int test = recurseHeadings.size();
177                         max = (test > max) ? test : max;
178
179                         recurseHeadings
180                     }
181                     
182                 }
183             }
184             */

185             return rowspan;
186         }
187     }
188
189     public class Heading
190     {
191         private List JavaDoc subHeadings;
192         private Object JavaDoc label;
193         
194         /**
195          * Get the value of rowspan.
196          * @return value of rowspan.
197          */

198         public int getRowspan()
199         {
200             return 1;
201         }
202
203         /**
204          * Get the value of colspan.
205          * @return value of colspan.
206          */

207         public int getColspan()
208         {
209             return 1;
210         }
211                         
212         /**
213          * Get the value of subHeadings.
214          * @return value of subHeadings.
215          */

216         public List JavaDoc getSubHeadings()
217         {
218             return subHeadings;
219         }
220         
221         /**
222          * Set the value of subHeadings.
223          * @param v Value to assign to subHeadings.
224          */

225         public void setSubHeadings(List JavaDoc v)
226         {
227             this.subHeadings = v;
228         }
229
230         /**
231          * Get the value of label.
232          * @return value of label.
233          */

234         public Object JavaDoc getLabel()
235         {
236             return label;
237         }
238         
239         /**
240          * Set the value of label.
241          * @param v Value to assign to label.
242          */

243         public void setLabel(Object JavaDoc v)
244         {
245             this.label = v;
246         }
247     }
248 }
249
Popular Tags