Java Code Examples for org.pentaho.reporting.engine.classic.core.Element#setAttributeExpression()

The following examples show how to use org.pentaho.reporting.engine.classic.core.Element#setAttributeExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LineSparklineElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a new instance of the element. Override this method to return a concrete subclass of the element.
 *
 * @return the newly generated instance of the element.
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );

  element.setElementType( new LineSparklineType() );
  if ( getContent() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, getContent() );
  }
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }
  if ( spacing != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING, spacing );
  }
  return element;
}
 
Example 2
Source File: BarSparklineElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a new instance of the element. Override this method to return a concrete subclass of the element.
 *
 * @return the newly generated instance of the element.
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );

  element.setElementType( new BarSparklineType() );
  if ( getContent() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, getContent() );
  }
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }
  if ( spacing != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING, spacing );
  }

  return element;
}
 
Example 3
Source File: TextFieldElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates the text field element.
 *
 * @return the generated text field element
 * @see org.pentaho.reporting.engine.classic.core.elementfactory.ElementFactory#createElement()
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );
  element.setElementType( new TextFieldType() );
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }

  element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, getNullString() );
  return element;
}
 
Example 4
Source File: ContentFieldElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a new drawable field element based on the defined properties.
 *
 * @return the generated elements
 * @throws IllegalStateException
 *           if the field name is not set.
 * @see ElementFactory#createElement()
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );

  element.setElementType( new ContentFieldType() );
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }
  if ( getNullValue() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, getNullValue() );
  }
  if ( getBaseURL() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE, getBaseURL() );
  }
  return element;
}
 
Example 5
Source File: PieSparklineElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new instance of the element. Override this method to return a concrete subclass of the element.
 *
 * @return the newly generated instance of the element.
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );

  element.setElementType( new PieSparklineType() );
  if ( getContent() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, getContent() );
  }
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }
  if ( startAngle != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.START_ANGLE, startAngle );
  }
  if ( lowSlice != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.LOW_SLICE, lowSlice );
  }
  if ( mediumSlice != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.MEDIUM_SLICE, mediumSlice );
  }
  if ( highSlice != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.HIGH_SLICE, highSlice );
  }
  if ( counterClockwise != null ) {
    element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.COUNTER_CLOCKWISE,
        counterClockwise );
  }

  return element;
}
 
Example 6
Source File: KeepTogetherIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Element createFieldItem( final String text, final float width, final float height ) {
  final FormulaExpression fe = new FormulaExpression();
  fe.setFormula( "=[value]" );

  final Element label = new Element();
  label.setElementType( LabelType.INSTANCE );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height );
  label.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, fe );
  label.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, fe );
  return label;
}
 
Example 7
Source File: OrphanIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Element createFieldItem( final String text, final float width, final float height ) {
  final FormulaExpression fe = new FormulaExpression();
  fe.setFormula( "=[value]" );

  final Element label = new Element();
  label.setElementType( LabelType.INSTANCE );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height );
  label.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, fe );
  label.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, fe );
  return label;
}
 
Example 8
Source File: RelationalReportBuilder.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Element createFieldItem( final String fieldName, final Class aggregationType, final Color background ) {
  final ElementType targetType;
  if ( dataSchemaModel != null ) {
    final DataAttributeContext context = dataSchemaModel.getDataAttributeContext();
    final DataAttributes attributes = dataSchemaModel.getDataSchema().getAttributes( fieldName );
    targetType = AutoGeneratorUtility.createFieldType( attributes, context );
  } else {
    targetType = TextFieldType.INSTANCE;
  }

  final Element element = new Element();
  element.setAttributeExpression( "test-run", "test-value", new CopyValueAsTextExpression( fieldName ) );
  element.setElementType( targetType );
  element.getElementType().configureDesignTimeDefaults( element, Locale.getDefault() );
  element.getStyle().setStyleProperty( ElementStyleKeys.BACKGROUND_COLOR, background );

  if ( targetType instanceof NumberFieldType ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FORMAT_STRING, "0.00;-0.00" );
  }

  element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, fieldName );
  element.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 80f );
  element.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
  element.setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.AGGREGATION_TYPE, aggregationType );
  element.setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_STYLING, Boolean.FALSE );
  return element;
}
 
Example 9
Source File: BarcodeElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates a new instance of the element. Override this method to return a concrete subclass of the element.
 *
 * @return the newly generated instance of the element.
 */
