View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/cewolf/CewolfPieDataTag.java,v 1.2 2006/03/16 14:23:02 hkollmann Exp $
3    * $Revision: 1.2 $
4    * $Date: 2006/03/16 14:23:02 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib.cewolf;
25  
26  import java.util.HashMap;
27  
28  import javax.servlet.jsp.JspException;
29  
30  import de.laures.cewolf.taglib.DataAware;
31  import de.laures.cewolf.DatasetProducer;
32  
33  import org.jfree.data.general.DefaultPieDataset;
34  
35  import org.dbforms.taglib.AbstractDbBaseHandlerTag;
36  import org.dbforms.config.ResultSetVector;
37  
38  /***
39   * 
40   * This tag defines PieData for cewolf
41   * 
42   * @author Henner Kollmann
43   * 
44   */
45  
46  public class CewolfPieDataTag extends AbstractDbBaseHandlerTag {
47  	private String categoryField;
48  
49  	private String dataField;
50  
51  	public int doEndTag() throws JspException {
52  		DefaultPieDataset ds = new DefaultPieDataset();
53  		ResultSetVector rsv = getParentForm().getResultSetVector();
54  		for (int i = 0; i < rsv.size(); i++) {
55  			Comparable c = (Comparable) rsv.getFieldAsObject(i,
56  					getCategoryField());
57  			Number n = (Number) rsv.getFieldAsObject(i, getDataField());
58  			ds.setValue(c, n);
59  		}
60  		DatasetProducer dataProducer = new DbFormsDatasetProducer(ds);
61  		DataAware dw = (DataAware) findAncestorWithClass(this, DataAware.class);
62  		dw.setDataProductionConfig(dataProducer, new HashMap(), false);
63  		return SKIP_BODY;
64  	}
65  
66  	/***
67  	 * @return Returns the categoryField.
68  	 */
69  	public String getCategoryField() {
70  		return categoryField;
71  	}
72  
73  	/***
74  	 * @param categoryField
75  	 *            The categoryField to set.
76  	 */
77  	public void setCategoryField(String categoryField) {
78  		this.categoryField = categoryField;
79  	}
80  
81  	/***
82  	 * @return Returns the dataField.
83  	 */
84  	public String getDataField() {
85  		return dataField;
86  	}
87  
88  	/***
89  	 * @param dataField
90  	 *            The dataField to set.
91  	 */
92  	public void setDataField(String dataField) {
93  		this.dataField = dataField;
94  	}
95  
96  	public void doFinally() {
97  		super.doFinally();
98  		categoryField = null;
99  		dataField = null;
100 	}
101 
102 }