use of com.ramussoft.report.SerialNumber in project ramus by Vitaliy-Yakovchuk.
the class TablePrint method print.
@SuppressWarnings("unchecked")
@Override
public void print(Out out, Data data) {
if (!data.isPrintFor(attributes.get("printFor")))
return;
if (rows.next() != null) {
onNext();
String style = attributes.get("Style");
if (style == null)
style = "";
if (style.length() > 0)
style = " style=\"" + style + "\"";
String border;
if ((border = attributes.get("Border")) != null)
out.println("<table width =\"100%\" border=\"" + border + "\"" + style + ">");
else
out.println("<table width =\"100%\"" + style + ">");
out.println("<tr>");
for (ColumnHeader header : columnHeaders) {
header.print(out, data);
}
out.println("</tr>");
HashSet<TableRow> tableRows = new HashSet<TableRow>();
List<TableRow> tableRowsList = new ArrayList<TableRow>();
List<Index> orders = new ArrayList<Index>(columnHeaders.size());
int index = 0;
for (ColumnHeader header : columnHeaders) {
String order = header.attributes.get("ColumnOrderNumber");
if ((order != null) && (order.length() > 0)) {
try {
orders.add(new Index(index, Integer.parseInt(order)));
} catch (Exception e) {
throw new DataException("Error.wrongNumberFormatForOrderNumber", e.getLocalizedMessage(), order);
}
}
index++;
}
Collections.sort(orders);
int[] indexes = null;
if (orders.size() > 0) {
indexes = new int[orders.size()];
for (int i = 0; i < indexes.length; i++) indexes[i] = orders.get(i).index;
}
do {
List[] lists = new List[columnBodies.size()];
for (int i = 0; i < lists.length; i++) {
lists[i] = new ArrayList(4);
ColumnBody body = columnBodies.get(i);
body.setTablePrint(this);
body.print(lists[i], data);
}
TableRow holder = new TableRow(lists, indexes);
if (!tableRows.contains(holder)) {
tableRows.add(holder);
tableRowsList.add(holder);
}
} while (rows.next() != null);
TableRow[] tableRows2;
if (indexes != null) {
tableRows2 = new TableRow[tableRows.size()];
Iterator<TableRow> iterator = tableRows.iterator();
int j = 0;
while (iterator.hasNext()) {
tableRows2[j] = iterator.next();
j++;
}
Arrays.sort(tableRows2);
} else {
tableRows2 = tableRowsList.toArray(new TableRow[tableRowsList.size()]);
}
int number = 1;
for (TableRow tableRow : tableRows2) {
out.println("<tr>");
List[] lists = tableRow.lists;
for (int i = 0; i < lists.length; i++) {
out.print(columnBodies.get(i).getTdStartTag());
for (Object object : lists[i]) {
if (object instanceof SerialNumber)
((SerialNumber) object).setNumber(number);
out.print(object);
}
out.println("</td>");
}
out.println("</tr>");
number++;
}
out.println("</table>");
}
}
Aggregations