Package net.sf.jasperreports.engine.design

Examples of net.sf.jasperreports.engine.design.JRDesignSubreport


        ? columnsGroup.getFooterSubreports()
        : columnsGroup.getHeaderSubreports();

    for (Iterator iterator = subreportsList.iterator(); iterator.hasNext();) {
      Subreport sr = (Subreport) iterator.next();
      JRDesignSubreport subreport = new JRDesignSubreport(new JRDesignStyle().getDefaultStyleProvider());

      //The data source
      int dataSourceOrigin = sr.getDatasource().getDataSourceOrigin();
      if (DJConstants.DATA_SOURCE_ORIGIN_USE_REPORT_CONNECTION == dataSourceOrigin){
        JRDesignExpression connectionExpression = ExpressionUtils.getReportConnectionExpression();
        subreport.setConnectionExpression(connectionExpression);
      } else if (DJConstants.DATA_SOURCE_TYPE_SQL_CONNECTION == sr.getDatasource().getDataSourceType()) {
        JRDesignExpression connectionExpression = ExpressionUtils.getConnectionExpression(sr.getDatasource());
        subreport.setConnectionExpression(connectionExpression);
      } else {
        JRDesignExpression dataSourceExpression = ExpressionUtils.getDataSourceExpression(sr.getDatasource());
        subreport.setDataSourceExpression(dataSourceExpression);
      }

//      int random_ = subReportRandom.nextInt();
      //the subreport design
      String paramname = sr.getReport().toString(); //TODO ensure this name is unique among all possible subreports
      ((DynamicJasperDesign)getDesign()).getParametersWithValues().put(paramname, sr.getReport());
      String expText = "("+JasperReport.class.getName()+")$P{REPORT_PARAMETERS_MAP}.get( \""+ paramname +"\" )";
      JRDesignExpression srExpression = ExpressionUtils.createExpression(expText, JasperReport.class);
      subreport.setExpression(srExpression );


      //set the parameters
      subreport.setParametersMapExpression(ExpressionUtils.getParameterExpression(sr));
      for (Iterator subreportParamsIter = sr.getParameters().iterator(); subreportParamsIter.hasNext();) {
        SubreportParameter srparam = (SubreportParameter) subreportParamsIter.next();
        JRDesignSubreportParameter subreportParameter = new JRDesignSubreportParameter();
        subreportParameter.setName(srparam.getName());
        JRExpression expression2 = ExpressionUtils.createExpression(getDesign(), srparam);
        subreportParameter.setExpression(expression2);
        try {
          subreport.addParameter(subreportParameter );
        } catch (JRException e) {
          log.error("Error registering parameter for subreport, there must be another parameter with the same name");
          throw new CoreException(e.getMessage(),e);
        }
      }

      //some other options (cosmetic)
      //subreport.setStretchType(JRDesignElement.STRETCH_TYPE_NO_STRETCH);
      int offset = LayoutUtils.findVerticalOffset(band);
      subreport.setY(offset);
      subreport.setX(-getReport().getOptions().getLeftMargin().intValue());
      subreport.setWidth(getReport().getOptions().getPage().getWidth());
      subreport.setHeight(SUBREPORT_DEFAULT_HEIGHT);
      subreport.setPositionType(JRElement.POSITION_TYPE_FLOAT);
      subreport.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);
      subreport.setRemoveLineWhenBlank(true); //No subreport, no reserved space

      band.setHeight(offset + subreport.getHeight());
     
      if (sr.getStyle() != null)
        applyStyleToElement(sr.getStyle(), subreport);

      //adding to the band
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.design.JRDesignSubreport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.