001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * SubreportWizardExistingReport.java
028: *
029: * Created on March 22, 2006, 8:52 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.wizard;
034:
035: import it.businesslogic.ireport.JRSubreportParameter;
036: import it.businesslogic.ireport.Report;
037: import it.businesslogic.ireport.SubReportElement;
038: import it.businesslogic.ireport.gui.MainFrame;
039: import it.businesslogic.ireport.util.Misc;
040: import java.io.File;
041: import java.util.Vector;
042: import javax.swing.JComboBox;
043: import javax.swing.JOptionPane;
044: import javax.swing.JPanel;
045: import javax.swing.event.DocumentEvent;
046: import javax.swing.event.DocumentListener;
047: import javax.swing.table.TableColumn;
048: import net.sf.jasperreports.engine.JRParameter;
049: import net.sf.jasperreports.engine.JasperReport;
050: import net.sf.jasperreports.engine.design.JasperDesign;
051: import it.businesslogic.ireport.util.I18n;
052: import javax.swing.SwingUtilities;
053:
054: /**
055: *
056: * @author gtoffoli
057: */
058: public class SubreportWizardExistingReport extends javax.swing.JPanel
059: implements GenericWizard {
060:
061: private String reportFileName = null;
062: private SubReportElement subReportElement = null;
063: private BaseWizardPanel wizardPanel = null;
064: private javax.swing.JDialog wizardDialog = null;
065:
066: /** Creates new form SubreportWizardPanes */
067: public SubreportWizardExistingReport() {
068: initComponents();
069: applyI18n();
070: jRTextExpressionAreaConnectionExpression.getDocument()
071: .addDocumentListener(new DocumentListener() {
072: public void changedUpdate(DocumentEvent e) {
073: if (wizardPanel != null)
074: wizardPanel.updateButtons();
075: }
076:
077: public void insertUpdate(DocumentEvent e) {
078: if (wizardPanel != null)
079: wizardPanel.updateButtons();
080: }
081:
082: public void removeUpdate(DocumentEvent e) {
083: if (wizardPanel != null)
084: wizardPanel.updateButtons();
085: }
086: });
087:
088: jRTextExpressionAreaDataSourceExpression.getDocument()
089: .addDocumentListener(new DocumentListener() {
090: public void changedUpdate(DocumentEvent e) {
091: if (wizardPanel != null)
092: wizardPanel.updateButtons();
093: }
094:
095: public void insertUpdate(DocumentEvent e) {
096: if (wizardPanel != null)
097: wizardPanel.updateButtons();
098: }
099:
100: public void removeUpdate(DocumentEvent e) {
101: if (wizardPanel != null)
102: wizardPanel.updateButtons();
103: }
104: });
105:
106: // These are the combobox values
107: Vector values = new Vector();
108:
109: Report report = MainFrame.getMainInstance()
110: .getActiveReportFrame().getReport();
111:
112: values.addAll(report.getFields());
113: values.addAll(report.getVariables());
114: values.addAll(report.getParameters());
115: jTableParameters.setRowHeight(20);
116:
117: TableColumn col = jTableParameters.getColumnModel()
118: .getColumn(1);
119: TableComboBoxEditor tcb = new TableComboBoxEditor(values);
120: ((JComboBox) tcb.getComponent()).setEditable(true);
121: col.setCellEditor(tcb);
122:
123: // If the cell should appear like a combobox in its
124: // non-editing state, also set the combobox renderer
125: //col.setCellRenderer(new TableComboBoxRenderer(values));
126:
127: }
128:
129: /** This method is called from within the constructor to
130: * initialize the form.
131: * WARNING: Do NOT modify this code. The content of this method is
132: * always regenerated by the Form Editor.
133: */
134: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
135: private void initComponents() {
136: java.awt.GridBagConstraints gridBagConstraints;
137:
138: jPanel0 = new javax.swing.JPanel();
139: jRadioButton1 = new javax.swing.JRadioButton();
140: jRadioButton2 = new javax.swing.JRadioButton();
141: jRTextExpressionAreaConnectionExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
142: jRadioButton3 = new javax.swing.JRadioButton();
143: jRTextExpressionAreaDataSourceExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
144: jRadioButton6 = new javax.swing.JRadioButton();
145: buttonGroup1 = new javax.swing.ButtonGroup();
146: jPanel1 = new javax.swing.JPanel();
147: jScrollPane1 = new javax.swing.JScrollPane();
148: jTableParameters = new javax.swing.JTable();
149: jPanel2 = new javax.swing.JPanel();
150: jRadioButton4 = new javax.swing.JRadioButton();
151: jLabel1 = new javax.swing.JLabel();
152: jRadioButton5 = new javax.swing.JRadioButton();
153: jLabel2 = new javax.swing.JLabel();
154: jPanel3 = new javax.swing.JPanel();
155: jLabel3 = new javax.swing.JLabel();
156: buttonGroup2 = new javax.swing.ButtonGroup();
157:
158: jPanel0.setLayout(new java.awt.GridBagLayout());
159:
160: jPanel0
161: .addPropertyChangeListener(new java.beans.PropertyChangeListener() {
162: public void propertyChange(
163: java.beans.PropertyChangeEvent evt) {
164: jPanel0PropertyChange(evt);
165: }
166: });
167:
168: buttonGroup1.add(jRadioButton1);
169: jRadioButton1.setSelected(true);
170: jRadioButton1
171: .setText("Use the same connection used to fill the master report");
172: jRadioButton1.setBorder(javax.swing.BorderFactory
173: .createEmptyBorder(0, 0, 0, 0));
174: jRadioButton1.setFocusPainted(false);
175: jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
176: jRadioButton1.setMinimumSize(new java.awt.Dimension(115, 20));
177: jRadioButton1.setPreferredSize(new java.awt.Dimension(115, 20));
178: jRadioButton1
179: .addItemListener(new java.awt.event.ItemListener() {
180: public void itemStateChanged(
181: java.awt.event.ItemEvent evt) {
182: jRadioButton1ItemStateChanged(evt);
183: }
184: });
185: jRadioButton1
186: .addActionListener(new java.awt.event.ActionListener() {
187: public void actionPerformed(
188: java.awt.event.ActionEvent evt) {
189: jRadioButton1ActionPerformed(evt);
190: }
191: });
192:
193: gridBagConstraints = new java.awt.GridBagConstraints();
194: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
196: gridBagConstraints.weightx = 1.0;
197: gridBagConstraints.insets = new java.awt.Insets(4, 20, 0, 0);
198: jPanel0.add(jRadioButton1, gridBagConstraints);
199:
200: buttonGroup1.add(jRadioButton2);
201: jRadioButton2.setText("Use another connection");
202: jRadioButton2.setBorder(javax.swing.BorderFactory
203: .createEmptyBorder(0, 0, 0, 0));
204: jRadioButton2.setFocusPainted(false);
205: jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
206: jRadioButton2.setMinimumSize(new java.awt.Dimension(115, 20));
207: jRadioButton2.setPreferredSize(new java.awt.Dimension(115, 20));
208: jRadioButton2
209: .addItemListener(new java.awt.event.ItemListener() {
210: public void itemStateChanged(
211: java.awt.event.ItemEvent evt) {
212: jRadioButton1ItemStateChanged1(evt);
213: }
214: });
215: jRadioButton2
216: .addActionListener(new java.awt.event.ActionListener() {
217: public void actionPerformed(
218: java.awt.event.ActionEvent evt) {
219: jRadioButton1ActionPerformed1(evt);
220: }
221: });
222:
223: gridBagConstraints = new java.awt.GridBagConstraints();
224: gridBagConstraints.gridx = 0;
225: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
226: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
227: gridBagConstraints.weightx = 1.0;
228: gridBagConstraints.insets = new java.awt.Insets(10, 20, 0, 0);
229: jPanel0.add(jRadioButton2, gridBagConstraints);
230:
231: jRTextExpressionAreaConnectionExpression
232: .setBorder(javax.swing.BorderFactory
233: .createEtchedBorder());
234: jRTextExpressionAreaConnectionExpression.setElectricScroll(0);
235: jRTextExpressionAreaConnectionExpression
236: .setMinimumSize(new java.awt.Dimension(300, 47));
237: jRTextExpressionAreaConnectionExpression
238: .setPreferredSize(new java.awt.Dimension(300, 47));
239: gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.gridx = 0;
241: gridBagConstraints.gridwidth = 2;
242: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
243: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
244: gridBagConstraints.weightx = 1.0;
245: gridBagConstraints.insets = new java.awt.Insets(1, 40, 0, 6);
246: jPanel0.add(jRTextExpressionAreaConnectionExpression,
247: gridBagConstraints);
248:
249: buttonGroup1.add(jRadioButton3);
250: jRadioButton3.setText("Use a JRDataSource expression");
251: jRadioButton3.setBorder(javax.swing.BorderFactory
252: .createEmptyBorder(0, 0, 0, 0));
253: jRadioButton3.setFocusPainted(false);
254: jRadioButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
255: jRadioButton3.setPreferredSize(new java.awt.Dimension(129, 20));
256: jRadioButton3
257: .addItemListener(new java.awt.event.ItemListener() {
258: public void itemStateChanged(
259: java.awt.event.ItemEvent evt) {
260: jRadioButton3ItemStateChanged(evt);
261: }
262: });
263:
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.gridx = 0;
266: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
267: gridBagConstraints.weightx = 1.0;
268: gridBagConstraints.insets = new java.awt.Insets(10, 20, 0, 0);
269: jPanel0.add(jRadioButton3, gridBagConstraints);
270:
271: jRTextExpressionAreaDataSourceExpression
272: .setBorder(javax.swing.BorderFactory
273: .createEtchedBorder());
274: jRTextExpressionAreaDataSourceExpression.setElectricScroll(0);
275: jRTextExpressionAreaDataSourceExpression
276: .setMinimumSize(new java.awt.Dimension(300, 47));
277: jRTextExpressionAreaDataSourceExpression
278: .setPreferredSize(new java.awt.Dimension(300, 47));
279: gridBagConstraints = new java.awt.GridBagConstraints();
280: gridBagConstraints.gridx = 0;
281: gridBagConstraints.gridwidth = 2;
282: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
283: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
284: gridBagConstraints.weightx = 1.0;
285: gridBagConstraints.insets = new java.awt.Insets(1, 40, 0, 6);
286: jPanel0.add(jRTextExpressionAreaDataSourceExpression,
287: gridBagConstraints);
288:
289: buttonGroup1.add(jRadioButton6);
290: jRadioButton6
291: .setText("Do not use any connection or datasource");
292: jRadioButton6.setBorder(javax.swing.BorderFactory
293: .createEmptyBorder(0, 0, 0, 0));
294: jRadioButton6.setFocusPainted(false);
295: jRadioButton6.setMargin(new java.awt.Insets(0, 0, 0, 0));
296: jRadioButton6.setMinimumSize(new java.awt.Dimension(129, 20));
297: jRadioButton6.setPreferredSize(new java.awt.Dimension(129, 20));
298: jRadioButton6
299: .addItemListener(new java.awt.event.ItemListener() {
300: public void itemStateChanged(
301: java.awt.event.ItemEvent evt) {
302: jRadioButton3ItemStateChanged1(evt);
303: }
304: });
305:
306: gridBagConstraints = new java.awt.GridBagConstraints();
307: gridBagConstraints.gridx = 0;
308: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
309: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
310: gridBagConstraints.weightx = 1.0;
311: gridBagConstraints.weighty = 1.0;
312: gridBagConstraints.insets = new java.awt.Insets(10, 20, 0, 0);
313: jPanel0.add(jRadioButton6, gridBagConstraints);
314:
315: jPanel1.setLayout(new java.awt.GridBagLayout());
316:
317: jTableParameters
318: .setModel(new javax.swing.table.DefaultTableModel(
319: new Object[][] {
320:
321: }, new String[] { "Parameter name",
322: "Expression" }) {
323: boolean[] canEdit = new boolean[] { false, true };
324:
325: public boolean isCellEditable(int rowIndex,
326: int columnIndex) {
327: return canEdit[columnIndex];
328: }
329: });
330: jScrollPane1.setViewportView(jTableParameters);
331:
332: gridBagConstraints = new java.awt.GridBagConstraints();
333: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
334: gridBagConstraints.weightx = 1.0;
335: gridBagConstraints.weighty = 1.0;
336: jPanel1.add(jScrollPane1, gridBagConstraints);
337:
338: jPanel2.setLayout(new java.awt.GridBagLayout());
339:
340: buttonGroup2.add(jRadioButton4);
341: jRadioButton4.setSelected(true);
342: jRadioButton4
343: .setText("Store the directory name in a parameter");
344: jRadioButton4.setBorder(javax.swing.BorderFactory
345: .createEmptyBorder(0, 0, 0, 0));
346: jRadioButton4.setFocusPainted(false);
347: jRadioButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
348: jRadioButton4.setMinimumSize(new java.awt.Dimension(115, 20));
349: jRadioButton4.setPreferredSize(new java.awt.Dimension(115, 20));
350: jRadioButton4
351: .addItemListener(new java.awt.event.ItemListener() {
352: public void itemStateChanged(
353: java.awt.event.ItemEvent evt) {
354: jRadioButton1ItemStateChanged2(evt);
355: }
356: });
357: jRadioButton4
358: .addActionListener(new java.awt.event.ActionListener() {
359: public void actionPerformed(
360: java.awt.event.ActionEvent evt) {
361: jRadioButton1ActionPerformed2(evt);
362: }
363: });
364:
365: gridBagConstraints = new java.awt.GridBagConstraints();
366: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
367: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
368: gridBagConstraints.weightx = 1.0;
369: gridBagConstraints.insets = new java.awt.Insets(10, 20, 0, 0);
370: jPanel2.add(jRadioButton4, gridBagConstraints);
371:
372: jLabel1.setText("$P{SUBREPORT_DIR} + \"/name.jasper\"");
373: gridBagConstraints = new java.awt.GridBagConstraints();
374: gridBagConstraints.gridx = 0;
375: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
376: gridBagConstraints.insets = new java.awt.Insets(2, 40, 0, 0);
377: jPanel2.add(jLabel1, gridBagConstraints);
378:
379: buttonGroup2.add(jRadioButton5);
380: jRadioButton5.setText("Use a static absolute path reference");
381: jRadioButton5.setBorder(javax.swing.BorderFactory
382: .createEmptyBorder(0, 0, 0, 0));
383: jRadioButton5.setFocusPainted(false);
384: jRadioButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
385: jRadioButton5.setMinimumSize(new java.awt.Dimension(115, 20));
386: jRadioButton5.setPreferredSize(new java.awt.Dimension(115, 20));
387: jRadioButton5
388: .addItemListener(new java.awt.event.ItemListener() {
389: public void itemStateChanged(
390: java.awt.event.ItemEvent evt) {
391: jRadioButton2jRadioButton1ItemStateChanged1(evt);
392: }
393: });
394: jRadioButton5
395: .addActionListener(new java.awt.event.ActionListener() {
396: public void actionPerformed(
397: java.awt.event.ActionEvent evt) {
398: jRadioButton2jRadioButton1ActionPerformed1(evt);
399: }
400: });
401:
402: gridBagConstraints = new java.awt.GridBagConstraints();
403: gridBagConstraints.gridx = 0;
404: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
405: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
406: gridBagConstraints.weightx = 1.0;
407: gridBagConstraints.insets = new java.awt.Insets(24, 20, 0, 0);
408: jPanel2.add(jRadioButton5, gridBagConstraints);
409:
410: jLabel2.setText("\" path reference \"");
411: gridBagConstraints = new java.awt.GridBagConstraints();
412: gridBagConstraints.gridx = 0;
413: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
414: gridBagConstraints.insets = new java.awt.Insets(2, 40, 0, 0);
415: jPanel2.add(jLabel2, gridBagConstraints);
416:
417: jPanel3.setLayout(new java.awt.GridBagLayout());
418:
419: jLabel3.setText("Finish");
420: jPanel3.add(jLabel3, new java.awt.GridBagConstraints());
421:
422: setLayout(new java.awt.BorderLayout());
423:
424: }// </editor-fold>//GEN-END:initComponents
425:
426: private void jRadioButton3ItemStateChanged1(
427: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton3ItemStateChanged1
428: if (wizardPanel != null)
429: wizardPanel.updateButtons();
430: }//GEN-LAST:event_jRadioButton3ItemStateChanged1
431:
432: private void jRadioButton2jRadioButton1ActionPerformed1(
433: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2jRadioButton1ActionPerformed1
434: // TODO add your handling code here:
435: }//GEN-LAST:event_jRadioButton2jRadioButton1ActionPerformed1
436:
437: private void jRadioButton2jRadioButton1ItemStateChanged1(
438: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton2jRadioButton1ItemStateChanged1
439: // TODO add your handling code here:
440: }//GEN-LAST:event_jRadioButton2jRadioButton1ItemStateChanged1
441:
442: private void jRadioButton1ActionPerformed2(
443: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed2
444: // TODO add your handling code here:
445: }//GEN-LAST:event_jRadioButton1ActionPerformed2
446:
447: private void jRadioButton1ItemStateChanged2(
448: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged2
449: // TODO add your handling code here:
450: }//GEN-LAST:event_jRadioButton1ItemStateChanged2
451:
452: private void jRadioButton1ActionPerformed1(
453: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed1
454: // TODO add your handling code here:
455: }//GEN-LAST:event_jRadioButton1ActionPerformed1
456:
457: private void jRadioButton1ItemStateChanged1(
458: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged1
459: // TODO add your handling code here:
460: }//GEN-LAST:event_jRadioButton1ItemStateChanged1
461:
462: private void jRadioButton1ActionPerformed(
463: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
464: if (wizardPanel != null)
465: wizardPanel.updateButtons();
466: }//GEN-LAST:event_jRadioButton1ActionPerformed
467:
468: private void jRadioButton1ItemStateChanged(
469: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
470: if (wizardPanel != null)
471: wizardPanel.updateButtons();
472: }//GEN-LAST:event_jRadioButton1ItemStateChanged
473:
474: private void jRadioButton3ItemStateChanged(
475: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton3ItemStateChanged
476: wizardPanel.updateButtons();
477: }//GEN-LAST:event_jRadioButton3ItemStateChanged
478:
479: private void jPanel0PropertyChange(
480: java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jPanel0PropertyChange
481:
482: }//GEN-LAST:event_jPanel0PropertyChange
483:
484: // Variables declaration - do not modify//GEN-BEGIN:variables
485: private javax.swing.ButtonGroup buttonGroup1;
486: private javax.swing.ButtonGroup buttonGroup2;
487: private javax.swing.JLabel jLabel1;
488: private javax.swing.JLabel jLabel2;
489: private javax.swing.JLabel jLabel3;
490: private javax.swing.JPanel jPanel0;
491: private javax.swing.JPanel jPanel1;
492: private javax.swing.JPanel jPanel2;
493: private javax.swing.JPanel jPanel3;
494: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaConnectionExpression;
495: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDataSourceExpression;
496: private javax.swing.JRadioButton jRadioButton1;
497: private javax.swing.JRadioButton jRadioButton2;
498: private javax.swing.JRadioButton jRadioButton3;
499: private javax.swing.JRadioButton jRadioButton4;
500: private javax.swing.JRadioButton jRadioButton5;
501: private javax.swing.JRadioButton jRadioButton6;
502: private javax.swing.JScrollPane jScrollPane1;
503: private javax.swing.JTable jTableParameters;
504:
505: // End of variables declaration//GEN-END:variables
506:
507: public String[] getStepsNames() {
508:
509: String[] names = new String[3];
510: //
511: names[0] = I18n.getString(
512: "subreportWizardExistingReport.stepsnames.connection",
513: "Connection / datasource");
514: names[1] = I18n.getString(
515: "subreportWizardExistingReport.stepsnames.parameters",
516: "Parameters");
517: names[2] = I18n.getString(
518: "subreportWizardExistingReport.stepsnames.expression",
519: "Expression");
520: //names[3] = I18n.getString("subreportWizardExistingReport.stepsnames.finish","Finish");
521: //names[0] = "Connection / datasource";
522: //names[1] = "Parameters";
523: //names[2] = "Expression";
524: //names[3] = "Finish";
525: //
526:
527: return names;
528: }
529:
530: public String getStepDescription(int step) {
531:
532: //
533: if (step == 0)
534: return I18n
535: .getString(
536: "subreportWizardExistingReport.stepdescription.step0",
537: "How fill the subreport");
538: //"How fill the subreport";
539: if (step == 1)
540: return I18n
541: .getString(
542: "subreportWizardExistingReport.stepdescription.step1",
543: "Subreport parameters");
544: //"Subreport parameters";
545: if (step == 2)
546: return I18n
547: .getString(
548: "subreportWizardExistingReport.stepdescription.step2",
549: "Subreport expession");
550: //"Subreport expession";
551: if (step == 3)
552: return I18n
553: .getString(
554: "subreportWizardExistingReport.stepdescription.step3",
555: "Finish");
556: //"Finish";
557: //
558:
559: return "";
560: }
561:
562: public void initWizard() {
563:
564: }
565:
566: public void finish(int currentStep) {
567:
568: if (currentStep > 0) {
569:
570: // Set the connection...
571: if (jRadioButton1.isSelected()) {
572: getSubReportElement().setUseConnection(true);
573: getSubReportElement().setConnectionExpression(
574: "$P{REPORT_CONNECTION}");
575: } else if (jRadioButton2.isSelected()) {
576: getSubReportElement().setUseConnection(true);
577: getSubReportElement().setConnectionExpression(
578: jRTextExpressionAreaConnectionExpression
579: .getText());
580: } else if (jRadioButton3.isSelected()) {
581: getSubReportElement().setUseConnection(false);
582: getSubReportElement().setDataSourceExpression(
583: jRTextExpressionAreaDataSourceExpression
584: .getText());
585: } else if (jRadioButton6.isSelected()) {
586: getSubReportElement().setUseConnection(false);
587: getSubReportElement().setConnectionExpression("");
588: getSubReportElement().setDataSourceExpression("");
589: }
590:
591: for (int i = 0; i < jTableParameters.getRowCount(); ++i) {
592: Object obj = jTableParameters.getValueAt(i, 1);
593: if (obj != null && ("" + obj).trim().length() > 0) {
594: if (obj instanceof it.businesslogic.ireport.JRParameter) {
595: obj = "$P{" + obj + "}";
596: } else if (obj instanceof it.businesslogic.ireport.JRVariable) {
597: obj = "$V{" + obj + "}";
598: } else if (obj instanceof it.businesslogic.ireport.JRField) {
599: obj = "$F{" + obj + "}";
600: }
601:
602: it.businesslogic.ireport.JRSubreportParameter srp = new it.businesslogic.ireport.JRSubreportParameter(
603: "" + jTableParameters.getValueAt(i, 0), ""
604: + obj);
605:
606: getSubReportElement().getSubreportParameters().add(
607: srp);
608: }
609: }
610:
611: if (jRadioButton4.isSelected()) {
612: Report report = MainFrame.getMainInstance()
613: .getActiveReportFrame().getReport();
614: Vector v = report.getParameters();
615: boolean found = false;
616: for (int i = 0; i < report.getParameters().size(); ++i) {
617: it.businesslogic.ireport.JRParameter param = (it.businesslogic.ireport.JRParameter) report
618: .getParameters().elementAt(i);
619:
620: if (param.getName().equals("SUBREPORT_DIR")) {
621: found = true;
622:
623: break;
624: }
625: }
626: if (!found) {
627: it.businesslogic.ireport.JRParameter param = new it.businesslogic.ireport.JRParameter(
628: "SUBREPORT_DIR", "java.lang.String");
629: File f = new File(getReportFileName());
630:
631: // Set as subreport directory the current compilation directory...
632: /*
633:
634: String s = f.getParent(); //Path();
635: */
636: String s = MainFrame.getMainInstance()
637: .getTranslatedCompileDirectory();
638:
639: if (s.length() > 0 && !s.endsWith(File.separator))
640: s += File.separator;
641:
642: s = Misc.string_replace("\\\\", "\\", s);
643: s = "\"" + s + "\"";
644:
645: param.setDefaultValueExpression(s);
646: report.addParameter(param);
647: }
648: getSubReportElement().setSubreportExpression(
649: jLabel1.getText());
650: } else {
651: getSubReportElement().setSubreportExpression(
652: jLabel2.getText());
653: }
654: getSubReportElement().setSubreportExpressionClass(
655: "java.lang.String");
656: }
657:
658: this .getWizardDialog().setVisible(false);
659: this .getWizardDialog().dispose();
660: }
661:
662: public boolean nextStep(int nextStep) {
663:
664: if (nextStep == 0) // First step == 0
665: {
666: } else if (nextStep == 1) // First step == 0
667: {
668: try {
669: if (getReportFileName().toLowerCase().endsWith(
670: ".jasper")) {
671:
672: JasperReport jr = (JasperReport) net.sf.jasperreports.engine.util.JRLoader
673: .loadObject(getReportFileName());
674: JRParameter[] params = jr.getParameters();
675:
676: javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel) jTableParameters
677: .getModel();
678: dtm.setRowCount(0);
679: for (int i = 0; i < params.length; ++i) {
680: JRParameter param = params[i];
681: if (param.getName() != null
682: && !param.isSystemDefined()) {
683: dtm.addRow(new Object[] { param.getName(),
684: "" });
685: }
686: }
687: jTableParameters.updateUI();
688:
689: } else {
690:
691: JasperDesign jr = (JasperDesign) net.sf.jasperreports.engine.xml.JRXmlLoader
692: .load(getReportFileName());
693:
694: JRParameter[] params = jr.getParameters();
695:
696: javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel) jTableParameters
697: .getModel();
698: dtm.setRowCount(0);
699: for (int i = 0; i < params.length; ++i) {
700: JRParameter param = params[i];
701: if (param.getName() != null
702: && !param.isSystemDefined()) {
703: dtm.addRow(new Object[] { param.getName(),
704: "" });
705: }
706: }
707: jTableParameters.updateUI();
708:
709: }
710:
711: } catch (Exception ex) {
712: final String errorMessage = ex.getMessage();
713: SwingUtilities.invokeLater(new Runnable() {
714: public void run() {
715: JOptionPane
716: .showMessageDialog(
717: SubreportWizardExistingReport.this ,
718: I18n
719: .getFormattedString(
720: "messages.subreportWizardExistingReport.errorLoadingSubreport",
721: "Error loading the subreport file: {0}",
722: new Object[] { errorMessage }));
723: }
724: });
725:
726: ex.printStackTrace();
727: //finish(-1);
728: //return false;
729: }
730: return true;
731: } else if (nextStep == 2) // First step == 0
732: {
733: try {
734: File f = new File(getReportFileName());
735:
736: String s = f.getName();
737: if (!s.toLowerCase().endsWith(".jasper")) {
738: if (s.lastIndexOf(".") > 0) {
739: s = s.substring(0, s.lastIndexOf("."));
740: }
741: s += ".jasper";
742: }
743:
744: jLabel1.setText("$P{SUBREPORT_DIR} + \"" + s + "\"");
745:
746: String s2 = MainFrame.getMainInstance()
747: .getTranslatedCompileDirectory();
748: f = new File(getReportFileName());
749: f = new File(s2, f.getName());
750:
751: s2 = Misc.string_replace("\\\\", "\\", "" + f);
752:
753: jLabel2.setText("\"" + s2 + "\"");
754:
755: } catch (Exception ex) {
756: ex.printStackTrace();
757: }
758:
759: }
760: return true;
761: }
762:
763: public boolean previousStep(int previousStep) {
764: return true;
765: }
766:
767: public boolean canFinish(int currentStep) {
768: return true;
769: }
770:
771: public boolean canNext(int currentStep) {
772:
773: if (currentStep == 0) {
774: if (jRadioButton1.isSelected())
775: return true;
776: else if (jRadioButton2.isSelected()
777: && jRTextExpressionAreaConnectionExpression
778: .getText().trim().length() > 0)
779: return true;
780: else if (jRadioButton3.isSelected()
781: && jRTextExpressionAreaDataSourceExpression
782: .getText().trim().length() > 0)
783: return true;
784: else if (jRadioButton6.isSelected())
785: return true;
786:
787: return false;
788: }
789: if (currentStep == 1) {
790: return true;
791: }
792: return false;
793: }
794:
795: public boolean canPrevious(int currentStep) {
796: return (currentStep > 0);
797: }
798:
799: public JPanel getStepPanel(int step) {
800: if (step == 0)
801: return jPanel0;
802: if (step == 1)
803: return jPanel1;
804: if (step == 2)
805: return jPanel2;
806: if (step == 3)
807: return jPanel3;
808: return null;
809: }
810:
811: public String getReportFileName() {
812: return reportFileName;
813: }
814:
815: public void setReportFileName(String reportFileName) {
816: this .reportFileName = reportFileName;
817: }
818:
819: public SubReportElement getSubReportElement() {
820: return subReportElement;
821: }
822:
823: public void setSubReportElement(SubReportElement subReportElement) {
824: this .subReportElement = subReportElement;
825: }
826:
827: public BaseWizardPanel getWizardPanel() {
828: return wizardPanel;
829: }
830:
831: public void setWizardPanel(BaseWizardPanel wizardPanel) {
832: this .wizardPanel = wizardPanel;
833: }
834:
835: public javax.swing.JDialog getWizardDialog() {
836: return wizardDialog;
837: }
838:
839: public void setWizardDialog(javax.swing.JDialog wizardDialog) {
840: this .wizardDialog = wizardDialog;
841: }
842:
843: public void applyI18n() {
844: // Start autogenerated code ----------------------
845: jRadioButton1
846: .setText(I18n
847: .getString(
848: "subreportWizardExistingReport.radioButton1",
849: "Use the same connection used to fill the master report"));
850: jRadioButton2.setText(I18n.getString(
851: "subreportWizardExistingReport.radioButton2",
852: "Use another connection"));
853: jRadioButton3.setText(I18n.getString(
854: "subreportWizardExistingReport.radioButton3",
855: "Use a JRDataSource expression"));
856: jRadioButton4.setText(I18n.getString(
857: "subreportWizardExistingReport.radioButton4",
858: "Store the directory name in a parameter"));
859: jRadioButton5.setText(I18n.getString(
860: "subreportWizardExistingReport.radioButton5",
861: "Use a static absolute path reference"));
862: jRadioButton6.setText(I18n.getString(
863: "subreportWizardExistingReport.radioButton6",
864: "Do not use any connection or datasource"));
865: // End autogenerated code ----------------------
866: // Start autogenerated code ----------------------
867: jLabel1.setText(I18n.getString(
868: "subreportWizardExistingReport.label1",
869: "$P{SUBREPORT_DIR} + \"/name.jasper\""));
870: jLabel2.setText(I18n.getString(
871: "subreportWizardExistingReport.label2",
872: "\" path reference \""));
873: jLabel3.setText(I18n.getString(
874: "subreportWizardExistingReport.label3", "Finish"));
875: // End autogenerated code ----------------------
876:
877: jTableParameters
878: .getColumnModel()
879: .getColumn(0)
880: .setHeaderValue(
881: I18n
882: .getString(
883: "subreportWizardExistingReport.tablecolumn.parameterName",
884: "Parameter name"));
885: jTableParameters
886: .getColumnModel()
887: .getColumn(1)
888: .setHeaderValue(
889: I18n
890: .getString(
891: "subreportWizardExistingReport.tablecolumn.expression",
892: "Expression"));
893:
894: }
895: }
|