* @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;
}