/** * Registers the parameter for the value formatter for the given variable and puts it's * implementation in the parameters map. * * @param djVariable * @param variableName */ protected void registerValueFormatter(DJGroupVariable djVariable, String variableName) { if (djVariable.getValueFormatter() == null) { return; } JRDesignParameter dparam = new JRDesignParameter(); dparam.setName(variableName + "_vf"); // value formater suffix dparam.setValueClassName(DJValueFormatter.class.getName()); log.debug("Registering value formatter parameter for property " + dparam.getName()); try { getDjd().addParameter(dparam); } catch (JRException e) { throw new EntitiesRegistrationException(e.getMessage(), e); } getDjd().getParametersWithValues().put(dparam.getName(), djVariable.getValueFormatter()); }
protected void registerEntity(Entity entity) { DJGroupVariable columnsGroupVariable = (DJGroupVariable) entity; try { String name = this.getDjd().getName() + "_" + columnsGroupVariable .getColumnToApplyOperation() .getGroupVariableName(type, columnToGroupByProperty); columnsGroupVariable.setName(name); if (columnsGroupVariable.getValueExpression() == null) { JRDesignVariable jrVariable = (JRDesignVariable) transformEntity(entity); log.debug( "registering group variable " + jrVariable.getName() + " (" + jrVariable.getValueClassName() + ")"); getDjd().addVariable(jrVariable); registerValueFormatter(columnsGroupVariable, jrVariable.getName()); } else { registerCustomExpressionParameter( name + "_valueExpression", columnsGroupVariable.getValueExpression()); } if (columnsGroupVariable.getPrintWhenExpression() != null) { registerCustomExpressionParameter( name + "_printWhenExpression", columnsGroupVariable.getPrintWhenExpression()); } if (columnsGroupVariable.getLabel() != null && columnsGroupVariable.getLabel().getLabelExpression() != null) { registerCustomExpressionParameter( name + "_labelExpression", columnsGroupVariable.getLabel().getLabelExpression()); } } catch (JRException e) { throw new EntitiesRegistrationException(e.getMessage(), e); } }
protected Object transformEntity(Entity entity) { DJGroupVariable groupVariable = (DJGroupVariable) entity; AbstractColumn col = groupVariable.getColumnToApplyOperation(); String variableName = groupVariable.getName(); log.debug("transforming group variable " + variableName); DJCalculation op = groupVariable.getOperation(); JRDesignExpression expression = new JRDesignExpression(); // only variables from the last registered group are important now List groupsList = getDjd().getGroupsList(); JRDesignGroup registeredGroup = (JRDesignGroup) groupsList.get(groupsList.size() - 1); if (col instanceof ExpressionColumn && ((ExpressionColumn) col).getExpressionForCalculation() != null) { ExpressionColumn expcol = (ExpressionColumn) col; expression.setText(expcol.getTextForExpressionForCalculartion()); expression.setValueClassName(expcol.getExpressionForCalculation().getClassName()); } else if (col instanceof PercentageColumn) { PercentageColumn pcol = (PercentageColumn) col; expression.setText(pcol.getPercentageColumn().getTextForExpression()); expression.setValueClassName(pcol.getPercentageColumn().getValueClassNameForExpression()); DJGroup djgroup = groupVariable.getGroup(); registeredGroup = LayoutUtils.findParentJRGroup(djgroup, getDynamicReport(), getDjd(), getLayoutManager()); } else { if (col.getTextFormatter() != null) { PropertyColumn pcol = (PropertyColumn) col; expression.setText("$F{" + pcol.getColumnProperty().getProperty() + "}"); expression.setValueClassName(pcol.getColumnProperty().getValueClassName()); } else { expression.setText(col.getTextForExpression()); expression.setValueClassName(col.getValueClassNameForExpression()); } } JRDesignVariable variable = new JRDesignVariable(); variable.setExpression(expression); variable.setCalculation(CalculationEnum.getByValue(groupVariable.getOperation().getValue())); variable.setName(variableName); variable.setResetType(ResetTypeEnum.GROUP); variable.setResetGroup(registeredGroup); String valueClassName = col.getVariableClassName(op); String initialExpression = col.getInitialExpression(op); // if (DJCalculation.SYSTEM.equals(groupVariable.getOperation())){ // variable.setValueClassName(Object.class.getName()); // } else { // } variable.setValueClassName(valueClassName); if (initialExpression != null) { JRDesignExpression initialExp = new JRDesignExpression(); initialExp.setText(initialExpression); initialExp.setValueClassName(valueClassName); variable.setInitialValueExpression(initialExp); } return variable; }