Search in sources :

Example 26 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket in project dwoss by gg-net.

the class CustomerExporterTryout method main.

public static void main(String[] args) throws IOException, InterruptedException {
    CustomerGenerator gen = new CustomerGenerator();
    FileJacket fj = CustomerExporterOperation.toXls(IntStream.range(0, 40).mapToObj(i -> gen.makeOldCustomer()).collect(Collectors.toList()));
    Desktop.getDesktop().open(fj.toTemporaryFile());
    Thread.sleep(6000);
}
Also used : CustomerGenerator(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator) FileJacket(eu.ggnet.dwoss.util.FileJacket)

Example 27 with FileJacket

use of eu.ggnet.dwoss.util.FileJacket 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);
}
Also used : ArrayList(java.util.ArrayList) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) FileJacket(eu.ggnet.dwoss.util.FileJacket) Date(java.util.Date) STableColumn(eu.ggnet.lucidcalc.STableColumn) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) File(java.io.File) TableModel(javax.swing.table.TableModel)

Aggregations

FileJacket (eu.ggnet.dwoss.util.FileJacket)27 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)18 File (java.io.File)14 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)11 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)8 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)7 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)7 CSheet (eu.ggnet.lucidcalc.CSheet)7 STable (eu.ggnet.lucidcalc.STable)7 STableColumn (eu.ggnet.lucidcalc.STableColumn)7 STableModelList (eu.ggnet.lucidcalc.STableModelList)7 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)7 CFormat (eu.ggnet.lucidcalc.CFormat)6 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)5 CBorder (eu.ggnet.lucidcalc.CBorder)5 JExcelLucidCalcWriter (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)4 ArrayList (java.util.ArrayList)4 Inject (javax.inject.Inject)4 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)3