1 32 33 package it.businesslogic.ireport.gui.prompt; 34 35 import it.businesslogic.ireport.*; 36 37 import java.util.*; 38 39 40 43 public class Prompter 44 { 45 46 52 public static HashMap promptForParameters(Report report) 53 { 54 55 HashMap hm = new HashMap(); 56 57 for (int i = 0; i < report.getParameters().size(); ++i) 58 { 59 60 JRParameter param = (JRParameter) (report.getParameters().elementAt( 61 i)); 62 63 if (param.isIsForPrompting() && param.getClassType() != null && 64 !param.isBuiltin()) 65 { 66 67 PromptDialog pd = new PromptDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance(), 68 true); 69 pd.setParameter(param); 70 pd.setVisible(true); 71 72 boolean isCollection = false; 73 74 if (pd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) 75 { 76 77 Object value = pd.getValue(); 78 79 if (param.getClassType().equals("java.lang.String")) 80 { 81 hm.put(param.getName(), value); 82 } 83 else if (param.getClassType().equals("java.lang.Integer")) 84 { 85 86 try 87 { 88 hm.put(param.getName(), new Integer ("" + value)); 89 } 90 catch (Exception ex) 91 { 92 System.out.println(ex.getMessage()); 93 } 94 } 95 else if (param.getClassType().equals("java.lang.Long")) 96 { 97 98 try 99 { 100 hm.put(param.getName(), new Long ("" + value)); 101 } 102 catch (Exception ex) 103 { 104 System.out.println(ex.getMessage()); 105 } 106 } 107 else if (param.getClassType().equals("java.lang.Double")) 108 { 109 110 try 111 { 112 hm.put(param.getName(), new Double ("" + value)); 113 } 114 catch (Exception ex) 115 { 116 System.out.println(ex.getMessage()); 117 } 118 } 119 else if (param.getClassType().equals("java.lang.Float")) 120 { 121 122 try 123 { 124 hm.put(param.getName(), new Float ("" + value)); 125 } 126 catch (Exception ex) 127 { 128 System.out.println(ex.getMessage()); 129 } 130 } 131 else if (param.getClassType().equals("java.lang.Boolean")) 132 { 133 134 try 135 { 136 hm.put(param.getName(), new Boolean ("" + value)); 137 } 138 catch (Exception ex) 139 { 140 System.out.println(ex.getMessage()); 141 } 142 } 143 else if (param.getClassType().equals("java.util.Date")) 144 { 145 146 try 147 { 148 149 if (value != null) hm.put(param.getName(), value); 155 } 156 catch (Exception ex) 157 { 158 System.out.println(ex.getMessage()); 159 } 160 } 161 else if (param.getClassType().equals("java.sql.Time")) 162 { 163 164 try 165 { 166 167 java.util.Date d = (java.util.Date )value; java.sql.Time time = new java.sql.Time (d.getTime()); 173 hm.put(param.getName(), time); 174 } 175 catch (Exception ex) 176 { 177 System.out.println(ex.getMessage()); 178 } 179 } 180 else if (param.getClassType().equals("java.sql.Timestamp")) 181 { 182 183 try 184 { 185 186 java.util.Date d = (java.util.Date )value; java.sql.Timestamp time = new java.sql.Timestamp (d.getTime()); 192 hm.put(param.getName(), time); 193 } 194 catch (Exception ex) 195 { 196 System.out.println(ex.getMessage()); 197 } 198 } 199 else 200 { 201 try { 202 Class clazz = Class.forName(param.getClassType()); 203 204 if ( java.util.Collection .class.isAssignableFrom(clazz) ) 205 { 206 isCollection = true; 207 java.util.Collection collection = null; 208 collection = new java.util.ArrayList (); 209 210 if (value != null) 211 { 212 fillCollection( collection, ""+value); 213 214 param.setLastDefaultValue("" + value); 215 value = collection; 216 217 try 218 { 219 hm.put(param.getName(), collection); 220 } 221 catch (Exception ex) 222 { 223 System.out.println(ex.getMessage()); 224 } 225 } 226 } 227 228 } catch (Exception ex) 229 { 230 ex.printStackTrace(); 231 } 232 233 234 } 235 236 if (value != null && !isCollection) 237 { 238 param.setLastDefaultValue( value); 239 } 240 } 241 } 242 } 243 244 return hm; 245 } 246 247 public static void fillCollection( java.util.Collection collection, String str) 248 { 249 if (str == null || str.length() == 0) return; 250 251 StringTokenizer st = new StringTokenizer(str,",",false); 252 253 while (st.hasMoreTokens()) 254 { 255 String s = st.nextToken(); 256 257 s = s.trim(); 258 collection.add(s); 261 } 262 263 264 265 } 266 } 267 | Popular Tags |