public Element createElement() {
  final Element element = new Element();
  applyElementName( element );
  applyStyle( element.getStyle() );

  element.setElementType( new SimpleBarcodesType() );
  if ( getContent() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, getContent() );
  }
  if ( getFieldname() != null ) {
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
  }
  if ( getFormula() != null ) {
    final FormulaExpression formulaExpression = new FormulaExpression();
    formulaExpression.setFormula( getFormula() );
    element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
  }

  if ( getType() != null ) {
    element.setAttribute( SimpleBarcodesAttributeNames.NAMESPACE, SimpleBarcodesAttributeNames.TYPE_ATTRIBUTE,
        getType() );
  }
  if ( getChecksum() != null ) {
    element.setAttribute( SimpleBarcodesAttributeNames.NAMESPACE, SimpleBarcodesAttributeNames.CHECKSUM_ATTRIBUTE,
        getChecksum() );
  }
  if ( barWidth != null ) {
    element.setAttribute( SimpleBarcodesAttributeNames.NAMESPACE, SimpleBarcodesAttributeNames.BAR_WIDTH_ATTRIBUTE,
        barWidth );
  }
  if ( barHeight != null ) {
    element.setAttribute( SimpleBarcodesAttributeNames.NAMESPACE, SimpleBarcodesAttributeNames.BAR_HEIGHT_ATTRIBUTE,
        barHeight );
  }
  if ( showText != null ) {
    element.setAttribute( SimpleBarcodesAttributeNames.NAMESPACE, SimpleBarcodesAttributeNames.SHOW_TEXT_ATTRIBUTE,
        showText );
  }

  return element;
}
 
Example 10
Source File: NumberFieldElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates the number text element based on the defined settings. Undefined properties will not be set in the
 * generated element.
 *
 * @return the generated numberic text element
 * @see org.pentaho.reporting.engine.classic.core.elementfactory.ElementFactory#createElement()
 */
public Element createElement() {
  final Element element = new Element();

  if ( format instanceof DecimalFormat || format == null ) {
    element.setElementType( new NumberFieldType() );
    if ( getFieldname() != null ) {
      element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
    }
    if ( getFormula() != null ) {
      final FormulaExpression formulaExpression = new FormulaExpression();
      formulaExpression.setFormula( getFormula() );
      element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
    }
    if ( format != null ) {
      final DecimalFormat decimalFormat = (DecimalFormat) format;
      final String formatString = decimalFormat.toPattern();
      element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FORMAT_STRING, formatString );
    }
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, getNullString() );
  } else {
    final NumberFormatFilter dataSource = new NumberFormatFilter();
    if ( format != null ) {
      dataSource.setFormatter( format );
    }
    final DataRowDataSource dds = new DataRowDataSource();
    if ( getFormula() != null ) {
      dds.setFormula( getFormula() );
    } else {
      dds.setDataSourceColumnName( getFieldname() );
    }

    dataSource.setDataSource( dds );
    if ( getNullString() != null ) {
      dataSource.setNullValue( getNullString() );
    }
    element.setDataSource( dataSource );
  }

  applyElementName( element );
  applyStyle( element.getStyle() );
  element.getStyle().setStyleProperty( ElementStyleKeys.EXCEL_DATA_FORMAT_STRING, getExcelCellFormat() );
  return element;
}
 
Example 11
Source File: DateFieldElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Creates the date text element based on the defined settings. Undefined properties will not be set in the generated
 * element.
 *
 * @return the generated date text element
 * @see org.pentaho.reporting.engine.classic.core.elementfactory.ElementFactory#createElement()
 */
public Element createElement() {
  final Element element = new Element();
  if ( format instanceof SimpleDateFormat || format == null ) {
    element.setElementType( new DateFieldType() );
    if ( getFieldname() != null ) {
      element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname() );
    }
    if ( getFormula() != null ) {
      final FormulaExpression formulaExpression = new FormulaExpression();
      formulaExpression.setFormula( getFormula() );
      element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression );
    }
    if ( format != null ) {
      final SimpleDateFormat simpleDateFormat = (SimpleDateFormat) format;
      final String formatString = simpleDateFormat.toPattern();
      element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FORMAT_STRING, formatString );
    }
    element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, getNullString() );
  } else {
    element.setElementType( new LegacyType() );
    final DateFormatFilter dataSource = new DateFormatFilter();
    if ( format != null ) {
      dataSource.setFormatter( format );
    }

    final DataRowDataSource dds = new DataRowDataSource();
    if ( getFormula() != null ) {
      dds.setFormula( getFormula() );
    } else {
      dds.setDataSourceColumnName( getFieldname() );
    }

    dataSource.setDataSource( dds );
    if ( getNullString() != null ) {
      dataSource.setNullValue( getNullString() );
    }
    element.setDataSource( dataSource );
  }

  applyElementName( element );
  applyStyle( element.getStyle() );
  element.getStyle().setStyleProperty( ElementStyleKeys.EXCEL_DATA_FORMAT_STRING, getExcelCellFormat() );

  return element;
}