public ListePlaquePanel(final String id,
final Map<Parameters, Object> parameters)
{
super(id, parameters);
final Saison saison = (Saison) parameters.get(Parameters.SAISON);
final WebResource export = new WebResource()
{
/**
*
*/
private static final long serialVersionUID = -479972350710704177L;
@Override
public IResourceStream getResourceStream()
{
Collection<PlaqueAttribueeLine> plaques = new Vector<PlaqueAttribueeLine>();
plaques = CollectionUtils.collect(saison.getInfosSaison()
.getList(), PlaqueAttribueeLine.TR_INFO_SAISON);
final SelectionStrategy selectStr = new PlaqueFixeSelectionStrategy(
saison);
final OrderingStrategy orderStr = new ComparatorOrderingStrategy(
PlaqueAttribueeLine.COMP_NOM_PRENOM);
final HSSFWorkbook wb = new HSSFWorkbook();
int page = -1;
final HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 12);
font.setFontName("Arial");
final HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
for (final Iterator iter = saison.getCategoriesParticipantes()
.iterator(); iter.hasNext();)
{
final CategorieParticipante catPart = (CategorieParticipante) iter
.next();
Collection<PlaqueAttribueeLine> plaquesCategorie = selectStr
.getResult(catPart.getCategorie(), plaques);
plaquesCategorie = orderStr.getResult(plaquesCategorie);
final Iterator<PlaqueAttribueeLine> itLine = plaquesCategorie
.iterator();
while (itLine.hasNext())
{
final HSSFSheet sheet = this.newSheet(wb, catPart
.getCategorie(), ++page);
sheet.getPrintSetup().setLandscape(true);
for (short j = 0; j < ListePlaquePanel.COLONNES_PAR_PAGE; j++)
{
for (short k = 0; k < ListePlaquePanel.LIGNES_PAR_PAGE; k++)
{
if (itLine.hasNext())
{
final PlaqueAttribueeLine line = itLine
.next();
final HSSFRow row = sheet.createRow(this
.getIndexLigne(k));
HSSFCell cell = row
.createCell(this
.getIndexColonne(
j,
ListePlaquePanel.INDEX_PLAQUE));
cell.setCellValue(line.getPlaque());
cell.setCellStyle(style);
cell = row.createCell(this.getIndexColonne(
j, ListePlaquePanel.INDEX_NOM));
cell.setCellValue(line.getNomPrenom());
cell.setCellStyle(style);
cell = row
.createCell(this
.getIndexColonne(
j,
ListePlaquePanel.INDEX_COMMENTAIRE));
cell.setCellValue(line.getCommentaire());
cell.setCellStyle(style);
}
else
{
break;
}
}
}
}
page = -1;
}
try
{
FileOutputStream fileOut = new FileOutputStream("temp.xls");
wb.write(fileOut);
fileOut.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return new FileResourceStream(new File("temp.xls"));
}
@Override
protected void setHeaders(WebResponse response)
{
super.setHeaders(response);
response.setAttachmentHeader("Plaques - "
+ saison.getAnnee().toString() + ".xls");
}
private HSSFSheet newSheet(final HSSFWorkbook wb,
final Categorie categorie, final int page)
{