1 6 7 package albel.tags.table.model; 8 9 import org.apache.commons.collections.collection.*; 10 import org.apache.commons.collections.*; 11 15 public class Table { 16 17 20 private java.util.List source; 21 22 25 private java.util.List columns=new java.util.ArrayList (); 26 27 30 private String id; 31 32 35 private TableState tableState=new TableState(); 36 37 40 private String sourceBeanClass; 41 42 45 private TableHandlers tableHandlers=new TableHandlers(this); 46 47 50 private NewRowColumns newRowColumns=new NewRowColumns(this); 51 52 55 private Keys keys; 56 57 60 private java.util.Locale locale=java.util.Locale.US; 61 62 63 private Table() { 64 } 65 66 67 public Table(String id) { 68 this.id=id; 69 keys=new Keys(this.id); 70 } 71 75 public java.util.List getSource() { 76 return this.source; 77 } 78 79 83 public void setSource(java.util.List source) { 84 this.source = source; 85 } 86 87 91 public java.util.List getColumns() { 92 return this.columns; 93 } 94 95 99 public void setColumns(java.util.List columns) { 100 this.columns = columns; 101 } 102 public boolean hasColumn(String 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 prop) 111 { 112 return (Column)CollectionUtils.find(columns, PredicateUtils.equalPredicate(new Column(this,prop))); 113 } 114 118 public String getId() { 119 return this.id; 120 } 121 122 126 public void setId(String id) { 127 this.id = id; 128 } 129 130 134 public TableState getTableState() 135 { 136 return this.tableState; 137 } 138 139 143 public void setTableState(TableState tableState) 144 { 145 this.tableState = tableState; 146 } 147 148 public void setCell(Cell newCell)throws TableTagException 149 { 150 Object 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 iex) 160 { 161 throw new TableTagException(iex); 162 } 163 } 164 public Cell getCell(Cell cell)throws TableTagException 165 { 166 Object bean=source.get(cell.getRow().getNumber()); 167 String val; 168 try 169 { 170 val=org.apache.commons.beanutils.BeanUtils. 171 getProperty( 172 bean, 173 cell.getColumn().getProperty()); 174 } 175 catch (Exception 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 col)throws TableTagException 182 { 183 if(row.getNumber()>=source.size()) 184 throw new TableTagException("Specified row "+row.getNumber()+" does not exists"); 185 Object bean=source.get(row.getNumber()); 186 String val; 187 try 188 { 189 val=org.apache.commons.beanutils.BeanUtils. 190 getProperty( 191 bean, 192 col); 193 } 194 catch (Exception iex) 195 { 196 throw new TableTagException(iex); 197 } 198 return new Cell(row,getColumn(col),val); 199 } 200 public Object getSourceBean(Row row) 201 { 202 return source.get(row.getNumber()); 203 } 204 public Object getSourceBean(int row) 205 { 206 return source.get(row); 207 } 208 public void insertCells(Cell cells[])throws TableTagException 209 { 210 try 211 { 212 Object 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 e) 221 { 222 throw new TableTagException(e); 223 } 224 } 225 226 230 public String getSourceBeanClass() 231 { 232 return this.sourceBeanClass; 233 } 234 235 239 public void setSourceBeanClass(String sourceBeanClass) 240 { 241 this.sourceBeanClass = sourceBeanClass; 242 } 243 244 248 public TableHandlers getTableHandlers() 249 { 250 return this.tableHandlers; 251 } 252 253 257 public void setTableHandlers(TableHandlers tableHandlers) 258 { 259 this.tableHandlers = tableHandlers; 260 } 261 262 266 public NewRowColumns getNewRowColumns() 267 { 268 return this.newRowColumns; 269 } 270 271 275 public void setNewRowColumns(NewRowColumns newRowColumns) 276 { 277 this.newRowColumns = newRowColumns; 278 } 279 280 284 public Keys getKeys() 285 { 286 return this.keys; 287 } 288 289 293 public void setKeys(Keys keys) 294 { 295 this.keys = keys; 296 } 297 298 302 public java.util.Locale getLocale() 303 { 304 return this.locale; 305 } 306 307 311 public void setLocale(java.util.Locale 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 |