{
super(id, parameters);
this.course = (Course) parameters.get(Parameters.COURSE);
final WebResource export = new WebResource()
{
/**
*
*/
private static final long serialVersionUID = 7267314593474884211L;
@Override
public IResourceStream getResourceStream()
{
final List<InscriptionLine> inscriptions = new Vector<InscriptionLine>(
CollectionUtils.collect(ListeInscritsPanel.this.course.getInscriptions()
.getList(), InscriptionLine.TR_INSCRIPTION));
final HSSFWorkbook wb = new HSSFWorkbook();
final HSSFSheet sheet = wb.createSheet("Inscriptions");
sheet.setColumnWidth((short) 0, (short) 5500);
sheet.setColumnWidth((short) 1, (short) 6500);
sheet.setColumnWidth((short) 2, (short) 6500);
sheet.setColumnWidth((short) 3, (short) 2000);
sheet.setColumnWidth((short) 4, (short) 3500);
sheet.setColumnWidth((short) 5, (short) 6000);
sheet.setColumnWidth((short) 6, (short) 7000);
sheet.setColumnWidth((short) 7, (short) 3500);
sheet.setColumnWidth((short) 8, (short) 3500);
// --------- En-tête -----------
HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 18);
font.setFontName("Arial");
HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue(ListeInscritsPanel.this.course.getEvenement().getSaison().getNom()
+ " - " + ListeInscritsPanel.this.course.getEvenement().getNom() + " - "
+ ListeInscritsPanel.this.course.getNom() + " - Liste des inscriptions");
cell.setCellStyle(style);
// --------- Séparateur -----------
sheet.createRow((short) 1);
// --------- En-tête de colonne -------
font = wb.createFont();
font.setFontHeightInPoints((short) 10);
font.setFontName("Arial");
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style = wb.createCellStyle();
style.setFont(font);
row = sheet.createRow((short) 2);
row.createCell((short) 0).setCellValue("No. Licence");
row.createCell((short) 1).setCellValue("Nom");
row.createCell((short) 2).setCellValue("Prénom");
row.createCell((short) 3).setCellValue("Sexe");
row.createCell((short) 4).setCellValue("Date de naissance");
row.createCell((short) 5).setCellValue("Catégorie");
row.createCell((short) 6).setCellValue("Club");
row.createCell((short) 7).setCellValue("No. Plaque");
row.createCell((short) 8).setCellValue("No. Confirmation");
HSSFUtils.applyStyle(row, style);
// --------- Liste des inscrits -------
int i = 3;
for (final InscriptionLine line : inscriptions)
{
row = sheet.createRow((short) ++i);
row.createCell((short) 0).setCellValue(line.getLicence());
row.createCell((short) 1).setCellValue(line.getNom());
row.createCell((short) 2).setCellValue(line.getPrenom());
row.createCell((short) 3).setCellValue(line.getSexe());
cell = row.createCell((short) 4);
cell.setCellValue(line.getDateNaissance());
style = wb.createCellStyle();
style.setDataFormat(HSSFDataFormat
.getBuiltinFormat("m/d/yy"));
cell.setCellStyle(style);
row.createCell((short) 5).setCellValue(line.getCategorie());
row.createCell((short) 6).setCellValue(line.getClub());
row.createCell((short) 7).setCellValue(line.getNoPlaque());
row.createCell((short) 8).setCellValue(
line.getNoConfirmation());
}
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("inscriptions - "
+ ListeInscritsPanel.this.course.getEvenement().getEndroit() + ".xls");
}
};
export.setCacheable(false);
this.add(new ResourceLink("download", export));
}