KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > crosstab > gui > WizardFieldObject


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * WizardFieldObject.java
28  *
29  * Created on January 27, 2006, 3:42 PM
30  *
31  */

32
33 package it.businesslogic.ireport.crosstab.gui;
34
35 import it.businesslogic.ireport.JRField;
36 import it.businesslogic.ireport.JRParameter;
37 import it.businesslogic.ireport.JRVariable;
38 import java.util.Vector JavaDoc;
39
40 /**
41  *
42  * @author gtoffoli
43  */

44 public class WizardFieldObject {
45     
46     private Object JavaDoc obj = null;
47     
48     /** Creates a new instance of WizardFieldObject */
49     public WizardFieldObject(Object JavaDoc obj) {
50         
51         this.obj = obj;
52         
53     }
54     
55     public Vector JavaDoc getGroupByValues()
56     {
57         String JavaDoc classtype = "java.lang.String";
58         Vector JavaDoc groupByValues = new Vector JavaDoc();
59         
60         groupByValues.add("Unique");
61         
62         if (obj instanceof it.businesslogic.ireport.JRField)
63         {
64             classtype = ((JRField)obj).getClassType();
65         }
66         else if (obj instanceof it.businesslogic.ireport.JRParameter)
67         {
68             classtype = ((JRParameter)obj).getClassType();
69         }
70         else if (obj instanceof it.businesslogic.ireport.JRVariable)
71         {
72             classtype = ((JRVariable)obj).getClassType();
73         }
74         
75         try {
76             Class JavaDoc clazz = this.getClass().forName( classtype );
77             if ( java.util.Date JavaDoc.class.isAssignableFrom( clazz ))
78             {
79                 groupByValues.add("Year");
80                 groupByValues.add("Month");
81                 groupByValues.add("Week");
82                 groupByValues.add("Day");
83             }
84         } catch (Exception JavaDoc ex)
85         {}
86         
87       return groupByValues;
88     }
89     
90     public Vector JavaDoc getFunctions()
91     {
92         String JavaDoc classtype = "java.lang.String";
93         Vector JavaDoc functions = new Vector JavaDoc();
94         
95         functions.add("Count");
96         
97         if (obj instanceof it.businesslogic.ireport.JRField)
98         {
99             classtype = ((JRField)obj).getClassType();
100         }
101         else if (obj instanceof it.businesslogic.ireport.JRParameter)
102         {
103             classtype = ((JRParameter)obj).getClassType();
104         }
105         else if (obj instanceof it.businesslogic.ireport.JRVariable)
106         {
107             classtype = ((JRVariable)obj).getClassType();
108         }
109         
110         try {
111             Class JavaDoc clazz = this.getClass().forName( classtype );
112             
113             if (java.lang.Number JavaDoc.class.isAssignableFrom( clazz ))
114             {
115                 functions.add("Sum");
116                 functions.add("Count");
117                 functions.add("DistinctCount");
118                 functions.add("Average");
119                 functions.add("StandardDeviation");
120                 functions.add("Variance");
121             }
122             
123             if ( java.util.Date JavaDoc.class.isAssignableFrom( clazz ) ||
124                  java.lang.Number JavaDoc.class.isAssignableFrom( clazz ))
125             {
126                 functions.add("Lowest");
127                 functions.add("Highest");
128             }
129             
130             
131         } catch (Exception JavaDoc ex)
132         {}
133         
134         functions.add("First");
135         functions.add("Nothing");
136         
137       return functions;
138     }
139     
140     public String JavaDoc toString()
141     {
142         if (obj instanceof it.businesslogic.ireport.JRField)
143         {
144             return ((JRField)obj).getName() + " (field)";
145         }
146         else if (obj instanceof it.businesslogic.ireport.JRParameter)
147         {
148             return ((JRParameter)obj).getName() + " (parameter)";
149         }
150         else if (obj instanceof it.businesslogic.ireport.JRVariable)
151         {
152             return ((JRVariable)obj).getName() + " (variable)";
153         }
154         
155         return ""+obj;
156     }
157     
158     public String JavaDoc getName()
159     {
160         if (obj instanceof it.businesslogic.ireport.JRField)
161         {
162             return ((JRField)obj).getName();
163         }
164         else if (obj instanceof it.businesslogic.ireport.JRParameter)
165         {
166             return ((JRParameter)obj).getName();
167         }
168         else if (obj instanceof it.businesslogic.ireport.JRVariable)
169         {
170             return ((JRVariable)obj).getName();
171         }
172         
173         return ""+obj;
174     }
175     
176     public String JavaDoc getExpression(String JavaDoc groupByType)
177     {
178         String JavaDoc expression = "";
179         
180         if (obj instanceof it.businesslogic.ireport.JRField)
181         {
182             expression = "$F{" + ((JRField)obj).getName() + "}";
183         }
184         else if (obj instanceof it.businesslogic.ireport.JRParameter)
185         {
186             expression = "$P{" + ((JRParameter)obj).getName() + "}";
187         }
188         else if (obj instanceof it.businesslogic.ireport.JRVariable)
189         {
190             expression = "$V{" + ((JRVariable)obj).getName() + "}";
191         }
192         
193         if (groupByType.equals("Year"))
194         {
195             return "(new SimpleDateFormat(\"yyyy\")).format("+expression+")";
196         }
197         else if (groupByType.equals("Month"))
198         {
199             return "(new SimpleDateFormat(\"yyyy-MM\")).format("+expression+")";
200         }
201         else if (groupByType.equals("Week"))
202         {
203             return "(new SimpleDateFormat(\"yyyy-ww\")).format("+expression+")";
204         }
205         else if (groupByType.equals("Day"))
206         {
207             return "(new SimpleDateFormat(\"yyyy-MM-dd\")).format("+expression+")";
208         }
209         
210         return expression;
211     }
212     
213      public String JavaDoc getExpressionClass(String JavaDoc groupByType)
214     {
215         if (groupByType !=null && !groupByType.equals("Unique") )
216         {
217             return "java.lang.String";
218         }
219         
220         if (obj instanceof it.businesslogic.ireport.JRField)
221         {
222             return ((JRField)obj).getClassType();
223         }
224         else if (obj instanceof it.businesslogic.ireport.JRParameter)
225         {
226             return ((JRParameter)obj).getClassType();
227         }
228         else if (obj instanceof it.businesslogic.ireport.JRVariable)
229         {
230             return ((JRVariable)obj).getClassType();
231         }
232         
233         return "java.lang.String";
234      }
235 }
236
Popular Tags