public Object createObject(Attributes atts) {
    JRDesignVariable variable = new JRDesignVariable();

    variable.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));

    if (atts.getValue(JRXmlConstants.ATTRIBUTE_class) != null) {
      variable.setValueClassName(atts.getValue(JRXmlConstants.ATTRIBUTE_class));
    }

    ResetTypeEnum resetType =
        ResetTypeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_resetType));
    if (resetType != null) {
      variable.setResetType(resetType);
    }

    String groupName = atts.getValue(JRXmlConstants.ATTRIBUTE_resetGroup);
    if (groupName != null) {
      JRDesignGroup group = new JRDesignGroup();
      group.setName(groupName);
      variable.setResetGroup(group);
    }

    IncrementTypeEnum incrementType =
        IncrementTypeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_incrementType));
    if (incrementType != null) {
      variable.setIncrementType(incrementType);
    }

    groupName = atts.getValue(JRXmlConstants.ATTRIBUTE_incrementGroup);
    if (groupName != null) {
      JRDesignGroup group = new JRDesignGroup();
      group.setName(groupName);
      variable.setIncrementGroup(group);
    }

    CalculationEnum calculation =
        CalculationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_calculation));
    if (calculation != null) {
      variable.setCalculation(calculation);
    }

    if (atts.getValue(JRXmlConstants.ATTRIBUTE_incrementerFactoryClass) != null) {
      variable.setIncrementerFactoryClassName(
          atts.getValue(JRXmlConstants.ATTRIBUTE_incrementerFactoryClass));
    }

    return variable;
  }
Esempio n. 2
0
  private JRVariable createHelperVariable(
      JRVariable variable, String nameSuffix, byte calculation) {
    JRDesignVariable helper = new JRDesignVariable();
    helper.setName(variable.getName() + nameSuffix);
    helper.setValueClassName(variable.getValueClassName());
    helper.setIncrementerFactoryClassName(variable.getIncrementerFactoryClassName());
    helper.setResetType(variable.getResetType());
    helper.setResetGroup(variable.getResetGroup());
    helper.setIncrementType(variable.getIncrementType());
    helper.setIncrementGroup(variable.getIncrementGroup());
    helper.setCalculation(calculation);
    helper.setSystemDefined(true);
    helper.setExpression(variable.getExpression());

    return helper;
  }
Esempio n. 3
0
  private JRVariable createDistinctCountHelperVariable(JRVariable variable) {
    JRDesignVariable helper = new JRDesignVariable();
    helper.setName(variable.getName() + "_DISTINCT_COUNT");
    helper.setValueClassName(variable.getValueClassName());
    helper.setIncrementerFactoryClassName(JRDistinctCountIncrementerFactory.class.getName());
    helper.setResetType(JRVariable.RESET_TYPE_REPORT);

    if (variable.getIncrementType() != JRVariable.RESET_TYPE_NONE)
      helper.setResetType(variable.getIncrementType());

    helper.setResetGroup(variable.getIncrementGroup());
    helper.setCalculation(JRVariable.CALCULATION_NOTHING);
    helper.setSystemDefined(true);
    helper.setExpression(variable.getExpression());

    return helper;
  }
  @Override
  public JRDesignElement createReportElement(JasperDesign jd) {
    JRDesignTextField element = (JRDesignTextField) super.createReportElement(jd);

    FieldPercentageDialog dialog = new FieldPercentageDialog(Misc.getMainFrame());
    dialog.setJasperDesign(jd);

    dialog.setVisible(true);
    if (dialog.getDialogResult() == JOptionPane.OK_OPTION) {
      JRField f = dialog.getSelectedField();
      ResetTypeEnum resetType = dialog.getSelectedResetTypeValue();
      JRGroup group = null;
      if (resetType == ResetTypeEnum.GROUP) {
        group = dialog.getSelectedGroup();
      }

      // Let's create the variable...

      JRDesignVariable variable = new JRDesignVariable();
      for (int i = 0; ; ++i) {
        String vname = f.getName() + "_SUM";
        if (i > 0) vname += "_" + i;

        if (jd.getVariablesMap().containsKey(vname)) {
          continue;
        }

        variable.setName(vname);
        break;
      }

      variable.setExpression(
          Misc.createExpression(f.getValueClassName(), "$F{" + f.getName() + "}"));
      variable.setValueClassName(f.getValueClassName());
      variable.setCalculation(CalculationEnum.SUM);
      variable.setResetType(resetType);
      if (resetType == ResetTypeEnum.GROUP) {
        variable.setResetGroup(group);
      }
      try {
        jd.addVariable(variable);
      } catch (JRException ex) {
        ex.printStackTrace();
      }

      ((JRDesignExpression) element.getExpression())
          .setText(
              "new Double( $F{"
                  + f.getName()
                  + "}.doubleValue() / $V{"
                  + variable.getName()
                  + "}.doubleValue() )");
      ((JRDesignExpression) element.getExpression()).setValueClassName("java.lang.Double");

      element.setPattern("#,##0.00%");
      setMatchingClassExpression(
          ((JRDesignExpression) element.getExpression()),
          ((JRDesignExpression) element.getExpression()).getValueClassName(),
          true);

      element.setEvaluationTime(EvaluationTimeEnum.AUTO);

      return element;
    }

    return null;
  }
  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;
  }