All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.dynamicreports.report.builder.column.Columns Maven / Gradle / Ivy

Go to download

DynamicReports is an open source Java reporting library based on JasperReports. It allows to create dynamic report designs and it doesn't need a visual report designer. You can very quickly create reports and produce documents that can be displayed, printed or exported into many popular formats such as PDF, Excel, Word and others.

There is a newer version: 6.20.1
Show newest version
/**
 * DynamicReports - Free Java reporting library for creating reports dynamically
 *
 * Copyright (C) 2010 - 2016 Ricardo Mariaca
 * http://www.dynamicreports.org
 *
 * This file is part of DynamicReports.
 *
 * DynamicReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DynamicReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with DynamicReports. If not, see .
 */

package net.sf.dynamicreports.report.builder.column;

import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.FieldBuilder;
import net.sf.dynamicreports.report.builder.component.ComponentBuilder;
import net.sf.dynamicreports.report.builder.expression.Expressions;
import net.sf.dynamicreports.report.definition.DRIField;
import net.sf.dynamicreports.report.definition.datatype.DRIDataType;
import net.sf.dynamicreports.report.definition.expression.DRIExpression;

import org.apache.commons.lang3.Validate;

/**
 * A set of methods of creating report columns.
* It is used to display data in a multi-column layout. * * @author Ricardo Mariaca ([email protected]) */ public class Columns { //text /** * Creates a new column.
* It is used to show values from the data source. * * @param fieldName the name of the field * @param valueClass the field value class * @return a column builder */ public static TextColumnBuilder column(String fieldName, Class valueClass) { return column(DynamicReports.field(fieldName, valueClass)); } /** * Creates a new column.
* It is used to show values from the data source. * * @param title the column title * @param fieldName the name of the field * @param valueClass the field value class * @return a column builder */ public static TextColumnBuilder column(String title, String fieldName, Class valueClass) { return column(title, DynamicReports.field(fieldName, valueClass)); } /** * Creates a new column.
* It is used to show values from the data source. * * @param fieldName the name of the field * @param dataType the field data type * @return a column builder */ public static TextColumnBuilder column(String fieldName, DRIDataType dataType) { Validate.notNull(dataType, "dataType must not be null"); TextColumnBuilder textColumnBuilder = new TextColumnBuilder(DynamicReports.field(fieldName, dataType.getValueClass())); textColumnBuilder.setDataType(dataType); return textColumnBuilder; } /** * Creates a new column.
* It is used to show values from the data source. * * @param title the column title * @param fieldName the name of the field * @param dataType the field data type * @return a column builder */ public static TextColumnBuilder column(String title, String fieldName, DRIDataType dataType) { TextColumnBuilder textColumnBuilder = column(fieldName, dataType); textColumnBuilder.setTitle(title); return textColumnBuilder; } /** * Creates a new column.
* It is used to show values from the data source. * * @param field the field definition * @return a column builder */ public static TextColumnBuilder column(FieldBuilder field) { TextColumnBuilder textColumnBuilder = new TextColumnBuilder(field); if (field.getField().getDataType() != null) { textColumnBuilder.setDataType(field.getField().getDataType()); } return textColumnBuilder; } /** * Creates a new column.
* It is used to show values from the data source. * * @param title the column title * @param field the field definition * @return a column builder */ public static TextColumnBuilder column(String title, FieldBuilder field) { return column(field).setTitle(title); } //expression /** * Creates a new expression column.
* The column values are defined in an expression. * * @param expression the value expression * @return a column builder */ public static TextColumnBuilder column(DRIExpression expression) { TextColumnBuilder textColumnBuilder = new TextColumnBuilder(expression); if (expression instanceof DRIField && ((DRIField) expression).getDataType() != null) { textColumnBuilder.setDataType(((DRIField) expression).getDataType()); } return textColumnBuilder; } /** * Creates a new expression column.
* The column values are defined in an expression. * * @param title the column title * @param expression the value expression * @return a column builder */ public static TextColumnBuilder column(String title, DRIExpression expression) { return column(expression).setTitle(title); } //percentage /** * Creates a new percentage column.
* It calculates percentage values from column values. * * @param column the column definition * @return a column builder */ public static PercentageColumnBuilder percentageColumn(ValueColumnBuilder column) { return new PercentageColumnBuilder(column); } /** * Creates a new percentage column.
* It calculates percentage values from column values. * * @param title the column title * @param column the column definition * @return a column builder */ public static PercentageColumnBuilder percentageColumn(String title, ValueColumnBuilder column) { return percentageColumn(column).setTitle(title); } /** * Creates a new percentage column.
* It calculates percentage values from field values. * * @param fieldName the name of the field * @param valueClass the field value class * @return a column builder */ public static PercentageColumnBuilder percentageColumn(String fieldName, Class valueClass) { return percentageColumn(DynamicReports.field(fieldName, valueClass)); } /** * Creates a new percentage column.
* It calculates percentage values from field values. * * @param title the column title * @param fieldName the name of the field * @param valueClass the field value class * @return a column builder */ public static PercentageColumnBuilder percentageColumn(String title, String fieldName, Class valueClass) { return percentageColumn(fieldName, valueClass).setTitle(title); } /** * Creates a new percentage column.
* It calculates percentage values from field values. * * @param field the field definition * @return a column builder */ public static PercentageColumnBuilder percentageColumn(FieldBuilder field) { return new PercentageColumnBuilder(field); } /** * Creates a new percentage column.
* It calculates percentage values from field values. * * @param title the column title * @param field the field definition * @return a column builder */ public static PercentageColumnBuilder percentageColumn(String title, FieldBuilder field) { return percentageColumn(field).setTitle(title); } /*public static PercentageColumnBuilder percentageColumn(DRISimpleExpression expression) { return new PercentageColumnBuilder(expression); } public static PercentageColumnBuilder percentageColumn(String title, DRISimpleExpression expression) { return percentageColumn(expression).setTitle(title); } */ //column row number /** * Creates a new row number column.
* It displays row numbers, the row number is reset on each new column. * * @return a column builder */ public static TextColumnBuilder columnRowNumberColumn() { return column(Expressions.columnRowNumber()); } /** * Creates a new row number column.
* It displays row numbers, the row number is reset on each new column. * * @param title the column title * @return a column builder */ public static TextColumnBuilder columnRowNumberColumn(String title) { return columnRowNumberColumn().setTitle(title); } //page row number /** * Creates a new row number column.
* It displays row numbers, the row number is reset on each new page. * * @return a column builder */ public static TextColumnBuilder pageRowNumberColumn() { return column(Expressions.pageRowNumber()); } /** * Creates a new row number column.
* It displays row numbers, the row number is reset on each new page. * * @param title the column title * @return a column builder */ public static TextColumnBuilder pageRowNumberColumn(String title) { return pageRowNumberColumn().setTitle(title); } //report row number /** * Creates a new row number column.
* It displays row numbers. * * @return a column builder */ public static TextColumnBuilder reportRowNumberColumn() { return column(Expressions.reportRowNumber()); } /** * Creates a new row number column.
* It displays row numbers. * * @param title the column title * @return a column builder */ public static TextColumnBuilder reportRowNumberColumn(String title) { return reportRowNumberColumn().setTitle(title); } //component /** * Creates a new component column.
* It is used to display custom components (e.g. images or complex content) in columns. * * @param component the component definition * @return a column builder */ public static ComponentColumnBuilder componentColumn(ComponentBuilder component) { Validate.notNull(component, "component must not be null"); return new ComponentColumnBuilder(component); } /** * Creates a new component column.
* It is used to display custom components (e.g. images or complex content) in columns. * * @param title the column title * @param component the component definition * @return a column builder */ public static ComponentColumnBuilder componentColumn(String title, ComponentBuilder component) { return componentColumn(component).setTitle(title); } //boolean /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param fieldName the name of the field * @return a column builder */ public static BooleanColumnBuilder booleanColumn(String fieldName) { return booleanColumn(DynamicReports.field(fieldName, Boolean.class)); } /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param title the column title * @param fieldName the name of the field * @return a column builder */ public static BooleanColumnBuilder booleanColumn(String title, String fieldName) { return booleanColumn(title, DynamicReports.field(fieldName, Boolean.class)); } /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param field the field definition * @return a column builder */ public static BooleanColumnBuilder booleanColumn(FieldBuilder field) { return new BooleanColumnBuilder(field); } /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param title the column title * @param field the field definition * @return a column builder */ public static BooleanColumnBuilder booleanColumn(String title, FieldBuilder field) { return booleanColumn(field).setTitle(title); } /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param expression the boolean value expression * @return a column builder */ public static BooleanColumnBuilder booleanColumn(DRIExpression expression) { return new BooleanColumnBuilder(expression); } /** * Creates a new boolean column.
* It shows a boolean value either as a text or as an image. * * @param title the column title * @param expression the boolean value expression * @return a column builder */ public static BooleanColumnBuilder booleanColumn(String title, DRIExpression expression) { return booleanColumn(expression).setTitle(title); } //empty column /** * Creates a new empty column.
* * @return a column builder */ public static TextColumnBuilder emptyColumn() { return emptyColumn(false, false); } /** * Creates a new empty column.
* * @param showTitle show column title * @param showDetailRows show detail rows * @return a column builder */ public static TextColumnBuilder emptyColumn(boolean showTitle, boolean showDetailRows) { TextColumnBuilder column = column(Expressions.text(null)); if (showTitle) { column.setTitle(""); } if (!showDetailRows) { column.setPrintWhenExpression(Expressions.value(false)); } return column; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy