1 29 30 package it.businesslogic.ireport.util; 31 32 import it.businesslogic.ireport.Band; 33 import it.businesslogic.ireport.Group; 34 import it.businesslogic.ireport.JRField; 35 import it.businesslogic.ireport.Report; 36 import it.businesslogic.ireport.ReportElement; 37 import it.businesslogic.ireport.StaticTextReportElement; 38 import it.businesslogic.ireport.TextFieldReportElement; 39 import it.businesslogic.ireport.TransformationType; 40 import it.businesslogic.ireport.gui.wizard.UserChoicesWizardTemplate; 41 import java.util.Enumeration ; 42 import java.util.Vector ; 43 44 48 public class ReportGenerator { 49 50 public static Report createReport(UserChoicesWizardTemplate ucwt) throws Exception 51 { 52 if (ucwt.getTemplateFile().toUpperCase().endsWith("C.XML")) 53 { 54 return createColumnarReport(ucwt); 55 } 56 else 57 { 58 return createTabularReport(ucwt); 59 } 60 } 61 62 65 static public Report createColumnarReport(UserChoicesWizardTemplate ucwt) throws Exception 66 { 67 Report template = new Report(ucwt.getTemplateFile()); 68 69 template.incrementReportChanges(); 70 template.setFilename(null); 71 72 Band detail=null; 74 Band columns=null; 75 76 Enumeration e = template.getBands().elements(); 77 while (e.hasMoreElements()) { 78 Band band = (Band)e.nextElement(); 79 if (band.getName().equals("detail")) { 80 detail = band; 81 } else if (band.getName().equals("columnHeader")) { 82 columns = band; 83 } 84 } 85 86 e = template.getElements().elements(); 88 while (e.hasMoreElements()) { 89 ReportElement rElement = (ReportElement)e.nextElement(); 90 rElement.trasform(new java.awt.Point (0,- template.getBandYLocation( rElement.getBand() )),TransformationType.TRANSFORMATION_MOVE ); 91 } 92 93 if (ucwt.getGroupExpressions().size() > 0) { 95 Group g = template.getGroupByName("Group1"); 96 Group g1 = new Group( template,Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(0)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 97 g1.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(0) + "}" ); 98 template.addGroup(g1); 99 100 e = template.getElements().elements(); 102 while (e.hasMoreElements()) { 103 ReportElement rElement = (ReportElement)e.nextElement(); 104 if (rElement.getBand() == g.getGroupHeader()) 105 rElement.setBand(g1.getGroupHeader() ); 106 else if (rElement.getBand() == g.getGroupFooter()) 107 rElement.setBand(g1.getGroupFooter() ); 108 if (rElement instanceof StaticTextReportElement) { 110 StaticTextReportElement stre = (StaticTextReportElement)rElement; 111 if (stre.getText().equals("G1Label")) 112 stre.setText( ""+ucwt.getGroupExpressions().get(0)); 113 } else if (rElement instanceof TextFieldReportElement) { 114 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 115 if (tfre.getText().equals("G1Field")) { 116 tfre.setText("$F{"+ucwt.getGroupExpressions().get(0)+"}"); 117 String fname = ""+ucwt.getGroupExpressions().get(0); 119 String fclass = "java.lang.String"; 120 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 121 { 122 JRField f = (JRField)ucwt.getDisplayFields().get(i); 123 if (f.getName().equals(fname)) 124 { 125 fclass = f.getClassType(); 126 break; 127 } 128 } 129 tfre.setMatchingClassExpression( fclass, true ); 130 } 131 } 132 } 133 } 134 135 if (ucwt.getGroupExpressions().size() > 1) { 136 Group g = template.getGroupByName("Group2"); 137 Group g2 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(1)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 138 g2.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(1) + "}" ); 139 template.addGroup(g2); 140 141 e = template.getElements().elements(); 143 while (e.hasMoreElements()) { 144 ReportElement rElement = (ReportElement)e.nextElement(); 145 if (rElement.getBand() == g.getGroupHeader()) 146 rElement.setBand(g2.getGroupHeader() ); 147 else if (rElement.getBand() == g.getGroupFooter()) 148 rElement.setBand(g2.getGroupFooter() ); 149 if (rElement instanceof StaticTextReportElement) { 151 StaticTextReportElement stre = (StaticTextReportElement)rElement; 152 if (stre.getText().equals("G2Label")) 153 stre.setText( ""+ucwt.getGroupExpressions().get(1)); 154 } else if (rElement instanceof TextFieldReportElement) { 155 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 156 if (tfre.getText().equals("G2Field")) { 157 tfre.setText("$F{"+ucwt.getGroupExpressions().get(1)+"}"); 158 String fname = ""+ucwt.getGroupExpressions().get(1); 160 String fclass = "java.lang.String"; 161 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 162 { 163 JRField f = (JRField)ucwt.getDisplayFields().get(i); 164 if (f.getName().equals(fname)) 165 { 166 fclass = f.getClassType(); 167 break; 168 } 169 } 170 tfre.setMatchingClassExpression( fclass, true ); 171 } 172 } 173 } 174 } 175 176 if (ucwt.getGroupExpressions().size() > 2) { 177 Group g = template.getGroupByName("Group3"); 178 Group g3 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(2)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 179 g3.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(2) + "}" ); 180 template.addGroup(g3); 181 182 e = template.getElements().elements(); 184 while (e.hasMoreElements()) { 185 ReportElement rElement = (ReportElement)e.nextElement(); 186 if (rElement.getBand() == g.getGroupHeader()) 187 rElement.setBand(g3.getGroupHeader() ); 188 else if (rElement.getBand() == g.getGroupFooter()) 189 rElement.setBand(g3.getGroupFooter() ); 190 if (rElement instanceof StaticTextReportElement) { 192 StaticTextReportElement stre = (StaticTextReportElement)rElement; 193 if (stre.getText().equals("G3Label")) 194 stre.setText( ""+ucwt.getGroupExpressions().get(2)); 195 } else if (rElement instanceof TextFieldReportElement) { 196 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 197 if (tfre.getText().equals("G3Field")) { 198 tfre.setText("$F{"+ucwt.getGroupExpressions().get(2)+"}"); 199 String fname = ""+ucwt.getGroupExpressions().get(2); 201 String fclass = "java.lang.String"; 202 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 203 { 204 JRField f = (JRField)ucwt.getDisplayFields().get(i); 205 if (f.getName().equals(fname)) 206 { 207 fclass = f.getClassType(); 208 break; 209 } 210 } 211 tfre.setMatchingClassExpression( fclass, true ); 212 } 213 } 214 } 215 } 216 217 if (ucwt.getGroupExpressions().size() > 3) { 218 Group g = template.getGroupByName("Group4"); 219 Group g4 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(3)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 220 g4.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(3) + "}" ); 221 template.addGroup(g4); 222 223 e = template.getElements().elements(); 225 while (e.hasMoreElements()) { 226 ReportElement rElement = (ReportElement)e.nextElement(); 227 if (rElement.getBand() == g.getGroupHeader()) 228 rElement.setBand(g4.getGroupHeader() ); 229 else if (rElement.getBand() == g.getGroupFooter()) 230 rElement.setBand(g4.getGroupFooter() ); 231 if (rElement instanceof StaticTextReportElement) { 233 StaticTextReportElement stre = (StaticTextReportElement)rElement; 234 if (stre.getText().equals("G4Label")) 235 stre.setText( ""+ucwt.getGroupExpressions().get(3)); 236 } else if (rElement instanceof TextFieldReportElement) { 237 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 238 if (tfre.getText().equals("G4Field")) { 239 tfre.setText("$F{"+ucwt.getGroupExpressions().get(3)+"}"); 240 String fname = ""+ucwt.getGroupExpressions().get(3); 242 String fclass = "java.lang.String"; 243 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 244 { 245 JRField f = (JRField)ucwt.getDisplayFields().get(i); 246 if (f.getName().equals(fname)) 247 { 248 fclass = f.getClassType(); 249 break; 250 } 251 } 252 tfre.setMatchingClassExpression( fclass, true ); 253 } 254 } 255 } 256 } 257 258 int currentx = template.getLeftMargin()+10; 260 int currenty = 10; 261 e = template.getElements().elements(); 262 StaticTextReportElement detailLabel = null; 263 TextFieldReportElement detailField = null; 264 while (e.hasMoreElements() && (detailLabel==null || detailField == null) ) { 265 ReportElement rElement = (ReportElement)e.nextElement(); 266 if (rElement instanceof StaticTextReportElement) { 267 StaticTextReportElement stre = (StaticTextReportElement)rElement; 268 if (stre.getText().equalsIgnoreCase("DetailLabel")) 269 detailLabel =stre; 270 } else if (rElement instanceof TextFieldReportElement) { 271 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 272 if (tfre.getText().equalsIgnoreCase("DetailField")) 273 detailField = tfre; 274 } 275 } 276 277 if (detailField != null) 278 template.getElements().removeElement(detailField); 279 if (detailLabel != null) 280 template.getElements().removeElement(detailLabel); 281 282 if (detailField == null) 283 detailField = new TextFieldReportElement(0,0,100,20); 284 if (detailLabel == null) 285 detailLabel = new StaticTextReportElement(0,0,100,18); 286 287 int nfields = ucwt.getDisplayFields().size(); 288 289 290 if (ucwt.getGroupExpressions().size()>0) nfields--; 291 if (ucwt.getGroupExpressions().size()>1) nfields--; 292 if (ucwt.getGroupExpressions().size()>2) nfields--; 293 if (ucwt.getGroupExpressions().size()>3) nfields--; 294 295 int fwidth = template.getColumnWidth()/ ( (nfields <= 0) ? 1 : nfields); 296 int ffheight = detailField.getPosition().y; 297 298 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) { 299 it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField)ucwt.getDisplayFields().get(i); 301 template.addField(f); 302 303 if (ucwt.getGroupExpressions().size()>0 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(0) )) 304 continue; 305 if (ucwt.getGroupExpressions().size()>1 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(1) )) 306 continue; 307 if (ucwt.getGroupExpressions().size()>2 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(2) )) 308 continue; 309 if (ucwt.getGroupExpressions().size()>3 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(3) )) 310 continue; 311 312 313 TextFieldReportElement re = (TextFieldReportElement)detailField.cloneMe(); 314 re.setPosition(new java.awt.Point (detailField.getPosition().x, ffheight)); 315 re.updateBounds(); 316 re.setText("$F{"+ f.getName() +"}"); 317 318 re.setBand(detail); 319 re.setMatchingClassExpression( f.getClassType(), true ); 320 321 template.getElements().addElement(re); 322 323 StaticTextReportElement sre = (StaticTextReportElement)detailLabel.cloneMe(); 325 sre.setPosition(new java.awt.Point (detailLabel.getPosition().x,ffheight)); 326 sre.setWidth(fwidth); 327 sre.updateBounds(); 328 329 String columnLabelText=f.getName(); 332 if(ucwt.isSaveFieldDescriptions()) { 333 String description = f.getDescription(); 334 if(description!=null && description.length() > 0) 335 columnLabelText = description; 336 } 337 338 sre.setText(""+ columnLabelText +""); 339 sre.setBand(detail); 340 template.getElements().addElement(sre); 341 342 ffheight += detailField.position.y+detailField.height-10; 343 } 344 345 detail.setHeight(ffheight); 346 347 e = template.getElements().elements(); 349 Vector elements_to_delete = new Vector (); 350 while (e.hasMoreElements()) { 351 ReportElement rElement = (ReportElement)e.nextElement(); 352 Group g = null; 353 if ((g=template.getGroupByName("Group1"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 354 elements_to_delete.addElement(rElement); 355 else if ((g=template.getGroupByName("Group2"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 356 elements_to_delete.addElement(rElement); 357 else if ((g=template.getGroupByName("Group3"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 358 elements_to_delete.addElement(rElement); 359 else if ((g=template.getGroupByName("Group4"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 360 elements_to_delete.addElement(rElement); 361 } 362 e =elements_to_delete.elements(); 363 while (e.hasMoreElements()) { 364 template.getElements().removeElement(e.nextElement()); 365 } 366 367 Group g; 368 if ((g=template.getGroupByName("Group1"))!=null) { 369 template.getBands().removeElement(g.getGroupFooter()); 370 template.getBands().removeElement(g.getGroupHeader()); 371 template.getGroups().removeElement(g); 372 } 373 if ((g=template.getGroupByName("Group2"))!=null) { 374 template.getBands().removeElement(g.getGroupFooter()); 375 template.getBands().removeElement(g.getGroupHeader()); 376 template.getGroups().removeElement(g); 377 } 378 if ((g=template.getGroupByName("Group3"))!=null) { 379 template.getBands().removeElement(g.getGroupFooter()); 380 template.getBands().removeElement(g.getGroupHeader()); 381 template.getGroups().removeElement(g); 382 } 383 384 if ((g=template.getGroupByName("Group4"))!=null) { 385 template.getBands().removeElement(g.getGroupFooter()); 386 template.getBands().removeElement(g.getGroupHeader()); 387 template.getGroups().removeElement(g); 388 } 389 390 391 402 e = template.getElements().elements(); 404 while (e.hasMoreElements()) { 405 ReportElement rElement = (ReportElement)e.nextElement(); 406 rElement.trasform(new java.awt.Point (0,+ template.getBandYLocation( rElement.getBand() )),TransformationType.TRANSFORMATION_MOVE ); 407 } 408 409 template.setQuery( ucwt.getQuery() ); 410 template.setQueryLanguage( ucwt.getQuery_language() ); 411 412 return template; 413 } 414 415 416 417 418 422 public static Report createTabularReport(UserChoicesWizardTemplate ucwt) throws Exception 423 { 424 425 Report template = new Report(ucwt.getTemplateFile()); 426 427 template.incrementReportChanges(); 428 template.setFilename(null); 429 430 Band detail=null; 432 Band columns=null; 433 434 Enumeration e = template.getBands().elements(); 435 while (e.hasMoreElements()) { 436 Band band = (Band)e.nextElement(); 437 if (band.getName().equals("detail")) { 438 detail = band; 439 } else if (band.getName().equals("columnHeader")) { 440 columns = band; 441 } 442 } 443 444 e = template.getElements().elements(); 446 while (e.hasMoreElements()) { 447 ReportElement rElement = (ReportElement)e.nextElement(); 448 rElement.trasform(new java.awt.Point (0,- template.getBandYLocation( rElement.getBand() )),TransformationType.TRANSFORMATION_MOVE ); 449 } 450 451 if (ucwt.getGroupExpressions().size() > 0) { 453 Group g = template.getGroupByName("Group1"); 454 Group g1 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(0)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 455 g1.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(0) + "}" ); 456 template.addGroup(g1); 457 458 e = template.getElements().elements(); 460 while (e.hasMoreElements()) { 461 ReportElement rElement = (ReportElement)e.nextElement(); 462 if (rElement.getBand() == g.getGroupHeader()) 463 rElement.setBand(g1.getGroupHeader() ); 464 else if (rElement.getBand() == g.getGroupFooter()) 465 rElement.setBand(g1.getGroupFooter() ); 466 if (rElement instanceof StaticTextReportElement) { 468 StaticTextReportElement stre = (StaticTextReportElement)rElement; 469 if (stre.getText().equals("G1Label")) 470 stre.setText( ""+ucwt.getGroupExpressions().get(0)); 471 } else if (rElement instanceof TextFieldReportElement) { 472 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 473 if (tfre.getText().equals("G1Field")) { 474 tfre.setText("$F{"+ucwt.getGroupExpressions().get(0)+"}"); 475 String fname = ""+ucwt.getGroupExpressions().get(0); 477 String fclass = "java.lang.String"; 478 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 479 { 480 JRField f = (JRField)ucwt.getDisplayFields().get(i); 481 if (f.getName().equals(fname)) 482 { 483 fclass = f.getClassType(); 484 break; 485 } 486 } 487 tfre.setMatchingClassExpression( fclass, true ); 488 } 489 } 490 } 491 } 492 493 if (ucwt.getGroupExpressions().size() > 1) { 494 Group g = template.getGroupByName("Group2"); 495 Group g2 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(1)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 496 g2.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(1) + "}" ); 497 template.addGroup(g2); 498 499 e = template.getElements().elements(); 501 while (e.hasMoreElements()) { 502 ReportElement rElement = (ReportElement)e.nextElement(); 503 if (rElement.getBand() == g.getGroupHeader()) 504 rElement.setBand(g2.getGroupHeader() ); 505 else if (rElement.getBand() == g.getGroupFooter()) 506 rElement.setBand(g2.getGroupFooter() ); 507 if (rElement instanceof StaticTextReportElement) { 509 StaticTextReportElement stre = (StaticTextReportElement)rElement; 510 if (stre.getText().equals("G2Label")) 511 stre.setText( ""+ucwt.getGroupExpressions().get(1)); 512 } else if (rElement instanceof TextFieldReportElement) { 513 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 514 if (tfre.getText().equals("G2Field")) { 515 tfre.setText("$F{"+ucwt.getGroupExpressions().get(1)+"}"); 516 String fname = ""+ucwt.getGroupExpressions().get(1); 518 String fclass = "java.lang.String"; 519 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 520 { 521 JRField f = (JRField)ucwt.getDisplayFields().get(i); 522 if (f.getName().equals(fname)) 523 { 524 fclass = f.getClassType(); 525 break; 526 } 527 } 528 tfre.setMatchingClassExpression( fclass, true ); 529 } 530 } 531 } 532 } 533 534 if (ucwt.getGroupExpressions().size() > 2) { 535 Group g = template.getGroupByName("Group3"); 536 Group g3 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(2)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 537 g3.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(2) + "}" ); 538 template.addGroup(g3); 539 540 e = template.getElements().elements(); 542 while (e.hasMoreElements()) { 543 ReportElement rElement = (ReportElement)e.nextElement(); 544 if (rElement.getBand() == g.getGroupHeader()) 545 rElement.setBand(g3.getGroupHeader() ); 546 else if (rElement.getBand() == g.getGroupFooter()) 547 rElement.setBand(g3.getGroupFooter() ); 548 if (rElement instanceof StaticTextReportElement) { 550 StaticTextReportElement stre = (StaticTextReportElement)rElement; 551 if (stre.getText().equals("G3Label")) 552 stre.setText( ""+ucwt.getGroupExpressions().get(2)); 553 } else if (rElement instanceof TextFieldReportElement) { 554 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 555 if (tfre.getText().equals("G3Field")) { 556 tfre.setText("$F{"+ucwt.getGroupExpressions().get(2)+"}"); 557 String fname = ""+ucwt.getGroupExpressions().get(2); 559 String fclass = "java.lang.String"; 560 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 561 { 562 JRField f = (JRField)ucwt.getDisplayFields().get(i); 563 if (f.getName().equals(fname)) 564 { 565 fclass = f.getClassType(); 566 break; 567 } 568 } 569 tfre.setMatchingClassExpression( fclass, true ); 570 } 571 } 572 } 573 } 574 575 if (ucwt.getGroupExpressions().size() > 3) { 576 Group g = template.getGroupByName("Group4"); 577 Group g4 = new Group( template, Misc.string_replace("_"," ",""+ucwt.getGroupExpressions().get(3)), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); 578 g4.setGroupExpression("$F{"+ ucwt.getGroupExpressions().get(3) + "}" ); 579 template.addGroup(g4); 580 581 e = template.getElements().elements(); 583 while (e.hasMoreElements()) { 584 ReportElement rElement = (ReportElement)e.nextElement(); 585 if (rElement.getBand() == g.getGroupHeader()) 586 rElement.setBand(g4.getGroupHeader() ); 587 else if (rElement.getBand() == g.getGroupFooter()) 588 rElement.setBand(g4.getGroupFooter() ); 589 if (rElement instanceof StaticTextReportElement) { 591 StaticTextReportElement stre = (StaticTextReportElement)rElement; 592 if (stre.getText().equals("G4Label")) 593 stre.setText( ""+ucwt.getGroupExpressions().get(3)); 594 } else if (rElement instanceof TextFieldReportElement) { 595 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 596 if (tfre.getText().equals("G4Field")) { 597 tfre.setText("$F{"+ucwt.getGroupExpressions().get(3)+"}"); 598 String fname = ""+ucwt.getGroupExpressions().get(3); 600 String fclass = "java.lang.String"; 601 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) 602 { 603 JRField f = (JRField)ucwt.getDisplayFields().get(i); 604 if (f.getName().equals(fname)) 605 { 606 fclass = f.getClassType(); 607 break; 608 } 609 } 610 tfre.setMatchingClassExpression( fclass, true ); 611 } 612 } 613 } 614 } 615 616 int currentx = template.getLeftMargin()+10; 618 int currenty = 10; 619 e = template.getElements().elements(); 620 StaticTextReportElement detailLabel = null; 621 TextFieldReportElement detailField = null; 622 while (e.hasMoreElements() && (detailLabel==null || detailField == null) ) { 623 ReportElement rElement = (ReportElement)e.nextElement(); 624 if (rElement instanceof StaticTextReportElement) { 625 StaticTextReportElement stre = (StaticTextReportElement)rElement; 626 if (stre.getText().equalsIgnoreCase("DetailLabel")) 627 detailLabel =stre; 628 } else if (rElement instanceof TextFieldReportElement) { 629 TextFieldReportElement tfre = (TextFieldReportElement)rElement; 630 if (tfre.getText().equalsIgnoreCase("DetailField")) 631 detailField = tfre; 632 } 633 } 634 635 if (detailField != null) 636 template.getElements().removeElement(detailField); 637 if (detailLabel != null) 638 template.getElements().removeElement(detailLabel); 639 640 if (detailField == null) 641 detailField = new TextFieldReportElement(0,0,100,20); 642 if (detailLabel == null) 643 detailLabel = new StaticTextReportElement(0,0,100,18); 644 645 int nfields = ucwt.getDisplayFields().size(); 646 if (ucwt.getGroupExpressions().size()>0) nfields--; 647 if (ucwt.getGroupExpressions().size()>1) nfields--; 648 if (ucwt.getGroupExpressions().size()>2) nfields--; 649 if (ucwt.getGroupExpressions().size()>3) nfields--; 650 651 int fwidth = template.getColumnWidth()/( (nfields <= 0) ? 1 : nfields); 652 653 for (int i=0; i<ucwt.getDisplayFields().size(); ++i) { 654 it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField)ucwt.getDisplayFields().get(i); 656 template.addField(f); 657 658 if (ucwt.getGroupExpressions().size()>0 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(0) )) 659 continue; 660 if (ucwt.getGroupExpressions().size()>1 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(1) )) 661 continue; 662 if (ucwt.getGroupExpressions().size()>2 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(2) )) 663 continue; 664 if (ucwt.getGroupExpressions().size()>3 && f.getName().equalsIgnoreCase( ""+ucwt.getGroupExpressions().get(3) )) 665 continue; 666 667 668 TextFieldReportElement re = (TextFieldReportElement)detailField.cloneMe(); 669 re.setPosition(new java.awt.Point (currentx,detailField.getPosition().y)); 670 re.setWidth( fwidth); 671 re.updateBounds(); 672 re.setText("$F{"+ f.getName() +"}"); 673 674 re.setBand(detail); 675 re.setMatchingClassExpression( f.getClassType(), true ); 676 template.getElements().addElement(re); 677 678 StaticTextReportElement sre = (StaticTextReportElement)detailLabel.cloneMe(); 680 sre.setPosition(new java.awt.Point (currentx,detailLabel.getPosition().y)); 681 sre.setWidth(fwidth); 682 sre.updateBounds(); 683 684 String columnLabelText=f.getName(); 687 if(ucwt.isSaveFieldDescriptions()) { 688 String description = f.getDescription(); 689 if(description!=null && description.length() > 0) 690 columnLabelText = description; 691 } 692 693 sre.setText(""+ columnLabelText +""); 694 sre.setBand(columns); 695 template.getElements().addElement(sre); 696 697 currentx += fwidth; 698 currentx = Math.min(template.getWidth() - template.getRightMargin()+10-30, currentx); 699 } 700 701 e = template.getElements().elements(); 703 Vector elements_to_delete = new Vector (); 704 while (e.hasMoreElements()) { 705 ReportElement rElement = (ReportElement)e.nextElement(); 706 Group g = null; 707 if ((g=template.getGroupByName("Group1"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 708 elements_to_delete.addElement(rElement); 709 else if ((g=template.getGroupByName("Group2"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 710 elements_to_delete.addElement(rElement); 711 else if ((g=template.getGroupByName("Group3"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 712 elements_to_delete.addElement(rElement); 713 else if ((g=template.getGroupByName("Group4"))!=null && (rElement.getBand() == g.getGroupHeader() || rElement.getBand() == g.getGroupFooter())) 714 elements_to_delete.addElement(rElement); 715 } 716 e =elements_to_delete.elements(); 717 while (e.hasMoreElements()) { 718 template.getElements().removeElement(e.nextElement()); 719 } 720 721 Group g; 722 if ((g=template.getGroupByName("Group1"))!=null) { 723 template.getBands().removeElement(g.getGroupFooter()); 724 template.getBands().removeElement(g.getGroupHeader()); 725 template.getGroups().removeElement(g); 726 } 727 if ((g=template.getGroupByName("Group2"))!=null) { 728 template.getBands().removeElement(g.getGroupFooter()); 729 template.getBands().removeElement(g.getGroupHeader()); 730 template.getGroups().removeElement(g); 731 } 732 if ((g=template.getGroupByName("Group3"))!=null) { 733 template.getBands().removeElement(g.getGroupFooter()); 734 template.getBands().removeElement(g.getGroupHeader()); 735 template.getGroups().removeElement(g); 736 } 737 738 if ((g=template.getGroupByName("Group4"))!=null) { 739 template.getBands().removeElement(g.getGroupFooter()); 740 template.getBands().removeElement(g.getGroupHeader()); 741 template.getGroups().removeElement(g); 742 } 743 744 755 e = template.getElements().elements(); 757 while (e.hasMoreElements()) { 758 ReportElement rElement = (ReportElement)e.nextElement(); 759 rElement.trasform(new java.awt.Point (0,+ template.getBandYLocation( rElement.getBand() )),TransformationType.TRANSFORMATION_MOVE ); 760 } 761 762 template.setQuery( ucwt.getQuery() ); 763 template.setQueryLanguage( ucwt.getQuery_language() ); 764 765 return template; 766 } 767 } 768 | Popular Tags |