Advertisement
justyb11

Simple Pentaho TableModel

Feb 19th, 2015
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.10 KB | None | 0 0
  1. import java.util.Calendar;
  2. import java.util.Date;
  3. import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
  4.  
  5. //This creates the table model that will be passed to the report.
  6. String[] columnNames = ["Date Value"];
  7. Class[] columnTypes = [Date.class];
  8. def myTable = new TypedTableModel(columnNames, columnTypes);
  9.  
  10. //This grabs the start date from the report
  11. def startDate = dataRow.get("start_date");
  12.  
  13. //whenever you use dataRow, always follow it up with a check for null
  14. if (startDate == null)
  15.     //If null, return a blank table.
  16.     return myTable;
  17.  
  18. //Create a calendar, it is easier to manipulate than the Date class.
  19. def cal = Calendar.getInstance();
  20. //Set the calendar to whatever is in our start date.
  21. cal.setTime(startDate);
  22.  
  23. for(int i = 0; i < 5; i++) {
  24.     //This adds seven days to the calendar
  25.     cal.add(Calendar.DAY_OF_MONTH, 7);
  26.     //This creates a new insertable object from our calendar
  27.     Object [] insertValue = [cal.getTime()];
  28.     //This inserts the insertable object into the table model.
  29.     myTable.addRow(insertValue);
  30. }
  31.  
  32. //send the table model back to the report.
  33. return myTable;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement