for (int i = auxCols.length-1; i >= 0; i--) {
for (int j = auxRows.length-1; j >= 0; j--) {
DJCrosstabColumn crosstabColumn = auxCols[i];
DJCrosstabRow crosstabRow = auxRows[j];
JRDesignCrosstabCell cell = new JRDesignCrosstabCell();
cell.setWidth(new Integer(crosstabColumn.getWidth()));
cell.setHeight(new Integer(crosstabRow.getHeight()));
boolean isRowTotal = crosstabRow.getProperty() != null;
boolean isColumnTotal = crosstabColumn.getProperty() != null;
if (isColumnTotal)
cell.setColumnTotalGroup(crosstabColumn.getProperty().getProperty());
if (isRowTotal)
cell.setRowTotalGroup(crosstabRow.getProperty().getProperty());
JRDesignCellContents contents = new JRDesignCellContents();
int counter = 0;
int measureHeight = crosstabRow.getHeight() / djcross.getMeasures().size();
for (Iterator iterator = djcross.getMeasures().iterator(); iterator.hasNext(); counter++) {
DJCrosstabMeasure djmeasure = (DJCrosstabMeasure) iterator.next();
JRDesignTextField element = new JRDesignTextField();
element.setWidth(crosstabColumn.getWidth());
element.setHeight(measureHeight);
element.setY(counter*measureHeight);
JRDesignExpression measureExp = new JRDesignExpression();
// DJCrosstabMeasure measure = djcross.getMeasure(0);
boolean isTotalCell = isRowTotal || isColumnTotal;
if (!isTotalCell){
if (djmeasure.getValueFormatter()== null){
measureExp.setValueClassName(djmeasure.getProperty().getValueClassName());
measureExp.setText("$V{"+djmeasure.getProperty().getProperty()+"}");
} else {
measureExp.setText(djmeasure.getTextForValueFormatterExpression(djmeasure.getProperty().getProperty()));
measureExp.setValueClassName(djmeasure.getValueFormatter().getClassName());
}
} else { //is a total cell
if (djmeasure.getValueFormatter()== null){
if (djmeasure.getPrecalculatedTotalProvider() == null) {
measureExp.setValueClassName(djmeasure.getProperty().getValueClassName());
measureExp.setText("$V{"+djmeasure.getProperty().getProperty()+"}");
} else {
//call the precalculated value AND the value formatter
setExpressionForPrecalculatedTotalValue(auxCols, auxRows, measureExp, djmeasure, crosstabColumn, crosstabRow);
}
} else { //have value formatter
if (djmeasure.getPrecalculatedTotalProvider() == null) {
//no vlue formatter, no total provider
measureExp.setValueClassName(djmeasure.getProperty().getValueClassName());
measureExp.setText("$V{"+djmeasure.getProperty().getProperty()+"}");
} else {
//no vlue formatter, call the precalculated value only
// measureExp.setValueClass(String.class);
// measureExp.setText("\"VF, prec\"");
setExpressionForPrecalculatedTotalValue(auxCols, auxRows, measureExp, djmeasure, crosstabColumn, crosstabRow);
}
}
}
// measureExp.setValueClassName(djmeasure.getProperty().getValueClassName());
// measureExp.setText("$V{"+djmeasure.getProperty().getProperty()+"}");
element.setExpression(measureExp);
/**
* Is there any style for this object?
*/
/*if (crosstabRow.getProperty() == null && crosstabColumn.getProperty() == null && djmeasure.getStyle() != null ){
//this is the inner most cell
layoutManager.applyStyleToElement(djmeasure.getStyle() , element);
} else if (crosstabRow.getTotalStyle() != null) {
layoutManager.applyStyleToElement(crosstabRow.getTotalStyle(), element);
}
else if (crosstabColumn.getTotalStyle() != null) {
layoutManager.applyStyleToElement(crosstabColumn.getTotalStyle(), element);
}*/
//measure
if (!isRowTotal && !isColumnTotal && djmeasure.getStyle() != null ){
//this is the inner most cell
layoutManager.applyStyleToElement(djmeasure.getStyle() , element);
}
//row total only
if (isRowTotal && !isColumnTotal) {
Style style = getRowTotalStyle(crosstabRow);
if (style == null)
style = djmeasure.getStyle();
if (style != null)
layoutManager.applyStyleToElement(style, element);
}
//column total only
if (isColumnTotal && !isRowTotal) {
Style style = getColumnTotalStyle(crosstabColumn);
if (style == null)
style = djmeasure.getStyle();
if (style != null)
layoutManager.applyStyleToElement(style, element);
}
//row and column total
if (isRowTotal && isColumnTotal) {
Style style = getRowTotalStyle(crosstabRow);
if (style == null)
style = getColumnTotalStyle(crosstabColumn);
if (style == null)
style = djmeasure.getStyle();
if (style != null)
layoutManager.applyStyleToElement(style, element);
}
JRDesignStyle jrstyle = (JRDesignStyle) element.getStyle();
//FIXME this is a hack
if (jrstyle == null){
if (log.isDebugEnabled()){
log.warn("jrstyle is null in crosstab cell, this should have not happened.");
}
layoutManager.applyStyleToElement(null, element);
jrstyle = (JRDesignStyle)element.getStyle();
jrstyle.setBlankWhenNull(true);
}
JRDesignStyle alternateStyle = Utils.cloneStyle(jrstyle);
alternateStyle.setName(alternateStyle.getFontName() +"_for_column_" + djmeasure.getProperty());
alternateStyle.getConditionalStyleList().clear();
element.setStyle(alternateStyle);
try {
design.addStyle(alternateStyle);
} catch (JRException e) { /**e.printStackTrace(); //Already there, nothing to do **/}
setUpConditionStyles(alternateStyle, djmeasure, measureExp.getText());
if (djmeasure.getLink() != null){
String name = "cell_" + i + "_" + j + "_ope" + djmeasure.getOperation().getValue();
HyperLinkUtil.applyHyperLinkToElement((DynamicJasperDesign)this.design, djmeasure.getLink(), element, name);
}
contents.addElement(element);
}
contents.setMode(new Byte(Transparency.OPAQUE.getValue()));
applyBackgroundColor(contents,crosstabRow,crosstabColumn,i,j);
applyCellBorder(contents);
cell.setContents(contents);
try {
jrcross.addCell(cell);
} catch (JRException e) {