KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > albel > tags > table > model > Table


1 /*
2  * Table.java
3  *
4  * Created on Šeštadienis, 2004, Rugsėjo 4, 19.43
5  */

6
7 package albel.tags.table.model;
8
9 import org.apache.commons.collections.collection.*;
10 import org.apache.commons.collections.*;
11 /**
12  *
13  * @author Albertas Laurinav
14  */

15 public class Table {
16     
17     /**
18      * Holds value of property source.
19      */

20     private java.util.List JavaDoc source;
21     
22     /**
23      * Holds value of property columns.
24      */

25     private java.util.List JavaDoc columns=new java.util.ArrayList JavaDoc();
26     
27     /**
28      * Holds value of property id.
29      */

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

35      private TableState tableState=new TableState();
36      
37      /**
38       * Holds value of property sourceBeanClass.
39       */

40      private String JavaDoc sourceBeanClass;
41      
42      /**
43       * Holds value of property tableHandlers.
44       */

45      private TableHandlers tableHandlers=new TableHandlers(this);
46      
47      /**
48       * Holds value of property newRowColumns.
49       */

50      private NewRowColumns newRowColumns=new NewRowColumns(this);
51      
52      /**
53       * Holds value of property keys.
54       */

55      private Keys keys;
56      
57      /**
58       * Holds value of property locale.
59       */

60      private java.util.Locale JavaDoc locale=java.util.Locale.US;
61      
62     /** Creates a new instance of Table */
63     private Table() {
64     }
65     
66     /** Creates a new instance of Table */
67     public Table(String JavaDoc id) {
68         this.id=id;
69           keys=new Keys(this.id);
70     }
71     /**
72      * Getter for property source.
73      * @return Value of property source.
74      */

75     public java.util.List JavaDoc getSource() {
76         return this.source;
77     }
78     
79     /**
80      * Setter for property source.
81      * @param source New value of property source.
82      */

83     public void setSource(java.util.List JavaDoc source) {
84         this.source = source;
85     }
86     
87     /**
88      * Getter for property columns.
89      * @return Value of property columns.
90      */

91     public java.util.List JavaDoc getColumns() {
92         return this.columns;
93     }
94     
95     /**
96      * Setter for property columns.
97      * @param columns New value of property columns.
98      */

99     public void setColumns(java.util.List JavaDoc columns) {
100         this.columns = columns;
101     }
102     public boolean hasColumn(String JavaDoc name)
103     {
104         return CollectionUtils.exists(columns, PredicateUtils.equalPredicate(new Column(this,name)));
105     }
106     public void addColumn(Column col)
107     {
108         columns.add(col);
109     }
110     public Column getColumn(String JavaDoc prop)
111     {
112         return (Column)CollectionUtils.find(columns, PredicateUtils.equalPredicate(new Column(this,prop)));
113     }
114     /**
115      * Getter for property tableId.
116      * @return Value of property tableId.
117      */

118     public String JavaDoc getId() {
119         return this.id;
120     }
121     
122     /**
123      * Setter for property tableId.
124      * @param tableId New value of property tableId.
125      */

126     public void setId(String JavaDoc id) {
127         this.id = id;
128     }
129     
130      /**
131       * Getter for property tableState.
132       * @return Value of property tableState.
133       */

134      public TableState getTableState()
135      {
136          return this.tableState;
137      }
138      
139      /**
140       * Setter for property tableState.
141       * @param tableState New value of property tableState.
142       */

143      public void setTableState(TableState tableState)
144      {
145          this.tableState = tableState;
146      }
147      
148      public void setCell(Cell newCell)throws TableTagException
149      {
150          Object JavaDoc bean=source.get(newCell.getRow().getNumber());
151          try
152          {
153              org.apache.commons.beanutils.BeanUtils.
154                 setProperty(
155                     bean,
156                     newCell.getColumn().getProperty(),
157                     newCell.getValue());
158          }
159          catch (Exception JavaDoc iex)
160          {
161              throw new TableTagException(iex);
162          }
163      }
164      public Cell getCell(Cell cell)throws TableTagException
165      {
166          Object JavaDoc bean=source.get(cell.getRow().getNumber());
167                  String JavaDoc val;
168          try
169          {
170              val=org.apache.commons.beanutils.BeanUtils.
171                 getProperty(
172                     bean,
173                     cell.getColumn().getProperty());
174          }
175          catch (Exception JavaDoc iex)
176          {
177              throw new TableTagException(iex);
178          }
179                  return new Cell(cell.getRow(),cell.getColumn(),val);
180      }
181          public Cell getCell(Row row,String JavaDoc col)throws TableTagException
182          {
183              if(row.getNumber()>=source.size())
184                  throw new TableTagException("Specified row "+row.getNumber()+" does not exists");
185          Object JavaDoc bean=source.get(row.getNumber());
186                  String JavaDoc val;
187          try
188          {
189              val=org.apache.commons.beanutils.BeanUtils.
190                 getProperty(
191                     bean,
192                     col);
193          }
194          catch (Exception JavaDoc iex)
195          {
196              throw new TableTagException(iex);
197          }
198                  return new Cell(row,getColumn(col),val);
199          }
200      public Object JavaDoc getSourceBean(Row row)
201      {
202          return source.get(row.getNumber());
203      }
204      public Object JavaDoc getSourceBean(int row)
205      {
206          return source.get(row);
207      }
208      public void insertCells(Cell cells[])throws TableTagException
209      {
210          try
211          {
212              Object JavaDoc bean=Class.forName(getSourceBeanClass()).newInstance();
213              for(int i=0;i<cells.length;i++)
214              {
215                  org.apache.commons.beanutils.BeanUtils.
216                     setProperty(bean, cells[i].getColumn().getProperty(), cells[i].getValue());
217              }
218              source.add(bean);
219          }
220          catch (Exception JavaDoc e)
221          {
222              throw new TableTagException(e);
223          }
224      }
225      
226      /**
227       * Getter for property sourceBeanClass.
228       * @return Value of property sourceBeanClass.
229       */

230      public String JavaDoc getSourceBeanClass()
231      {
232          return this.sourceBeanClass;
233      }
234      
235      /**
236       * Setter for property sourceBeanClass.
237       * @param sourceBeanClass New value of property sourceBeanClass.
238       */

239      public void setSourceBeanClass(String JavaDoc sourceBeanClass)
240      {
241          this.sourceBeanClass = sourceBeanClass;
242      }
243      
244      /**
245       * Getter for property tableHandlers.
246       * @return Value of property tableHandlers.
247       */

248      public TableHandlers getTableHandlers()
249      {
250          return this.tableHandlers;
251      }
252      
253      /**
254       * Setter for property tableHandlers.
255       * @param tableHandlers New value of property tableHandlers.
256       */

257      public void setTableHandlers(TableHandlers tableHandlers)
258      {
259          this.tableHandlers = tableHandlers;
260      }
261      
262      /**
263       * Getter for property newRowColumns.
264       * @return Value of property newRowColumns.
265       */

266      public NewRowColumns getNewRowColumns()
267      {
268          return this.newRowColumns;
269      }
270      
271      /**
272       * Setter for property newRowColumns.
273       * @param newRowColumns New value of property newRowColumns.
274       */

275      public void setNewRowColumns(NewRowColumns newRowColumns)
276      {
277          this.newRowColumns = newRowColumns;
278      }
279      
280      /**
281       * Getter for property keys.
282       * @return Value of property keys.
283       */

284      public Keys getKeys()
285      {
286          return this.keys;
287      }
288      
289      /**
290       * Setter for property keys.
291       * @param keys New value of property keys.
292       */

293      public void setKeys(Keys keys)
294      {
295          this.keys = keys;
296      }
297      
298      /**
299       * Getter for property locale.
300       * @return Value of property locale.
301       */

302      public java.util.Locale JavaDoc getLocale()
303      {
304          return this.locale;
305      }
306      
307      /**
308       * Setter for property locale.
309       * @param locale New value of property locale.
310       */

311      public void setLocale(java.util.Locale JavaDoc locale)
312      {
313          this.locale = locale;
314      }
315      public void deleteRow(albel.tags.table.model.Row row)
316          throws TableTagException
317          {
318              if(source.size()<=row.getNumber())
319                  throw new TableTagException("Specified row "+row.getNumber()+" does not exists");
320                 source.remove(row.getNumber());
321          }
322 }
323
Popular Tags