1 32 33 package it.businesslogic.ireport.gui.wizard; 34 35 import it.businesslogic.ireport.Band; 36 import it.businesslogic.ireport.Group; 37 import it.businesslogic.ireport.IReportConnection; 38 import it.businesslogic.ireport.IReportTemplate; 39 import it.businesslogic.ireport.JRField; 40 import it.businesslogic.ireport.Report; 41 import it.businesslogic.ireport.ReportElement; 42 import it.businesslogic.ireport.StaticTextReportElement; 43 import it.businesslogic.ireport.SubReportElement; 44 import it.businesslogic.ireport.TextFieldReportElement; 45 import it.businesslogic.ireport.TransformationType; 46 import it.businesslogic.ireport.connection.JDBCConnection; 47 import it.businesslogic.ireport.connection.JRHibernateConnection; 48 import it.businesslogic.ireport.gui.ConnectionDialog; 49 import it.businesslogic.ireport.gui.JReportFrame; 50 import it.businesslogic.ireport.gui.MainFrame; 51 import it.businesslogic.ireport.gui.WizardDialog; 52 import it.businesslogic.ireport.gui.event.ReportBandChangedEvent; 53 import it.businesslogic.ireport.util.Misc; 54 import java.io.File ; 55 import java.io.FileInputStream ; 56 import java.io.FilenameFilter ; 57 import java.io.InputStream ; 58 import java.util.Enumeration ; 59 import java.util.Vector ; 60 import javax.swing.DefaultListModel ; 61 import javax.swing.ImageIcon ; 62 import javax.swing.JDialog ; 63 import javax.swing.JFileChooser ; 64 import javax.swing.JOptionPane ; 65 import javax.swing.JPanel ; 66 import javax.swing.event.DocumentEvent ; 67 import javax.swing.event.DocumentListener ; 68 69 import org.apache.xerces.parsers.DOMParser; 70 import org.apache.xpath.XPathAPI; 71 import org.apache.xpath.objects.XBoolean; 72 import org.w3c.dom.DOMException ; 73 import org.w3c.dom.Document ; 74 import org.w3c.dom.Node ; 75 import org.w3c.dom.NodeList ; 76 import org.xml.sax.SAXException ; 77 import it.businesslogic.ireport.util.I18n; 78 79 83 public class ReportGroupWizard extends javax.swing.JPanel implements GenericWizard { 84 85 private String reportFileName = null; 86 private SubReportElement subReportElement = null; 87 private BaseWizardPanel wizardPanel = null; 88 private JDialog wizardDialog = null; 89 private JReportFrame jReportFrame = null; 90 91 Vector templates = null; 92 93 private Thread t = null; 94 95 96 public ReportGroupWizard() { 97 initComponents(); 98 applyI18n(); 99 jRTextExpressionArea.getDocument().addDocumentListener( new DocumentListener () { 100 public void changedUpdate(DocumentEvent e) { 101 if (wizardPanel != null) wizardPanel.updateButtons(); 102 } 103 public void insertUpdate(DocumentEvent e) { 104 if (wizardPanel != null) wizardPanel.updateButtons(); 105 } 106 public void removeUpdate(DocumentEvent e) { 107 if (wizardPanel != null) wizardPanel.updateButtons(); 108 } 109 }); 110 111 jTextField1.getDocument().addDocumentListener( new DocumentListener () { 112 public void changedUpdate(DocumentEvent e) { 113 if (wizardPanel != null) wizardPanel.updateButtons(); 114 } 115 public void insertUpdate(DocumentEvent e) { 116 if (wizardPanel != null) wizardPanel.updateButtons(); 117 } 118 public void removeUpdate(DocumentEvent e) { 119 if (wizardPanel != null) wizardPanel.updateButtons(); 120 } 121 }); 122 123 Vector values = new Vector (); 125 126 Report report = MainFrame.getMainInstance().getActiveReportFrame().getReport(); 127 128 values.addAll( report.getFields()); 129 values.addAll( report.getVariables()); 130 values.addAll( report.getParameters()); 131 132 for (int i=0; i<values.size(); ++i) 133 { 134 jComboBoxObject.addItem(values.elementAt(i)); 135 } 136 } 137 138 public void startWizard() 139 { 140 setJReportFrame(MainFrame.getMainInstance().getActiveReportFrame()); 141 wizardDialog = new JDialog (MainFrame.getMainInstance(),true); 142 wizardPanel = new BaseWizardPanel(); 143 wizardPanel.setGenericWizard(this); 144 wizardDialog.getContentPane().add(wizardPanel); 145 wizardDialog.pack(); 146 Misc.centerFrame(wizardDialog); 147 148 wizardDialog.setVisible(true); 149 } 150 151 156 private void initComponents() { 158 java.awt.GridBagConstraints gridBagConstraints; 159 160 jPanel0 = new javax.swing.JPanel (); 161 jLabel1 = new javax.swing.JLabel (); 162 jTextField1 = new javax.swing.JTextField (); 163 jLabelErrorMessage = new javax.swing.JLabel (); 164 jPanel61 = new javax.swing.JPanel (); 165 jPanel6 = new javax.swing.JPanel (); 166 jRadioButton1 = new javax.swing.JRadioButton (); 167 jComboBoxObject = new javax.swing.JComboBox (); 168 jRadioButton2 = new javax.swing.JRadioButton (); 169 jRTextExpressionArea = new it.businesslogic.ireport.gui.JRTextExpressionArea(); 170 buttonGroup1 = new javax.swing.ButtonGroup (); 171 jPanel1 = new javax.swing.JPanel (); 172 jCheckBox1 = new javax.swing.JCheckBox (); 173 jCheckBox2 = new javax.swing.JCheckBox (); 174 175 jPanel0.setLayout(new java.awt.GridBagLayout ()); 176 177 jPanel0.addPropertyChangeListener(new java.beans.PropertyChangeListener () { 178 public void propertyChange(java.beans.PropertyChangeEvent evt) { 179 jPanel0PropertyChange(evt); 180 } 181 }); 182 183 jLabel1.setText("Group name"); 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 187 gridBagConstraints.insets = new java.awt.Insets (10, 24, 0, 24); 188 jPanel0.add(jLabel1, gridBagConstraints); 189 190 gridBagConstraints = new java.awt.GridBagConstraints (); 191 gridBagConstraints.gridx = 0; 192 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 193 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 10); 194 jPanel0.add(jTextField1, gridBagConstraints); 195 196 jLabelErrorMessage.setForeground(new java.awt.Color (204, 0, 51)); 197 jLabelErrorMessage.setText(" "); 198 gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.gridx = 0; 200 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 201 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 202 gridBagConstraints.weightx = 1.0; 203 gridBagConstraints.insets = new java.awt.Insets (2, 24, 15, 10); 204 jPanel0.add(jLabelErrorMessage, gridBagConstraints); 205 206 jPanel61.setMinimumSize(new java.awt.Dimension (10, 30)); 207 jPanel61.setPreferredSize(new java.awt.Dimension (10, 30)); 208 jPanel0.add(jPanel61, new java.awt.GridBagConstraints ()); 209 210 jPanel6.setLayout(new java.awt.GridBagLayout ()); 211 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 0; 214 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 215 gridBagConstraints.weightx = 1.0; 216 jPanel0.add(jPanel6, gridBagConstraints); 217 218 buttonGroup1.add(jRadioButton1); 219 jRadioButton1.setSelected(true); 220 jRadioButton1.setText("Group by the following report object:"); 221 jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 222 jRadioButton1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 223 jRadioButton1.addActionListener(new java.awt.event.ActionListener () { 224 public void actionPerformed(java.awt.event.ActionEvent evt) { 225 jRadioButton1ActionPerformed(evt); 226 } 227 }); 228 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 0; 231 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 232 gridBagConstraints.weightx = 1.0; 233 gridBagConstraints.insets = new java.awt.Insets (8, 24, 0, 10); 234 jPanel0.add(jRadioButton1, gridBagConstraints); 235 236 jComboBoxObject.setMinimumSize(new java.awt.Dimension (51, 22)); 237 jComboBoxObject.addActionListener(new java.awt.event.ActionListener () { 238 public void actionPerformed(java.awt.event.ActionEvent evt) { 239 jComboBoxObjectActionPerformed(evt); 240 } 241 }); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 0; 245 gridBagConstraints.gridy = 5; 246 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 247 gridBagConstraints.weightx = 1.0; 248 gridBagConstraints.insets = new java.awt.Insets (4, 40, 0, 10); 249 jPanel0.add(jComboBoxObject, gridBagConstraints); 250 251 buttonGroup1.add(jRadioButton2); 252 jRadioButton2.setText("Group by the following expression:"); 253 jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 254 jRadioButton2.setMargin(new java.awt.Insets (0, 0, 0, 0)); 255 jRadioButton2.addActionListener(new java.awt.event.ActionListener () { 256 public void actionPerformed(java.awt.event.ActionEvent evt) { 257 jRadioButton2ActionPerformed(evt); 258 } 259 }); 260 jRadioButton2.addPropertyChangeListener(new java.beans.PropertyChangeListener () { 261 public void propertyChange(java.beans.PropertyChangeEvent evt) { 262 jRadioButton2PropertyChange(evt); 263 } 264 }); 265 266 gridBagConstraints = new java.awt.GridBagConstraints (); 267 gridBagConstraints.gridx = 0; 268 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 269 gridBagConstraints.weightx = 1.0; 270 gridBagConstraints.insets = new java.awt.Insets (16, 24, 0, 10); 271 jPanel0.add(jRadioButton2, gridBagConstraints); 272 273 jRTextExpressionArea.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 274 jRTextExpressionArea.setElectricScroll(0); 275 jRTextExpressionArea.setMinimumSize(new java.awt.Dimension (300, 47)); 276 jRTextExpressionArea.setPreferredSize(new java.awt.Dimension (300, 120)); 277 gridBagConstraints = new java.awt.GridBagConstraints (); 278 gridBagConstraints.gridx = 0; 279 gridBagConstraints.gridwidth = 2; 280 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 281 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 282 gridBagConstraints.weightx = 1.0; 283 gridBagConstraints.insets = new java.awt.Insets (4, 40, 10, 6); 284 jPanel0.add(jRTextExpressionArea, gridBagConstraints); 285 286 jPanel1.setLayout(new java.awt.GridBagLayout ()); 287 288 jPanel1.addPropertyChangeListener(new java.beans.PropertyChangeListener () { 289 public void propertyChange(java.beans.PropertyChangeEvent evt) { 290 jPanel1PropertyChange(evt); 291 } 292 }); 293 294 jCheckBox1.setSelected(true); 295 jCheckBox1.setText("Add the group header"); 296 jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 297 jCheckBox1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 298 gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 300 gridBagConstraints.weightx = 1.0; 301 gridBagConstraints.insets = new java.awt.Insets (24, 24, 0, 24); 302 jPanel1.add(jCheckBox1, gridBagConstraints); 303 304 jCheckBox2.setSelected(true); 305 jCheckBox2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 306 jCheckBox2.setLabel("Add the group footer"); 307 jCheckBox2.setMargin(new java.awt.Insets (0, 0, 0, 0)); 308 gridBagConstraints = new java.awt.GridBagConstraints (); 309 gridBagConstraints.gridx = 0; 310 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 311 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 312 gridBagConstraints.weightx = 1.0; 313 gridBagConstraints.weighty = 1.0; 314 gridBagConstraints.insets = new java.awt.Insets (8, 24, 0, 24); 315 jPanel1.add(jCheckBox2, gridBagConstraints); 316 317 setLayout(new java.awt.BorderLayout ()); 318 319 } 321 private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) { if (wizardPanel != null) wizardPanel.updateButtons(); 323 } 325 private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) { if (wizardPanel != null) wizardPanel.updateButtons(); 327 328 } 330 private void jRadioButton2PropertyChange(java.beans.PropertyChangeEvent evt) { 332 } 334 private void jPanel1PropertyChange(java.beans.PropertyChangeEvent evt) { 336 } 338 private void jComboBoxObjectActionPerformed(java.awt.event.ActionEvent evt) { 340 if (wizardPanel != null) wizardPanel.updateButtons(); 341 } 343 344 private void jPanel0PropertyChange(java.beans.PropertyChangeEvent evt) { 346 347 348 } 350 351 private javax.swing.ButtonGroup buttonGroup1; 353 private javax.swing.JCheckBox jCheckBox1; 354 private javax.swing.JCheckBox jCheckBox2; 355 private javax.swing.JComboBox jComboBoxObject; 356 private javax.swing.JLabel jLabel1; 357 private javax.swing.JLabel jLabelErrorMessage; 358 private javax.swing.JPanel jPanel0; 359 private javax.swing.JPanel jPanel1; 360 private javax.swing.JPanel jPanel6; 361 private javax.swing.JPanel jPanel61; 362 private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionArea; 363 private javax.swing.JRadioButton jRadioButton1; 364 private javax.swing.JRadioButton jRadioButton2; 365 private javax.swing.JTextField jTextField1; 366 368 369 public String [] getStepsNames() { 370 371 String [] names = new String [2]; 372 names[0] = "Criteria"; 373 names[1] = "Details"; 374 375 return names; 376 } 377 378 public String getStepDescription(int step) { 379 380 if (step==0) return "Choose the group by criteria"; 381 if (step==1) return "Group details"; 382 return ""; 383 } 384 385 public void initWizard() { 386 } 388 389 public void finish(int currentStep) { 390 391 if (currentStep != -1) 392 { 393 Report report = getJReportFrame().getReport(); 394 Group grp = new Group(report, jTextField1.getText().trim()); 395 int available_vertical_space = report.getAvailableVerticalSpace(); 396 if (jCheckBox1.isSelected() && jCheckBox2.isSelected()) available_vertical_space /= 2; 397 if (available_vertical_space>50) available_vertical_space = 50; 398 399 if (jCheckBox1.isSelected()) grp.getGroupHeader().setHeight(available_vertical_space); 400 if (jCheckBox2.isSelected()) grp.getGroupFooter().setHeight(available_vertical_space); 401 402 if (jRadioButton1.isSelected()) 404 { 405 Object obj = jComboBoxObject.getSelectedItem(); 406 if (obj != null && (""+obj).trim().length() > 0) 407 { 408 if (obj instanceof it.businesslogic.ireport.JRParameter) 409 { 410 obj = "$P{" + obj + "}"; 411 } 412 else if (obj instanceof it.businesslogic.ireport.JRVariable) 413 { 414 obj = "$V{" + obj + "}"; 415 } 416 else if (obj instanceof it.businesslogic.ireport.JRField) 417 { 418 obj = "$F{" + obj + "}"; 419 } 420 421 grp.setGroupExpression( ""+obj); 422 } 423 } 424 else 425 { 426 grp.setGroupExpression( jRTextExpressionArea.getText().trim()); 427 428 } 429 430 431 report.addGroup(grp, true); 432 getJReportFrame().repaint(); 433 434 MainFrame.getMainInstance().getGroupsDialog().updateGroups(); 435 MainFrame.getMainInstance().getBandsDialog().updateBands(); 436 MainFrame.getMainInstance().getElementPropertiesDialog().updateBands(); 437 MainFrame.getMainInstance().getElementPropertiesDialog().updateGroups(); 438 MainFrame.getMainInstance().reportBandChanged( new ReportBandChangedEvent(this.getJReportFrame(), null, ReportBandChangedEvent.ADDED )); 439 } 440 441 this.getWizardDialog().setVisible(false); 442 this.getWizardDialog().dispose(); 443 } 444 445 public boolean nextStep(int nextStep) { 446 447 if (nextStep == 0) { 449 450 } 451 else if (nextStep == 1) 452 { 453 454 } 455 return true; 456 } 457 458 public boolean previousStep(int previousStep) { 459 return true; 460 } 461 462 public boolean canFinish(int currentStep) { 463 464 if (currentStep>0) return true; 465 else return canNext(currentStep); 466 } 467 468 public boolean canNext(int currentStep) { 469 470 if (currentStep == 0) 471 { 472 if (jTextField1.getText().trim().length() == 0) return false; 473 Vector v = getJReportFrame().getReport().getGroups(); 475 String s = jTextField1.getText().trim(); 476 jLabelErrorMessage.setText(" "); 477 for (int i=0; i<v.size(); ++i) 478 { 479 if (s.equals( ((Group)v.elementAt(i)).getName())) 480 { 481 jLabelErrorMessage.setText("This group name is already in use."); 482 return false; 483 } 484 } 485 486 if (jRadioButton1.isSelected() && jComboBoxObject.getSelectedItem() != null) return true; 487 if (jRadioButton2.isSelected() && jRTextExpressionArea.getText().trim().length() > 0) return true; 488 } 489 else if (currentStep == 1) 490 { 491 return false; 492 } 493 return false; 494 } 495 496 public boolean canPrevious(int currentStep) { 497 return (currentStep > 0); 498 } 499 500 public JPanel getStepPanel(int step) { 501 502 if (step == 0) return jPanel0; 503 if (step == 1) return jPanel1; 504 return null; 506 } 507 508 public String getReportFileName() { 509 return reportFileName; 510 } 511 512 public void setReportFileName(String reportFileName) { 513 this.reportFileName = reportFileName; 514 } 515 516 public SubReportElement getSubReportElement() { 517 return subReportElement; 518 } 519 520 public void setSubReportElement(SubReportElement subReportElement) { 521 this.subReportElement = subReportElement; 522 } 523 524 public BaseWizardPanel getWizardPanel() { 525 return wizardPanel; 526 } 527 528 public void setWizardPanel(BaseWizardPanel wizardPanel) { 529 this.wizardPanel = wizardPanel; 530 } 531 532 public javax.swing.JDialog getWizardDialog() { 533 return wizardDialog; 534 } 535 536 public void setWizardDialog(javax.swing.JDialog wizardDialog) { 537 this.wizardDialog = wizardDialog; 538 } 539 540 public JReportFrame getJReportFrame() { 541 return jReportFrame; 542 } 543 544 public void setJReportFrame(JReportFrame jReportFrame) { 545 this.jReportFrame = jReportFrame; 546 } 547 548 549 public void applyI18n(){ 550 jCheckBox1.setText(I18n.getString("reportGroupWizard.checkBox1","Add the group header")); 552 jRadioButton1.setText(I18n.getString("reportGroupWizard.radioButton1","Group by the following report object:")); 553 jRadioButton2.setText(I18n.getString("reportGroupWizard.radioButton2","Group by the following expression:")); 554 jLabel1.setText(I18n.getString("reportGroupWizard.label1","Group name")); 557 jLabelErrorMessage.setText(I18n.getString("reportGroupWizard.labelErrorMessage"," ")); 558 } 560 } 561 | Popular Tags |