View Javadoc

1   /*
2    * DynamicJasper: A library for creating reports dynamically by specifying
3    * columns, groups, styles, etc. at runtime. It also saves a lot of development
4    * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
5    *
6    * Copyright (C) 2008  FDV Solutions (http://www.fdvsolutions.com)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   *
11   * License as published by the Free Software Foundation; either
12   *
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   *
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   *
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   *
25   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26   *
27   *
28   */
29  
30  package ar.com.fdvs.dj.domain.entities;
31  
32  import java.util.ArrayList;
33  import java.util.HashMap;
34  import java.util.List;
35  import java.util.Map;
36  
37  import org.apache.commons.collections.list.UnmodifiableList;
38  
39  import ar.com.fdvs.dj.domain.DJBaseElement;
40  import ar.com.fdvs.dj.domain.DJCrosstab;
41  import ar.com.fdvs.dj.domain.DJGroupLabel;
42  import ar.com.fdvs.dj.domain.DynamicReportOptions;
43  import ar.com.fdvs.dj.domain.Style;
44  import ar.com.fdvs.dj.domain.constants.GroupLayout;
45  import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
46  import ar.com.fdvs.dj.domain.entities.columns.PropertyColumn;
47  
48  /**
49   * Entity created to handle groups of columns.</br>
50   * Multiple groups can be created for a single report. In this case the result </br>
51   * would be a nesting with the latest groups added to the report being the inner ones.
52   */
53  public class DJGroup extends DJBaseElement {
54  
55  	private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
56  	
57  	//The column used to group by
58  	private PropertyColumn columnToGroupBy;
59  
60  	public PropertyColumn getColumnToGroupBy() {
61  		return columnToGroupBy;
62  	}
63  
64  	public void setColumnToGroupBy(PropertyColumn columnToGroupBy) {
65  		this.columnToGroupBy = columnToGroupBy;
66  	}
67  
68  	/**
69  	 * Map<Column, Style>
70  	 */
71  	private Map columnHeaderStyles = new HashMap();
72  	private Style defaultColumnHeaederStyle;
73  
74  	//<DJGroupVariable>
75  	private List headerVariables = new ArrayList();
76  	//<DJGroupVariable>
77  	private List footerVariables = new ArrayList();
78  	//<DJGroupTemporalVariable>
79  	private List variables = new ArrayList();
80  	
81  	private boolean fitHeaderHeightToContent = true;
82  	private boolean fitFooterHeightToContent = true;
83  
84      /**
85       * For internal use only
86       */
87  	private String name;
88  	
89  	public boolean isFitHeaderHeightToContent() {
90  		return fitHeaderHeightToContent;
91  	}
92  
93  	public void setFitHeaderHeightToContent(boolean fitHeaderHeightToContent) {
94  		this.fitHeaderHeightToContent = fitHeaderHeightToContent;
95  	}
96  
97  	public boolean isFitFooterHeightToContent() {
98  		return fitFooterHeightToContent;
99  	}
100 
101 	/**
102 	 * When false, the footer height is not shrink to its content (variables in general), leaving a white space 
103 	 * @param fitFooterHeightToContent
104 	 */
105 	public void setFitFooterHeightToContent(boolean fitFooterHeightToContent) {
106 		this.fitFooterHeightToContent = fitFooterHeightToContent;
107 	}
108 
109 	private Integer headerHeight = DynamicReportOptions.DEFAULT_HEADER_HEIGHT; //for headers
110 	private Integer footerHeight = DynamicReportOptions.DEFAULT_FOOTER_VARIABLES_HEIGHT; //for headers
111 	
112 	private Integer headerVariablesHeight = null; //for values such as calculations, current value, etc.
113 	private Integer footerVariablesHeight = null; //for values such as calculations, current value, etc.
114 	
115 	private GroupLayout layout = GroupLayout.DEFAULT;
116 	private List footerSubreports = new ArrayList();
117 	private List headerSubreports = new ArrayList();
118 
119 	private List headerCrosstabs = new ArrayList();
120 	private List footerCrosstabs = new ArrayList();
121 
122 	private Boolean startInNewPage = Boolean.FALSE;
123 	private Boolean startInNewColumn = Boolean.FALSE;
124 	
125 	/**
126 	 * If the group is configured to print column names, they will be printed on every page 
127 	 * (even if a group is splitted in two pages)
128 	 * NOTE: this may cause unexpected results if header variables are present. 
129 	 */
130 	private Boolean reprintHeaderOnEachPage = Boolean.FALSE;
131 	
132 	private DJGroupLabel footerLabel; //general label, goes at the right of the group variables
133 
134 	/**
135 	 * pass-through property to setup group header band "allowSplit" property.
136 	 * When FALSE, if the content reaches end of the page, the whole band gets pushed
137 	 * to the next page.
138 	 */
139 	private boolean allowHeaderSplit = true;
140 
141 	/**
142 	 * pass-through property to setup group footer band "allowSplit" property.
143 	 * When FALSE, if the content reaches end of the page, the whole band gets pushed
144 	 * to the next page.
145 	 */
146 	private boolean allowFooterSplit = true;
147 
148 	/**
149 	 * Default Style for variables when showing in footer.
150 	 * First looks for the style at the ColumnsGroupVariable, then the default, finally
151 	 * it uses the columns style.
152 	 */
153 	private Style defaulFooterVariableStyle;
154 
155 	/**
156 	 * Default Style for variables when showing in header.
157 	 * The lookup order is the same as for "defaulFooterStyle"
158 	 */
159 	private Style defaulHeaderVariableStyle;
160 
161 	public Style getDefaulFooterVariableStyle() {
162 		return defaulFooterVariableStyle;
163 	}
164 
165 	public void setDefaulFooterVariableStyle(Style defaulFooterStyle) {
166 		this.defaulFooterVariableStyle = defaulFooterStyle;
167 	}
168 
169 	public Style getDefaulHeaderVariableStyle() {
170 		return defaulHeaderVariableStyle;
171 	}
172 
173 	public void setDefaulHeaderVariableStyle(Style defaulHeaderStyle) {
174 		this.defaulHeaderVariableStyle = defaulHeaderStyle;
175 	}
176 
177 	public List getFooterVariables() {
178 		return UnmodifiableList.decorate(footerVariables);
179 	}
180 
181 	public void setFooterVariables(ArrayList footerVariables) {
182 		this.footerVariables = footerVariables;
183 	}
184 
185 	public List getHeaderVariables() {
186 		return  UnmodifiableList.decorate(headerVariables);
187 	}
188 
189 	public void setHeaderVariables(ArrayList headerVariables) {
190 		this.headerVariables = headerVariables;
191 	}
192 
193 	public List getVariables() {
194 		return variables;
195 	}
196 
197 	public void setVariables(ArrayList variables) {
198 		this.variables = variables;
199 	}
200 	
201 	public Integer getFooterHeight() {
202 		return footerHeight;
203 	}
204 
205 	public void setFooterHeight(Integer footerHeight) {
206 		this.footerHeight = footerHeight;
207 	}
208 
209 	public Integer getHeaderHeight() {
210 		return headerHeight;
211 	}
212 
213 	public void setHeaderHeight(Integer headerHeight) {
214 		this.headerHeight = headerHeight;
215 	}
216 
217 	public GroupLayout getLayout() {
218 		return layout;
219 	}
220 
221 	public void setLayout(GroupLayout layout) {
222 		this.layout = layout;
223 	}
224 
225 	public List getFooterSubreports() {
226 		return footerSubreports;
227 	}
228 
229 	public List getHeaderSubreports() {
230 		return headerSubreports;
231 	}
232 
233 	public Boolean getStartInNewPage() {
234 		return startInNewPage;
235 	}
236 
237 	public void setStartInNewPage(Boolean startInNewPage) {
238 		this.startInNewPage = startInNewPage;
239 	}
240 
241 	public Boolean getStartInNewColumn() {
242 		return startInNewColumn;
243 	}
244 
245 	public void setStartInNewColumn(Boolean startInNewColumn) {
246 		this.startInNewColumn = startInNewColumn;
247 	}
248 
249 	public List getHeaderCrosstabs() {
250 		return headerCrosstabs;
251 	}
252 
253 	public void setHeaderCrosstabs(List headerCrosstabs) {
254 		this.headerCrosstabs = headerCrosstabs;
255 	}
256 
257 	public List getFooterCrosstabs() {
258 		return footerCrosstabs;
259 	}
260 
261 	public void setFooterCrosstabs(List footerCrosstabs) {
262 		this.footerCrosstabs = footerCrosstabs;
263 	}
264 
265 	public Map getColumnHeaderStyles() {
266 		return columnHeaderStyles;
267 	}
268 
269 	public void setColumnHeaderStyles(Map columnHeaderStyles) {
270 		this.columnHeaderStyles = columnHeaderStyles;
271 	}
272 
273 	public void addColumHeaderStyle(AbstractColumn col, Style style) {
274 		columnHeaderStyles.put(col, style);
275 	}
276 
277 	public Style getColumnHeaderStyle(AbstractColumn col) {
278 		if (this.columnHeaderStyles == null)
279 			return null;
280 
281 		return (Style) this.columnHeaderStyles.get(col);
282 	}
283 
284 	public Style getDefaultColumnHeaederStyle() {
285 		return defaultColumnHeaederStyle;
286 	}
287 
288 	public void setDefaultColumnHeaederStyle(Style defaultColumnHeaederStyle) {
289 		this.defaultColumnHeaederStyle = defaultColumnHeaederStyle;
290 	}
291 
292 	public boolean isAllowHeaderSplit() {
293 		return allowHeaderSplit;
294 	}
295 
296 	public void setAllowHeaederSplit(boolean allowHeaederSplit) {
297 		this.allowHeaderSplit = allowHeaederSplit;
298 	}
299 
300 	public boolean isAllowFooterSplit() {
301 		return allowFooterSplit;
302 	}
303 
304 	public void setAllowFooterSplit(boolean allowFooterSplit) {
305 		this.allowFooterSplit = allowFooterSplit;
306 	}
307 
308 	public Integer getHeaderVariablesHeight() {
309 		return headerVariablesHeight;
310 	}
311 
312 	public void setHeaderVariablesHeight(Integer headerVariablesHeight) {
313 		this.headerVariablesHeight = headerVariablesHeight;
314 	}
315 
316 	public Integer getFooterVariablesHeight() {
317 		return footerVariablesHeight;
318 	}
319 
320 	public void setFooterVariablesHeight(Integer footerVariablesHeight) {
321 		this.footerVariablesHeight = footerVariablesHeight;
322 	}
323 	
324 	public void addHeaderVariable(DJGroupVariable var) {
325 		headerVariables.add(var);
326 		var.setGroup(this);
327 	}
328 	
329 	public void addFooterVariable(DJGroupVariable var) {
330 		footerVariables.add(var);
331 		var.setGroup(this);
332 	}
333 
334 	public void addVariable(DJGroupVariableDef var) {
335 		variables.add(var);
336 	}
337 	
338 	public DJGroupLabel getFooterLabel() {
339 		return footerLabel;
340 	}
341 
342 	public void setFooterLabel(DJGroupLabel footerLabel) {
343 		this.footerLabel = footerLabel;
344 	}
345 
346 	public Boolean getReprintHeaderOnEachPage() {
347 		return reprintHeaderOnEachPage;
348 	}
349 
350 	public void setReprintHeaderOnEachPage(Boolean reprintHeaderOnEachPage) {
351 		this.reprintHeaderOnEachPage = reprintHeaderOnEachPage;
352 	}
353 
354 	public void addHeaderCrosstab(DJCrosstab cross){
355 		this.headerCrosstabs.add(cross);
356 	}
357 	
358 	public void addFooterCrosstab(DJCrosstab cross){
359 		this.footerCrosstabs.add(cross);
360 	}
361 
362 	public void setName(String name) {
363 		this.name = name;
364 	}
365 	
366 	public String getName() {
367 		return name;
368 	}
369 }