1 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 ; 39 40 44 public class WizardFieldObject { 45 46 private Object obj = null; 47 48 49 public WizardFieldObject(Object obj) { 50 51 this.obj = obj; 52 53 } 54 55 public Vector getGroupByValues() 56 { 57 String classtype = "java.lang.String"; 58 Vector groupByValues = new Vector (); 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 clazz = this.getClass().forName( classtype ); 77 if ( java.util.Date .class.isAssignableFrom( clazz )) 78 { 79 groupByValues.add("Year"); 80 groupByValues.add("Month"); 81 groupByValues.add("Week"); 82 groupByValues.add("Day"); 83 } 84 } catch (Exception ex) 85 {} 86 87 return groupByValues; 88 } 89 90 public Vector getFunctions() 91 { 92 String classtype = "java.lang.String"; 93 Vector functions = new Vector (); 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 clazz = this.getClass().forName( classtype ); 112 113 if (java.lang.Number .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 .class.isAssignableFrom( clazz ) || 124 java.lang.Number .class.isAssignableFrom( clazz )) 125 { 126 functions.add("Lowest"); 127 functions.add("Highest"); 128 } 129 130 131 } catch (Exception ex) 132 {} 133 134 functions.add("First"); 135 functions.add("Nothing"); 136 137 return functions; 138 } 139 140 public String 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 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 getExpression(String groupByType) 177 { 178 String 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 getExpressionClass(String 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 |