1 14 package org.compiere.report.core; 15 16 import java.io.*; 17 import java.util.*; 18 19 import org.compiere.util.*; 20 21 28 public class RModel implements Serializable 29 { 30 34 public RModel (String TableName) 35 { 36 m_data = new RModelData (TableName); 37 } 39 40 public static final String TABLE_ALIAS = "zz"; 41 42 public static final String FUNCTION_COUNT = "Count"; 43 44 public static final String FUNCTION_SUM = "Sum"; 45 46 47 private RModelData m_data = null; 48 49 private boolean m_editable = false; 50 51 52 53 54 59 protected RColumn getRColumn (int col) 60 { 61 if (col < 0 || col > m_data.cols.size()) 62 throw new java.lang.IllegalArgumentException ("Column invalid"); 63 return (RColumn)m_data.cols.get(col); 64 } 66 67 68 72 public void addColumn (RColumn rc) 73 { 74 m_data.cols.add(rc); 75 } 77 82 public void addColumn (RColumn rc, int index) 83 { 84 m_data.cols.add(index, rc); 85 } 87 90 public void addRow () 91 { 92 m_data.rows.add(new ArrayList()); 93 m_data.rowsMeta.add(null); 94 } 96 100 public void addRow (int index) 101 { 102 m_data.rows.add(index, new ArrayList()); 103 m_data.rowsMeta.add(index, null); 104 } 106 110 public void addRow (ArrayList l) 111 { 112 m_data.rows.add(l); 113 m_data.rowsMeta.add(null); 114 } 116 121 public void addRow (ArrayList l, int index) 122 { 123 m_data.rows.add(index, l); 124 m_data.rowsMeta.add(index, null); 125 } 127 132 public int getColumnIndex (String columnName) 133 { 134 if (columnName == null || columnName.length() == 0) 135 return -1; 136 for (int i = 0; i < m_data.cols.size(); i++) 138 { 139 RColumn rc = (RColumn)m_data.cols.get(i); 140 if (rc.getColSQL().startsWith(columnName)) 142 { 143 Log.trace(Log.l6_Database, "Column " + i + " " + rc.getColSQL() + " = " + columnName); 144 return i; 145 } 146 } 147 return -1; 148 } 150 151 152 158 public void query (Properties ctx, String whereClause, String orderClause) 159 { 160 m_data.query (ctx, whereClause, orderClause); 161 } 163 164 165 169 public void setGroup (String columnName) 170 { 171 setGroup(getColumnIndex(columnName)); 172 } 174 196 public void setGroup (int col) 197 { 198 Log.trace(Log.l4_Data, "RModel.setGroup col=" + col); 199 if (col < 0 || col >= m_data.cols.size()) 200 return; 201 Integer ii = new Integer (col); 202 if (!m_data.groups.contains(ii)) 203 m_data.groups.add(ii); 204 } 206 211 public boolean isGroupRow (int row) 212 { 213 return m_data.isGroupRow(row); 214 } 216 221 public void setFunction (String columnName, String function) 222 { 223 setFunction(getColumnIndex(columnName), function); 224 } 226 232 public void setFunction (int col, String function) 233 { 234 Log.trace(Log.l4_Data, "RModel.setFunction col=" + col + " - " + function); 235 if (col < 0 || col >= m_data.cols.size()) 236 return; 237 m_data.functions.put(new Integer (col), function); 238 } 240 241 243 247 public int getRowCount() 248 { 249 return m_data.rows.size(); 250 } 252 256 public int getColumnCount() 257 { 258 return m_data.cols.size(); 259 } 261 266 public String getColumnName (int col) 267 { 268 if (col < 0 || col > m_data.cols.size()) 269 throw new java.lang.IllegalArgumentException ("Column invalid"); 270 RColumn rc = (RColumn)m_data.cols.get(col); 271 if (rc != null) 272 return rc.getColHeader(); 273 return null; 274 } 276 281 public Class getColumnClass (int col) 282 { 283 if (col < 0 || col > m_data.cols.size()) 284 throw new java.lang.IllegalArgumentException ("Column invalid"); 285 RColumn rc = (RColumn)m_data.cols.get(col); 286 if (rc != null) 287 return rc.getColClass(); 288 return null; 289 } 291 297 public boolean isCellEditable (int rowIndex, int columnIndex) 298 { 299 return m_editable; 300 } 302 308 public Object getValueAt(int row, int col) 309 { 310 if (row < 0 || row >= m_data.rows.size()) 312 return null; 313 if (col < 0 || col >= m_data.cols.size()) 315 return null; 316 ArrayList myRow = (ArrayList)m_data.rows.get(row); 319 if (myRow == null || col >= myRow.size()) 321 return null; 322 return myRow.get(col); 324 } 326 333 public void setValueAt(Object aValue, int row, int col) 334 { 335 if (row < 0 || row >= m_data.rows.size()) 337 throw new IllegalArgumentException ("Row invalid"); 338 if (col < 0 || col >= m_data.cols.size()) 339 throw new IllegalArgumentException ("Column invalid"); 340 if (!isCellEditable(row, col)) 341 throw new IllegalArgumentException ("Cell is read only"); 342 ArrayList myRow = (ArrayList)m_data.rows.get(row); 344 if (myRow == null) 346 throw new java.lang.IllegalArgumentException ("Row not initialized"); 347 if (col >= myRow.size()) 349 while (myRow.size() < m_data.cols.size()) 350 myRow.add(null); 351 myRow.set(col, aValue); 353 } 355 360 public void moveRow (int from, int to) 361 { 362 m_data.moveRow(from,to); 363 } 365 366 367 368 } | Popular Tags |