1 32 33 package it.businesslogic.ireport.gui; 34 35 import it.businesslogic.ireport.*; 36 import it.businesslogic.ireport.gui.sheet.Tag; 37 import it.businesslogic.ireport.util.*; 38 39 40 43 public class JRVariableDialog 44 extends javax.swing.JDialog 45 { 46 47 48 JRVariable tmpVariable = null; 49 private SubDataset subDataset = null; 50 private String originalName = null; 51 52 59 public JRVariableDialog(SubDataset report, java.awt.Frame parent, 60 boolean modal) 61 { 62 super(parent, modal); 63 initComponents(); 64 65 this.setSubDataset(report); 66 updateGroups(); 67 68 this.jRTextExpressionAreaExpression.setText(""); 69 this.jRTextExpressionAreaInitialExpression.setText(""); 70 setTypes(); 71 this.jComboBoxClassType.setSelectedItem("java.lang.String"); 72 73 Misc.setComboboxSelectedTagValue( jComboBoxCalculationType, "Nothing" ); 74 Misc.setComboboxSelectedTagValue( jComboBoxResetType, "Report" ); 75 Misc.setComboboxSelectedTagValue( jComboBoxIncrementType, "None" ); 76 77 updateGroups(); 78 79 80 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 81 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 82 public void actionPerformed(java.awt.event.ActionEvent e) { 83 jButtonCancelActionPerformed(e); 84 } 85 }; 86 87 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 88 getRootPane().getActionMap().put("ESCAPE", escapeAction); 89 90 applyI18n(); 91 this.getRootPane().setDefaultButton(this.jButtonOK); 93 94 pack(); 95 } 96 97 100 public void setTypes() 101 { 102 this.jComboBoxClassType.addItem("java.lang.String"); 103 this.jComboBoxClassType.addItem("java.lang.Object"); 104 this.jComboBoxClassType.addItem("java.lang.Boolean"); 105 this.jComboBoxClassType.addItem("java.lang.Byte"); 106 this.jComboBoxClassType.addItem("java.util.Date"); 107 this.jComboBoxClassType.addItem("java.sql.Timestamp"); 108 this.jComboBoxClassType.addItem("java.sql.Time"); 109 this.jComboBoxClassType.addItem("java.lang.Double"); 110 this.jComboBoxClassType.addItem("java.lang.Float"); 111 this.jComboBoxClassType.addItem("java.lang.Integer"); 112 this.jComboBoxClassType.addItem("java.io.InputStream"); 113 this.jComboBoxClassType.addItem("java.lang.Long"); 114 this.jComboBoxClassType.addItem("java.lang.Short"); 115 this.jComboBoxClassType.addItem("java.math.BigDecimal"); 116 this.jComboBoxClassType.addItem( 117 "net.sf.jasperreports.engine.JREmptyDataSource"); 118 119 this.jComboBoxCalculationType.addItem(new Tag("Nothing", I18n.getString("variable.calculationType.Nothing", "Nothing") )); 120 this.jComboBoxCalculationType.addItem(new Tag("Count", I18n.getString("variable.calculationType.Count", "Count"))); 121 this.jComboBoxCalculationType.addItem(new Tag("DistinctCount", I18n.getString("variable.calculationType.DistinctCount", "Distinct count"))); 122 this.jComboBoxCalculationType.addItem(new Tag("Sum", I18n.getString("variable.calculationType.Sum", "Sum"))); 123 this.jComboBoxCalculationType.addItem(new Tag("Average", I18n.getString("variable.calculationType.Average", "Average"))); 124 this.jComboBoxCalculationType.addItem(new Tag("Lowest", I18n.getString("variable.calculationType.Lowest", "Lowest"))); 125 this.jComboBoxCalculationType.addItem(new Tag("Highest", I18n.getString("variable.calculationType.Highest", "Highest"))); 126 this.jComboBoxCalculationType.addItem(new Tag("StandardDeviation", I18n.getString("variable.calculationType.StandardDeviation", "Standard deviation"))); 127 this.jComboBoxCalculationType.addItem(new Tag("Variance", I18n.getString("variable.calculationType.Variance", "Variance") )); 128 this.jComboBoxCalculationType.addItem(new Tag("System", I18n.getString("variable.calculationType.System", "System") )); 129 this.jComboBoxCalculationType.addItem(new Tag("First", I18n.getString("variable.calculationType.First", "First") )); 130 131 this.jComboBoxResetType.addItem(new Tag("None",it.businesslogic.ireport.util.I18n.getString("resetType.None","None"))); 132 this.jComboBoxResetType.addItem(new Tag("Report",it.businesslogic.ireport.util.I18n.getString("resetType.Report","Report"))); 133 this.jComboBoxResetType.addItem(new Tag("Page",it.businesslogic.ireport.util.I18n.getString("resetType.Page","Page"))); 134 this.jComboBoxResetType.addItem(new Tag("Column",it.businesslogic.ireport.util.I18n.getString("resetType.Column","Column"))); 135 this.jComboBoxResetType.addItem(new Tag("Group",it.businesslogic.ireport.util.I18n.getString("resetType.Group","Group"))); 136 137 this.jComboBoxIncrementType.addItem(new Tag("None",it.businesslogic.ireport.util.I18n.getString("incrementType.None","None"))); 138 this.jComboBoxIncrementType.addItem(new Tag("Report",it.businesslogic.ireport.util.I18n.getString("incrementType.Report","Report"))); 139 this.jComboBoxIncrementType.addItem(new Tag("Page",it.businesslogic.ireport.util.I18n.getString("incrementType.Page","Page"))); 140 this.jComboBoxIncrementType.addItem(new Tag("Column",it.businesslogic.ireport.util.I18n.getString("incrementType.Column","Column"))); 141 this.jComboBoxIncrementType.addItem(new Tag("Group",it.businesslogic.ireport.util.I18n.getString("incrementType.Group","Group"))); 142 143 } 144 145 148 public void updateGroups() 149 { 150 151 if (getSubDataset() == null) 152 { 153 jComboBoxResetGroup.removeAllItems(); 154 jComboBoxResetGroup.addItem(""); 155 } 156 else 157 { 158 Misc.updateStringComboBox(jComboBoxResetGroup, 159 getSubDataset().getGroups(), false); 160 Misc.updateStringComboBox(jComboBoxIncrementGroup, 161 getSubDataset().getGroups(), false); 162 } 163 164 } 165 166 171 172 173 private void initComponents() { 175 java.awt.GridBagConstraints gridBagConstraints; 176 177 jLabel1 = new javax.swing.JLabel (); 178 jTextFieldName = new javax.swing.JTextField (); 179 jLabel2 = new javax.swing.JLabel (); 180 jComboBoxResetGroup = new javax.swing.JComboBox (); 181 jLabel3 = new javax.swing.JLabel (); 182 jLabel4 = new javax.swing.JLabel (); 183 jLabel5 = new javax.swing.JLabel (); 184 jComboBoxResetType = new javax.swing.JComboBox (); 185 jComboBoxCalculationType = new javax.swing.JComboBox (); 186 jLabel6 = new javax.swing.JLabel (); 187 jComboBoxClassType = new javax.swing.JComboBox (); 188 jLabel7 = new javax.swing.JLabel (); 189 jRTextExpressionAreaExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea(); 190 jRTextExpressionAreaInitialExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea(); 191 jLabel8 = new javax.swing.JLabel (); 192 jTextFieldNameIncrementerFactoryClass = new javax.swing.JTextField (); 193 jPanel1 = new javax.swing.JPanel (); 194 jButtonOK = new javax.swing.JButton (); 195 jButtonCancel = new javax.swing.JButton (); 196 jLabel9 = new javax.swing.JLabel (); 197 jLabel10 = new javax.swing.JLabel (); 198 jComboBoxIncrementType = new javax.swing.JComboBox (); 199 jComboBoxIncrementGroup = new javax.swing.JComboBox (); 200 201 getContentPane().setLayout(new java.awt.GridBagLayout ()); 202 203 setTitle("Add/modify variable"); 204 setModal(true); 205 addWindowListener(new java.awt.event.WindowAdapter () { 206 public void windowClosing(java.awt.event.WindowEvent evt) { 207 closeDialog(evt); 208 } 209 }); 210 211 jLabel1.setText("Variable name"); 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 0; 214 gridBagConstraints.gridy = 0; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 216 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 217 getContentPane().add(jLabel1, gridBagConstraints); 218 219 gridBagConstraints = new java.awt.GridBagConstraints (); 220 gridBagConstraints.gridx = 0; 221 gridBagConstraints.gridy = 1; 222 gridBagConstraints.gridwidth = 3; 223 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 224 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 225 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 226 getContentPane().add(jTextFieldName, gridBagConstraints); 227 228 jLabel2.setText("Calculation type"); 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 1; 231 gridBagConstraints.gridy = 2; 232 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 233 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 234 getContentPane().add(jLabel2, gridBagConstraints); 235 236 gridBagConstraints = new java.awt.GridBagConstraints (); 237 gridBagConstraints.gridx = 1; 238 gridBagConstraints.gridy = 5; 239 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 240 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 241 gridBagConstraints.weightx = 1.0; 242 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 243 getContentPane().add(jComboBoxResetGroup, gridBagConstraints); 244 245 jLabel3.setText("Variable expression"); 246 gridBagConstraints = new java.awt.GridBagConstraints (); 247 gridBagConstraints.gridx = 0; 248 gridBagConstraints.gridy = 10; 249 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 250 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 251 getContentPane().add(jLabel3, gridBagConstraints); 252 253 jLabel4.setText("Initial value expression"); 254 gridBagConstraints = new java.awt.GridBagConstraints (); 255 gridBagConstraints.gridx = 0; 256 gridBagConstraints.gridy = 12; 257 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 258 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 259 getContentPane().add(jLabel4, gridBagConstraints); 260 261 jLabel5.setText("Variable class type"); 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 0; 264 gridBagConstraints.gridy = 2; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 266 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 267 getContentPane().add(jLabel5, gridBagConstraints); 268 269 jComboBoxResetType.addActionListener(new java.awt.event.ActionListener () { 270 public void actionPerformed(java.awt.event.ActionEvent evt) { 271 jComboBoxResetTypeActionPerformed(evt); 272 } 273 }); 274 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 0; 277 gridBagConstraints.gridy = 5; 278 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 279 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 280 gridBagConstraints.weightx = 1.0; 281 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 282 getContentPane().add(jComboBoxResetType, gridBagConstraints); 283 284 gridBagConstraints = new java.awt.GridBagConstraints (); 285 gridBagConstraints.gridx = 1; 286 gridBagConstraints.gridy = 3; 287 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 288 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 289 gridBagConstraints.weightx = 1.0; 290 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 291 getContentPane().add(jComboBoxCalculationType, gridBagConstraints); 292 293 jLabel6.setText("Reset group"); 294 gridBagConstraints = new java.awt.GridBagConstraints (); 295 gridBagConstraints.gridx = 1; 296 gridBagConstraints.gridy = 4; 297 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 298 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 299 getContentPane().add(jLabel6, gridBagConstraints); 300 301 jComboBoxClassType.setEditable(true); 302 gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.gridx = 0; 304 gridBagConstraints.gridy = 3; 305 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 306 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 307 gridBagConstraints.weightx = 1.0; 308 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 309 getContentPane().add(jComboBoxClassType, gridBagConstraints); 310 311 jLabel7.setText("Reset type"); 312 gridBagConstraints = new java.awt.GridBagConstraints (); 313 gridBagConstraints.gridx = 0; 314 gridBagConstraints.gridy = 4; 315 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 316 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 317 getContentPane().add(jLabel7, gridBagConstraints); 318 319 jRTextExpressionAreaExpression.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 320 jRTextExpressionAreaExpression.setCaretVisible(false); 321 jRTextExpressionAreaExpression.setElectricScroll(0); 322 jRTextExpressionAreaExpression.setMinimumSize(new java.awt.Dimension (657, 100)); 323 jRTextExpressionAreaExpression.setNextFocusableComponent(jRTextExpressionAreaInitialExpression); 324 jRTextExpressionAreaExpression.setPreferredSize(new java.awt.Dimension (325, 70)); 325 gridBagConstraints = new java.awt.GridBagConstraints (); 326 gridBagConstraints.gridx = 0; 327 gridBagConstraints.gridy = 11; 328 gridBagConstraints.gridwidth = 2; 329 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 330 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 331 gridBagConstraints.weightx = 1.0; 332 gridBagConstraints.weighty = 1.0; 333 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 334 getContentPane().add(jRTextExpressionAreaExpression, gridBagConstraints); 335 336 jRTextExpressionAreaInitialExpression.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 337 jRTextExpressionAreaInitialExpression.setCaretVisible(false); 338 jRTextExpressionAreaInitialExpression.setElectricScroll(0); 339 jRTextExpressionAreaInitialExpression.setFont(new java.awt.Font ("Tahoma", 0, 12)); 340 jRTextExpressionAreaInitialExpression.setMinimumSize(new java.awt.Dimension (657, 100)); 341 jRTextExpressionAreaInitialExpression.setPreferredSize(new java.awt.Dimension (325, 70)); 342 gridBagConstraints = new java.awt.GridBagConstraints (); 343 gridBagConstraints.gridx = 0; 344 gridBagConstraints.gridy = 13; 345 gridBagConstraints.gridwidth = 2; 346 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 347 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 348 gridBagConstraints.weightx = 1.0; 349 gridBagConstraints.weighty = 1.0; 350 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 351 getContentPane().add(jRTextExpressionAreaInitialExpression, gridBagConstraints); 352 353 jLabel8.setText("Custom Incrementer Factory Class"); 354 gridBagConstraints = new java.awt.GridBagConstraints (); 355 gridBagConstraints.gridx = 0; 356 gridBagConstraints.gridy = 8; 357 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 358 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 359 getContentPane().add(jLabel8, gridBagConstraints); 360 361 jTextFieldNameIncrementerFactoryClass.setNextFocusableComponent(jRTextExpressionAreaExpression); 362 gridBagConstraints = new java.awt.GridBagConstraints (); 363 gridBagConstraints.gridx = 0; 364 gridBagConstraints.gridy = 9; 365 gridBagConstraints.gridwidth = 2; 366 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 367 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 368 gridBagConstraints.weightx = 1.0; 369 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 370 getContentPane().add(jTextFieldNameIncrementerFactoryClass, gridBagConstraints); 371 372 jPanel1.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.RIGHT)); 373 374 jButtonOK.setMnemonic('o'); 375 jButtonOK.setText("OK"); 376 jButtonOK.addActionListener(new java.awt.event.ActionListener () { 377 public void actionPerformed(java.awt.event.ActionEvent evt) { 378 jButtonOKActionPerformed(evt); 379 } 380 }); 381 382 jPanel1.add(jButtonOK); 383 384 jButtonCancel.setText("Cancel"); 385 jButtonCancel.setMnemonic('c'); 386 jButtonCancel.addActionListener(new java.awt.event.ActionListener () { 387 public void actionPerformed(java.awt.event.ActionEvent evt) { 388 jButtonCancelActionPerformed(evt); 389 } 390 }); 391 392 jPanel1.add(jButtonCancel); 393 394 gridBagConstraints = new java.awt.GridBagConstraints (); 395 gridBagConstraints.gridx = 0; 396 gridBagConstraints.gridy = 14; 397 gridBagConstraints.gridwidth = 3; 398 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 399 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 400 gridBagConstraints.weightx = 1.0; 401 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 402 getContentPane().add(jPanel1, gridBagConstraints); 403 404 jLabel9.setText("Increment type"); 405 gridBagConstraints = new java.awt.GridBagConstraints (); 406 gridBagConstraints.gridx = 0; 407 gridBagConstraints.gridy = 6; 408 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 409 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 410 getContentPane().add(jLabel9, gridBagConstraints); 411 412 jLabel10.setText("Increment group"); 413 gridBagConstraints = new java.awt.GridBagConstraints (); 414 gridBagConstraints.gridx = 1; 415 gridBagConstraints.gridy = 6; 416 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 417 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 418 getContentPane().add(jLabel10, gridBagConstraints); 419 420 jComboBoxIncrementType.addActionListener(new java.awt.event.ActionListener () { 421 public void actionPerformed(java.awt.event.ActionEvent evt) { 422 jComboBoxIncrementTypeActionPerformed(evt); 423 } 424 }); 425 426 gridBagConstraints = new java.awt.GridBagConstraints (); 427 gridBagConstraints.gridx = 0; 428 gridBagConstraints.gridy = 7; 429 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 430 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 431 gridBagConstraints.weightx = 1.0; 432 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 433 getContentPane().add(jComboBoxIncrementType, gridBagConstraints); 434 435 gridBagConstraints = new java.awt.GridBagConstraints (); 436 gridBagConstraints.gridx = 1; 437 gridBagConstraints.gridy = 7; 438 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 439 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 440 gridBagConstraints.weightx = 1.0; 441 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 442 getContentPane().add(jComboBoxIncrementGroup, gridBagConstraints); 443 444 pack(); 445 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 446 java.awt.Dimension dialogSize = getSize(); 447 setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); 448 } 450 private void jComboBoxIncrementTypeActionPerformed(java.awt.event.ActionEvent evt) { 452 Object t = jComboBoxIncrementType.getSelectedItem(); 453 String val = t+""; 454 455 if (t != null && t instanceof Tag) 456 { 457 val = ""+((Tag)t).getValue(); 458 } 459 460 jComboBoxIncrementGroup.setEnabled( val.equals("Group") ); 461 462 if (jComboBoxIncrementGroup.isEnabled() && 463 jComboBoxIncrementGroup.getSelectedItem() == null && 464 jComboBoxIncrementGroup.getItemCount() > 0) 465 { 466 jComboBoxIncrementGroup.setSelectedIndex(0); 467 } 468 } 470 private void jComboBoxResetTypeActionPerformed(java.awt.event.ActionEvent evt) { 472 Object t = jComboBoxResetType.getSelectedItem(); 473 String val = t+""; 474 475 if (t != null && t instanceof Tag) 476 { 477 val = ""+((Tag)t).getValue(); 478 } 479 480 481 jComboBoxResetGroup.setEnabled( val.equals("Group") ); 482 483 if (jComboBoxResetGroup.isEnabled() && 484 jComboBoxResetGroup.getSelectedItem() == null && 485 jComboBoxResetGroup.getItemCount() > 0) 486 { 487 jComboBoxResetGroup.setSelectedIndex(0); 488 } 489 490 } private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) { 493 setVisible(false); 494 this.setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION); 495 dispose(); 496 } 498 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) { 500 501 if (this.jTextFieldName.getText().trim().length() <= 0) 502 { 503 javax.swing.JOptionPane.showMessageDialog(this, 504 I18n.getString( "messages.jRVariableDialog.notValidName","Please insert a valid variable name!"), 505 I18n.getString( "messages.jRVariableDialog.notValidNameCaption","Invalid variable!"), 506 javax.swing.JOptionPane.WARNING_MESSAGE); 507 508 return; 509 } 510 511 tmpVariable = new JRVariable(this.jTextFieldName.getText(), false); 512 tmpVariable.setClassType( 513 this.jComboBoxClassType.getSelectedItem() + ""); 514 515 Object t = this.jComboBoxCalculationType.getSelectedItem(); 516 if (t != null && t instanceof Tag) tmpVariable.setCalculation( ((Tag)t).getValue()+"" ); 517 518 t = this.jComboBoxResetType.getSelectedItem(); 519 if (t != null && t instanceof Tag) tmpVariable.setResetType( ((Tag)t).getValue()+"" ); 520 521 522 t = this.jComboBoxIncrementType.getSelectedItem(); 523 if (t != null && t instanceof Tag) tmpVariable.setIncrementType( ((Tag)t).getValue()+"" ); 524 525 526 tmpVariable.setIncrementerFactoryClass(this.jTextFieldNameIncrementerFactoryClass.getText()); 528 529 if (this.jComboBoxClassType.getSelectedItem().toString().trim().length() == 0) 530 { 531 tmpVariable.setClassType("java.lang.String"); 532 } 533 534 else 535 { 536 tmpVariable.setClassType(this.jComboBoxClassType.getSelectedItem().toString().trim()); 537 } 538 539 if (tmpVariable.getResetType().equals("Group")) 540 { 541 542 if (this.jComboBoxResetGroup.getSelectedItem() == null || 543 this.jComboBoxResetGroup.getSelectedItem().equals("")) 544 { 545 javax.swing.JOptionPane.showMessageDialog(this, 546 I18n.getString( "messages.jRVariableDialog.notValidGroup","Please choose a valid group for the reset type selected!"), 547 I18n.getString( "messages.jRVariableDialog.notValidGroupCaption","Invalid group!"), 548 javax.swing.JOptionPane.WARNING_MESSAGE); 549 550 return; 551 } 552 553 tmpVariable.setResetGroup( 554 this.jComboBoxResetGroup.getSelectedItem() + ""); 555 } 556 557 if (tmpVariable.getIncrementType().equals("Group")) 558 { 559 560 if (this.jComboBoxIncrementGroup.getSelectedItem() == null || 561 this.jComboBoxIncrementGroup.getSelectedItem().equals("")) 562 { 563 javax.swing.JOptionPane.showMessageDialog(this, 564 I18n.getString( "messages.jRVariableDialog.notValidGroupIncrementType","Please choose a valid group for the increment type selected!"), 565 I18n.getString( "messages.jRVariableDialog.notValidGroupIncrementTypeCaption","Invalid group!"), 566 javax.swing.JOptionPane.WARNING_MESSAGE); 567 568 return; 569 } 570 571 tmpVariable.setIncrementGroup( 572 this.jComboBoxIncrementGroup.getSelectedItem() + ""); 573 } 574 575 if (getSubDataset() != null) 576 { 577 String newName = this.jTextFieldName.getText(); 579 if (getOriginalName() == null || !getOriginalName().equals(newName)) 580 { 581 for (int i=0; i< getSubDataset().getVariables().size(); ++i) 582 { 583 JRVariable f = (JRVariable)getSubDataset().getVariables().get(i); 584 if (f.getName().equals(newName)) 585 { 586 javax.swing.JOptionPane.showMessageDialog(this, 587 I18n.getString( "messages.JRVariableDialog.DuplicatedVariableName","A variable with this name already exists!"), 588 I18n.getString( "messages.JRVariableDialog.notValidVariableNameCaption","Invalid variable!"), 589 javax.swing.JOptionPane.WARNING_MESSAGE ); 590 return; 591 } 592 } 593 } 594 } 595 596 tmpVariable.setExpression(jRTextExpressionAreaExpression.getText()); 597 598 tmpVariable.setInitialValueExpression(jRTextExpressionAreaInitialExpression.getText()); 599 600 setVisible(false); 601 this.setDialogResult(javax.swing.JOptionPane.OK_OPTION); 602 dispose(); 603 } 605 609 private void closeDialog(java.awt.event.WindowEvent evt) { 611 setVisible(false); 612 this.setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION); 613 dispose(); 614 } 616 619 public static void main(String [] args) 620 { 621 new JRParameterDialog(new javax.swing.JFrame (), true).setVisible(true); 622 } 623 624 629 public it.businesslogic.ireport.JRVariable getVariable() 630 { 631 632 return tmpVariable; 633 } 634 635 640 public void setVariable(it.businesslogic.ireport.JRVariable tmpVariable) 641 { 642 originalName = tmpVariable.getName(); 643 this.jTextFieldName.setText(new String (tmpVariable.getName())); 644 645 this.jComboBoxClassType.setSelectedItem(new String (tmpVariable.getClassType())); 646 647 Misc.setComboboxSelectedTagValue( jComboBoxResetType, tmpVariable.getResetType() ); 648 Misc.setComboboxSelectedTagValue( jComboBoxIncrementType, tmpVariable.getIncrementType() ); 649 Misc.setComboboxSelectedTagValue( jComboBoxCalculationType, tmpVariable.getCalculation() ); 650 651 this.jComboBoxResetGroup.setSelectedItem(tmpVariable.getResetGroup()); 652 this.jComboBoxIncrementGroup.setSelectedItem(tmpVariable.getIncrementGroup()); 653 654 this.jRTextExpressionAreaExpression.setText(new String (tmpVariable.getExpression())); 655 this.jRTextExpressionAreaInitialExpression.setText(new String (tmpVariable.getInitialValueExpression())); 656 this.jTextFieldNameIncrementerFactoryClass.setText(new String (tmpVariable.getIncrementerFactoryClass())); 657 } 658 659 664 public int getDialogResult() 665 { 666 667 return dialogResult; 668 } 669 670 675 public void setDialogResult(int dialogResult) 676 { 677 this.dialogResult = dialogResult; 678 } 679 680 681 private javax.swing.JButton jButtonCancel; 683 private javax.swing.JButton jButtonOK; 684 private javax.swing.JComboBox jComboBoxCalculationType; 685 private javax.swing.JComboBox jComboBoxClassType; 686 private javax.swing.JComboBox jComboBoxIncrementGroup; 687 private javax.swing.JComboBox jComboBoxIncrementType; 688 private javax.swing.JComboBox jComboBoxResetGroup; 689 private javax.swing.JComboBox jComboBoxResetType; 690 private javax.swing.JLabel jLabel1; 691 private javax.swing.JLabel jLabel10; 692 private javax.swing.JLabel jLabel2; 693 private javax.swing.JLabel jLabel3; 694 private javax.swing.JLabel jLabel4; 695 private javax.swing.JLabel jLabel5; 696 private javax.swing.JLabel jLabel6; 697 private javax.swing.JLabel jLabel7; 698 private javax.swing.JLabel jLabel8; 699 private javax.swing.JLabel jLabel9; 700 private javax.swing.JPanel jPanel1; 701 private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaExpression; 702 private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaInitialExpression; 703 private javax.swing.JTextField jTextFieldName; 704 private javax.swing.JTextField jTextFieldNameIncrementerFactoryClass; 705 private int dialogResult; 707 708 public SubDataset getSubDataset() { 709 return subDataset; 710 } 711 712 public void setSubDataset(SubDataset subDataset) { 713 this.subDataset = subDataset; 714 jRTextExpressionAreaExpression.setSubDataset( subDataset); 715 jRTextExpressionAreaInitialExpression.setSubDataset( subDataset); 716 jRTextExpressionAreaExpression.getTokenMarker().setKeywordLookup(subDataset.getKeywordLookup()); 717 jRTextExpressionAreaInitialExpression.getTokenMarker().setKeywordLookup(subDataset.getKeywordLookup()); 718 } 719 public void applyI18n(){ 720 jButtonCancel.setText(I18n.getString("jRVariableDialog.buttonCancel","Cancel")); 722 jButtonOK.setText(I18n.getString("jRVariableDialog.buttonOK","OK")); 723 jLabel1.setText(I18n.getString("jRVariableDialog.label1","Variable name")); 724 jLabel10.setText(I18n.getString("jRVariableDialog.label10","Increment group")); 725 jLabel2.setText(I18n.getString("jRVariableDialog.label2","Calculation type")); 726 jLabel3.setText(I18n.getString("jRVariableDialog.label3","Variable expression")); 727 jLabel4.setText(I18n.getString("jRVariableDialog.label4","Initial value expression")); 728 jLabel5.setText(I18n.getString("jRVariableDialog.label5","Variable class type")); 729 jLabel6.setText(I18n.getString("jRVariableDialog.label6","Reset group")); 730 jLabel7.setText(I18n.getString("jRVariableDialog.label7","Reset type")); 731 jLabel8.setText(I18n.getString("jRVariableDialog.label8","Custom Incrementer Factory Class")); 732 jLabel9.setText(I18n.getString("jRVariableDialog.label9","Increment type")); 733 } 735 736 public String getOriginalName() { 737 return originalName; 738 } 739 740 public void setOriginalName(String originalName) { 741 this.originalName = originalName; 742 } 743 } 744 | Popular Tags |