001: package org.tigris.scarab.util;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: // JDK classes
050: import java.util.List;
051: import java.util.Date;
052:
053: /**
054: * A model that provides for an application to present a set of tabular data.
055: * Can be used along with a velocity macro to create a table.
056: *
057: *
058: * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
059: * @version $Id: TableModel.java 7502 2003-03-28 00:02:24Z jon $
060: */
061: public abstract class TableModel
062: // implements Retrievable
063: {
064: private List headings;
065: private List rows;
066:
067: public static boolean isDate(Object obj) {
068: return obj instanceof Date;
069: }
070:
071: public static boolean isHeading(Object obj) {
072: return obj instanceof Heading;
073: }
074:
075: public static boolean isColumnHeading(Object obj) {
076: return obj instanceof ColumnHeading;
077: }
078:
079: public abstract int getColumnCount();
080:
081: public abstract int getRowCount();
082:
083: public abstract Object getValueAt(int row, int column)
084: throws Exception;
085:
086: /**
087: * Get the value of headings.
088: * @return value of headings.
089: */
090: public List getHeadings() {
091: return headings;
092: }
093:
094: /**
095: * Set the value of headings.
096: * @param v Value to assign to headings.
097: */
098: public void setHeadings(List v) {
099: this .headings = v;
100: }
101:
102: /**
103: * Get the value of rows.
104: * @return value of rows.
105: */
106: public List getRows() {
107: return rows;
108: }
109:
110: /**
111: * Set the value of rows.
112: * @param v Value to assign to rows.
113: */
114: public void setRows(List v) {
115: this .rows = v;
116: }
117:
118: public class ColumnHeading extends Heading {
119: /**
120: * Get the value of colspan. This method only works with one
121: * level of subheadings
122: * @return value of colspan.
123: */
124: public int getColspan() {
125: int colspan = 1;
126: List subHeadings = getSubHeadings();
127: if (subHeadings != null && subHeadings.size() > 0) {
128: colspan = subHeadings.size();
129: }
130:
131: return colspan;
132: }
133: }
134:
135: public class RowHeading extends Heading {
136: /**
137: * Get the value of rowspan. This method only works with one
138: * level of subheadings
139: * @return value of rowspan.
140: */
141: public int getRowspan() {
142: int rowspan = 1;
143: List subHeadings = getSubHeadings();
144: if (subHeadings != null && subHeadings.size() > 0) {
145: rowspan = subHeadings.size();
146: }
147:
148: /*
149: while (subHeadings != null || subHeadings.size() > 0)
150: {
151: subHeadings = recurseHeadings
152:
153: int size = subHeadings.size();
154: for (int i=0; i<size; i++)
155: {
156: int max = 1;
157: List recurseHeadings =
158: ((Heading)subHeadings.get(i)).getSubHeadings();
159: while (recurseHeadings != null
160: && recurseHeadings.size() > 0)
161: {
162: int test = recurseHeadings.size();
163: max = (test > max) ? test : max;
164:
165: recurseHeadings
166: }
167:
168: }
169: }
170: */
171: return rowspan;
172: }
173: }
174:
175: public class Heading {
176: private List subHeadings;
177: private Object label;
178:
179: /**
180: * Get the value of rowspan.
181: * @return value of rowspan.
182: */
183: public int getRowspan() {
184: return 1;
185: }
186:
187: /**
188: * Get the value of colspan.
189: * @return value of colspan.
190: */
191: public int getColspan() {
192: return 1;
193: }
194:
195: /**
196: * Get the value of subHeadings.
197: * @return value of subHeadings.
198: */
199: public List getSubHeadings() {
200: return subHeadings;
201: }
202:
203: /**
204: * Set the value of subHeadings.
205: * @param v Value to assign to subHeadings.
206: */
207: public void setSubHeadings(List v) {
208: this .subHeadings = v;
209: }
210:
211: /**
212: * Get the value of label.
213: * @return value of label.
214: */
215: public Object getLabel() {
216: return label;
217: }
218:
219: /**
220: * Set the value of label.
221: * @param v Value to assign to label.
222: */
223: public void setLabel(Object v) {
224: this.label = v;
225: }
226: }
227: }
|