Package org.eclipse.birt.report.model.api

Examples of org.eclipse.birt.report.model.api.ReportDesignHandle


      // create a new session
      SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);

      // create a design or a template. Then create a report element
      // factory
      ReportDesignHandle design = session.createDesign();
      ElementFactory efactory = design.getElementFactory();

      // set my initial properties
      design.setDisplayName("my Test Report");
      design.setDescription("test");
      design.setIconFile("/templates/blank_report.gif");
      design.setFileName("c:/TEMP/sample.rptdesign");
      design.setDefaultUnits("in");
      design.setProperty("comments", "what not and what have you");

      SimpleMasterPageHandle element = efactory
          .newSimpleMasterPage("Page Master");
      DesignElementHandle footerText = efactory.newTextItem("test");
      footerText.setProperty("contentType", "html");
      footerText.setStringProperty("content", "MyTest");

      // Add in a simple page footer to our master page
      element.getPageFooter().add(footerText);

      // try to add the footer to the Master Page
      try {
        design.getMasterPages().add(element);
      } catch (ContentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (NameException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      // create a new grid element, and set the width to 100 percent of
      // the page design
      GridHandle grid = efactory.newGridItem(null, 1, 1);
      grid.setWidth("100%");

      // Add the grid to the report body
      design.getBody().add(grid);

      // create a new row
      RowHandle row = (RowHandle) grid.getRows().get(0);

      // Create a label and add it to the first cell.
      LabelHandle label = efactory.newLabel("Hello, world!");
      label.setText("Hello, World!");
      CellHandle cell = (CellHandle) row.getCells().get(0);
      cell.getContent().add(label);

      // save the report design
      design.saveAs("c:/TEMP/sample.rptdesign");
      design.close();
      System.out.println("Finished");
    } catch (ContentException e) {
      e.printStackTrace();
    } catch (NameException e) {
      e.printStackTrace();
View Full Code Here


          .openLibrary("C:/eclipse/GWTBirt/BIRTGwt/src/reports/DataSets.rptlibrary");
      dataSourceHandle = (DataSourceHandle) design.getDataSources()
          .get(0);

      // create a new report
      ReportDesignHandle reportDesign = session.createDesign();
      reportDesign.getDataSources().add(dataSourceHandle);

      // find the correct data set based on dateSetName
      int dataSetCount = 0;
      for (Iterator dataSetIterator = dataSetNames.iterator(); dataSetIterator
          .hasNext();) {
        dataSetCount++;
        String dataSetName = (String) dataSetIterator.next();

        for (Iterator i = design.getDataSets().iterator(); i.hasNext();) {
          DataSetHandle dataSetHandle = (DataSetHandle) i.next();

          if (dataSetHandle.getName().contains(dataSetName)) {

            dataSetHandleToUse = dataSetHandle;
            dataSetHandleToUse.setName(dataSetHandle.getName());
          }
        }

        // Add the current data set to the report design
        boolean hasDataSetAlready = false;
        for (Iterator i = reportDesign.getDataSets().iterator(); i
            .hasNext();) {
          DataSetHandle dataSetInReport = (DataSetHandle) i.next();

          if (dataSetInReport.getName().equalsIgnoreCase(
              dataSetHandleToUse.getName())) {
            hasDataSetAlready = true;
          }
        }
        if (hasDataSetAlready == false)
          reportDesign.getDataSets().add(dataSetHandleToUse);

        // get the columns from the selected dataset
        List columnList = new ArrayList();
        for (Iterator i = dataSetHandleToUse.getCachedMetaDataHandle()
            .getResultSet().iterator(); i.hasNext();) {
          ResultSetColumnHandle colInfo = (ResultSetColumnHandle) i
              .next();

          columnList.add(colInfo.getColumnName());
        }

        // create new table, set the data set
        TableHandle reportTable = reportDesign.getElementFactory()
            .newTableItem(
                "testTable" + dataSetHandleToUse.getName(),
                columnList.size());
        reportTable.setWidth("100%");
        reportTable.setDataSet(dataSetHandleToUse);

        // create a new detail row and add to the report
        RowHandle detailRow = (RowHandle) reportTable.getDetail()
            .get(0);
        int x = 0; // used to mark current column position

        // go through column list and create a new column binding,
        // otherwise data will not be populated into the report
        // Then add a new column to our row
        for (Iterator i = columnList.iterator(); i.hasNext();) {
          String columnName = (String) i.next();

          ComputedColumn computedColumn = StructureFactory
              .createComputedColumn();
          computedColumn.setName(columnName);
          computedColumn.setExpression("dataSetRow[\"" + columnName
              + "\"]");
          PropertyHandle computedSet = reportTable
              .getColumnBindings();
          reportTable.getColumnBindings().addItem(computedColumn);

          // add new data item and cell
          DataItemHandle data = reportDesign.getElementFactory()
              .newDataItem(columnName);
          data.setResultSetColumn(columnName);
          CellHandle cell = (CellHandle) detailRow.getCells().get(x);
          cell.getContent().add(data);
          x++; // advance position
        }

        // add the table to my report
        reportDesign.getBody().add(reportTable);
      }
      // set my initial properties for the new report
      reportDesign.setDisplayName(reportName);
      reportDesign.setDescription(reportName);
      reportDesign.setIconFile("/templates/blank_report.gif");
      reportDesign.setFileName("C:/eclipse/GWTBirt/BIRTGwt/src/reports/"
          + reportName + ".rptdesign");
      reportDesign.setDefaultUnits("in");
      reportDesign.setProperty("comments", reportName);
      reportDesign.setProperty(IReportRunnable.TITLE, reportName);

      // save report design
      reportDesign.saveAs("C:/eclipse/GWTBirt/BIRTGwt/src/reports/"
          + reportName + ".rptdesign");

      return true;
    } catch (ContentException e) {
      // TODO Auto-generated catch block
View Full Code Here

   * BIRT rptdesign file must match the name of an existing OpenReports
   * DataSource.
   */
  private void handleDataSourceOverrides(IReportRunnable design)
  {   
    ReportDesignHandle reportDH = (ReportDesignHandle) design.getDesignHandle();
   
    List<?> birtDataSources = reportDH.getAllDataSources();
   
    if (birtDataSources == null) return;
   
    Iterator<?> iterator = birtDataSources.iterator();
    while (iterator.hasNext())
View Full Code Here

      default:  parameter.put("DataType", "ANY"); break;
    }


    //Get report design and find default value, prompt text and data set expression using the DE API
    ReportDesignHandle reportHandle = ( ReportDesignHandle ) report.getDesignHandle( );
    ScalarParameterHandle parameterHandle = (ScalarParameterHandle) reportHandle.findParameter( scalar.getName() );
    parameter.put("Default Value", parameterHandle.getDefaultValue());
    parameter.put("Prompt Text", parameterHandle.getPromptText());
    parameter.put("Data Set Expression", parameterHandle.getValueExpr());

    if(scalar.getControlType() !=  IScalarParameterDefn.TEXT_BOX)
View Full Code Here

TOP

Related Classes of org.eclipse.birt.report.model.api.ReportDesignHandle

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.