Package org.pentaho.jfreereport.castormodel.reportspec

Examples of org.pentaho.jfreereport.castormodel.reportspec.Field


    int totalWidth = reportSpec.getLeftMargin() + reportSpec.getRightMargin();
    List groupsList = new LinkedList();
    List details = new LinkedList();
    // leading spacer
    if ( spacerWidth > 0 ) {
      Field spacer = new Field();
      spacer.setName( "" ); //$NON-NLS-1$
      spacer.setDisplayName( "" ); //$NON-NLS-1$
      spacer.setType( Types.VARCHAR );
      spacer.setFormat( "" ); //$NON-NLS-1$
      spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
      spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
      spacer.setWidth( new BigDecimal( spacerWidth ) );
      spacer.setWidthLocked( true );
      totalWidth += spacerWidth;
      spacer.setExpression( "none" ); //$NON-NLS-1$
      spacer.setIsWidthPercent( false );
      spacer.setIsDetail( true );
      reportSpec.addField( spacer );
    }
    for ( int i = 0; i < colHeaders.length; i++ ) {
      // System.out.println("header [" + i + "] = " + colHeaders[i]);
      Class typeClass = null;
      for ( int j = 0; j < resultSet.getRowCount(); j++ ) {
        Object value = resultSet.getValueAt( j, i );
        if ( ( value != null ) && !value.toString().equals( "" ) ) { //$NON-NLS-1$
          typeClass = value.getClass();
        }
      }
      String columnName = colHeaders[i].toString();
      Field f = new Field();
      f.setName( columnName );
      f.setNullString( getNullString() );
      if ( isGroup( columnName ) ) {
        f.setDisplayName( getGroupLabel( columnName, i ) );
      } else if ( i < displayNames.length ) {
        f.setDisplayName( displayNames[i] );
      } else {
        f.setDisplayName( columnName );
      }
      f.setIsWidthPercent( false );
      f.setWidth( new BigDecimal( getWidth( columnName ) ) );
      f.setWidthLocked( true );
      f.setIsDetail( !isGroup( columnName ) );
      if ( f.getIsDetail() ) {
        details.add( f );
      } else {
        groupsList.add( f );
      }
      f.setBackgroundColor( "#FFFFFF" ); //$NON-NLS-1$
      f.setType( getType( typeClass ) );
      if ( ( itemHides == null ) || ( itemHides.length == 0 ) ) {
        f.setUseItemHide( getType( typeClass ) == Types.NUMERIC ? false : true );
      } else {
        f.setUseItemHide( useItemHide( columnName ) );
      }
      f.setVerticalAlignment( "middle" ); //$NON-NLS-1$
      f.setFormat( getColumnFormat( columnName ) );
      String alignment = getColumnAlignment( columnName );
      if ( alignment != null ) {
        f.setHorizontalAlignment( alignment );
      } else {
        if ( f.getIsDetail() && ( f.getType() == Types.NUMERIC ) ) {
          f.setHorizontalAlignment( "right" ); //$NON-NLS-1$
        }
      }
      if ( f.getIsDetail() && ( f.getType() == Types.NUMERIC ) ) {
        f.setExpression( "sum" ); //$NON-NLS-1$
      } else {
        f.setExpression( "none" ); //$NON-NLS-1$
      }
      f.setCalculateGroupTotals( createSubTotals );
      reportSpec.addField( f );
      if ( ( spacerWidth > 0 ) && f.getIsDetail() ) {
        // spacer
        Field spacer = new Field();
        spacer.setName( "" ); //$NON-NLS-1$
        spacer.setDisplayName( "" ); //$NON-NLS-1$
        spacer.setType( Types.VARCHAR );
        spacer.setFormat( "" ); //$NON-NLS-1$
        spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
        spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
        spacer.setWidth( new BigDecimal( spacerWidth ) );
        spacer.setWidthLocked( true );
        totalWidth += spacerWidth;
        spacer.setExpression( "none" ); //$NON-NLS-1$
        spacer.setIsWidthPercent( false );
        spacer.setIsDetail( true );
        reportSpec.addField( spacer );
      }
    }
    for ( int i = 0; i < details.size(); i++ ) {
      Field f = (Field) details.get( i );
      totalWidth += f.getWidth().intValue();
    }
    if ( createTotalColumn ) {
      Field f = new Field();
      f.setName( "TOTAL_COLUMN" ); //$NON-NLS-1$
      f.setDisplayName( totalColumnName );
      f.setType( Types.NUMERIC );
      f.setFormat( totalColumnFormat );
      f.setHorizontalAlignment( "right" ); //$NON-NLS-1$
      f.setVerticalAlignment( "middle" ); //$NON-NLS-1$
      f.setWidth( new BigDecimal( totalColumnWidth ) );
      f.setWidthLocked( true );
      f.setExpression( "sum" ); //$NON-NLS-1$
      f.setIsWidthPercent( false );
      f.setIsDetail( true );
      reportSpec.addField( f );
      totalWidth += totalColumnWidth;
      if ( spacerWidth > 0 ) {
        // spacer
        Field spacer = new Field();
        spacer.setName( "" ); //$NON-NLS-1$
        spacer.setDisplayName( "" ); //$NON-NLS-1$
        spacer.setType( Types.VARCHAR );
        spacer.setFormat( "" ); //$NON-NLS-1$
        spacer.setHorizontalAlignment( "right" ); //$NON-NLS-1$
        spacer.setVerticalAlignment( "middle" ); //$NON-NLS-1$
        spacer.setWidth( new BigDecimal( spacerWidth ) );
        spacer.setWidthLocked( true );
        totalWidth += spacerWidth;
        spacer.setExpression( "none" ); //$NON-NLS-1$
        spacer.setIsWidthPercent( false );
        spacer.setIsDetail( true );
        reportSpec.addField( spacer );
      }
    }
    try {
      reportSpec.setUseCustomPageFormat( true );
View Full Code Here

TOP

Related Classes of org.pentaho.jfreereport.castormodel.reportspec.Field

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.