use of eu.ggnet.lucidcalc.STableModelList in project dwoss by gg-net.
the class AuditReporterOperation method byRange.
/**
* Returns an audit report of units which are on a roll in transaction, but not yet rolled in.
* <p/>
* @return an audit report of units which are on a roll in transaction, but not yet rolled in.
*/
@Override
public FileJacket byRange(Date start, Date end) {
SubMonitor m = monitorFactory.newSubMonitor("AuditReport", 100);
m.message("loading UniqueUnits");
m.start();
List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uus.getEntityManager()).findBetweenInputDates(start, end);
m.worked(5, "preparing Document");
List<Object[]> rows = new ArrayList<>();
for (UniqueUnit uu : uniqueUnits) {
rows.add(new Object[] { uu.getRefurbishId(), uu.getProduct().getGroup().getNote(), uu.getProduct().getPartNo(), uu.getSerial(), ProductFormater.toName(uu.getProduct()), uu.getContractor(), UniqueUnitFormater.toSingleLineAccessories(uu), UniqueUnitFormater.toSingleLineComment(uu), UniqueUnitFormater.toSingleLineInternalComment(uu), uu.getCondition().getNote(), uu.getShipmentLabel(), uu.getProduct().getDescription(), "" });
}
CSheet sheet = new CSheet("Audit");
STable table = new STable();
table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
table.add(new STableColumn("SopoNr", 7)).add(new STableColumn("Warengruppe", 13)).add(new STableColumn("ArtikelNr", 15)).add(new STableColumn("Seriennummer", 27));
table.add(new STableColumn("Name", 30)).add(new STableColumn("Lieferant", 12)).add(new STableColumn("Zubehör", 50)).add(new STableColumn("Bemerkung", 50));
table.add(new STableColumn("Interne Bemerkung", 30)).add(new STableColumn("Zustand", 12)).add(new STableColumn("Shipment", 12)).add(new STableColumn("Beschreibung", 50));
table.setModel(new STableModelList(rows));
sheet.addBelow(table);
CCalcDocument document = new TempCalcDocument();
document.add(sheet);
FileJacket fj = new FileJacket("Audit", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document));
m.finish();
return fj;
}
use of eu.ggnet.lucidcalc.STableModelList in project dwoss by gg-net.
the class TableToExcelExporter method export.
/**
* Export a JTable view to a temporary .xls file.
* Supported cell renderer:<ol>
* </ol>
* <p/>
* @param table
* @param fileName
* @return
* @throws de.dw.util.UserInfoException
*/
public static FileJacket export(JTable table, String fileName) throws UserInfoException {
int visibleRowCount = table.getRowCount();
if (visibleRowCount < 1)
throw new UserInfoException("Die Tabelle enthält keine Daten.");
int columnCount = table.getColumnCount();
TableModel model = table.getModel();
List<Object[]> rows = new ArrayList<>();
for (int i = 0; i < visibleRowCount; i++) {
Object[] row = new Object[columnCount + 1];
for (int j = 0; j < columnCount; j++) {
// convert value of table to specified value
Object value = model.getValueAt(table.convertRowIndexToModel(i), table.convertColumnIndexToModel(j));
if (value instanceof Date) {
row[j] = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMANY).format(value);
continue;
}
// check for enums with getNote() or getName() via PojoUtil reflection
if (value instanceof Enum) {
try {
row[j] = PojoUtil.getValue("note", value);
continue;
} catch (RuntimeException e) {
try {
row[j] = PojoUtil.getValue("name", value);
continue;
} catch (RuntimeException ex) {
}
}
}
row[j] = value;
}
rows.add(row);
}
STable sTable = new STable();
for (int i = 0; i < columnCount; i++) {
int width = table.getColumnModel().getColumn(i).getWidth();
sTable.add(new STableColumn(table.getColumnName(i), width / 5));
}
sTable.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument(fileName);
cdoc.add(new CSheet("Sheet1", sTable));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
return new FileJacket(fileName, ".xls", file);
}
Aggregations