0001: /*
0002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
0003: * http://www.jaspersoft.com.
0004: *
0005: * Unless you have purchased a commercial license agreement from JasperSoft,
0006: * the following license terms apply:
0007: *
0008: * This program is free software; you can redistribute it and/or modify
0009: * it under the terms of the GNU General Public License version 2 as published by
0010: * the Free Software Foundation.
0011: *
0012: * This program is distributed WITHOUT ANY WARRANTY; and without the
0013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0014: * See the GNU General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU General Public License
0017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
0018: * or write to:
0019: *
0020: * Free Software Foundation, Inc.,
0021: * 59 Temple Place - Suite 330,
0022: * Boston, MA USA 02111-1307
0023: *
0024: *
0025: *
0026: *
0027: * SubreportWizardNewReport.java
0028: *
0029: * Created on March 22, 2006, 8:52 PM
0030: *
0031: */
0032:
0033: package it.businesslogic.ireport.gui.wizard;
0034:
0035: import it.businesslogic.ireport.Band;
0036: import it.businesslogic.ireport.Group;
0037: import it.businesslogic.ireport.IReportConnection;
0038: import it.businesslogic.ireport.IReportTemplate;
0039: import it.businesslogic.ireport.JRField;
0040: import it.businesslogic.ireport.Report;
0041: import it.businesslogic.ireport.ReportElement;
0042: import it.businesslogic.ireport.StaticTextReportElement;
0043: import it.businesslogic.ireport.SubReportElement;
0044: import it.businesslogic.ireport.TextFieldReportElement;
0045: import it.businesslogic.ireport.TransformationType;
0046: import it.businesslogic.ireport.connection.JDBCConnection;
0047: import it.businesslogic.ireport.connection.JRHibernateConnection;
0048: import it.businesslogic.ireport.connection.NullConnection;
0049: import it.businesslogic.ireport.gui.ConnectionDialog;
0050: import it.businesslogic.ireport.gui.MainFrame;
0051: import it.businesslogic.ireport.gui.WizardDialog;
0052: import it.businesslogic.ireport.util.Misc;
0053: import java.io.File;
0054: import java.io.FileInputStream;
0055: import java.io.FilenameFilter;
0056: import java.io.InputStream;
0057: import java.util.Enumeration;
0058: import java.util.Vector;
0059: import javax.swing.DefaultListModel;
0060: import javax.swing.ImageIcon;
0061: import javax.swing.JFileChooser;
0062: import javax.swing.JOptionPane;
0063: import javax.swing.JPanel;
0064: import javax.swing.event.DocumentEvent;
0065: import javax.swing.event.DocumentListener;
0066:
0067: import org.apache.xerces.parsers.DOMParser;
0068: import org.apache.xpath.XPathAPI;
0069: import org.apache.xpath.objects.XBoolean;
0070: import org.w3c.dom.DOMException;
0071: import org.w3c.dom.Document;
0072: import org.w3c.dom.Node;
0073: import org.w3c.dom.NodeList;
0074: import org.xml.sax.SAXException;
0075: import it.businesslogic.ireport.util.I18n;
0076:
0077: /**
0078: *
0079: * @author gtoffoli
0080: */
0081: public class SubreportWizardNewReport extends javax.swing.JPanel
0082: implements GenericWizard, Runnable {
0083:
0084: private String reportFileName = null;
0085: private SubReportElement subReportElement = null;
0086: private BaseWizardPanel wizardPanel = null;
0087: private javax.swing.JDialog wizardDialog = null;
0088:
0089: Vector templates = null;
0090:
0091: private Thread t = null;
0092:
0093: /** Creates new form SubreportWizardPanes */
0094: public SubreportWizardNewReport() {
0095: initComponents();
0096: applyI18n();
0097: jRSQLExpressionArea1.getDocument().addDocumentListener(
0098: new DocumentListener() {
0099: public void changedUpdate(DocumentEvent e) {
0100: if (wizardPanel != null)
0101: wizardPanel.updateButtons();
0102: }
0103:
0104: public void insertUpdate(DocumentEvent e) {
0105: if (wizardPanel != null)
0106: wizardPanel.updateButtons();
0107: }
0108:
0109: public void removeUpdate(DocumentEvent e) {
0110: if (wizardPanel != null)
0111: wizardPanel.updateButtons();
0112: }
0113: });
0114:
0115: jTextFieldBean.getDocument().addDocumentListener(
0116: new DocumentListener() {
0117: public void changedUpdate(DocumentEvent e) {
0118: if (wizardPanel != null)
0119: wizardPanel.updateButtons();
0120: }
0121:
0122: public void insertUpdate(DocumentEvent e) {
0123: if (wizardPanel != null)
0124: wizardPanel.updateButtons();
0125: }
0126:
0127: public void removeUpdate(DocumentEvent e) {
0128: if (wizardPanel != null)
0129: wizardPanel.updateButtons();
0130: }
0131: });
0132:
0133: jTextFieldReportFileName.getDocument().addDocumentListener(
0134: new DocumentListener() {
0135: public void changedUpdate(DocumentEvent e) {
0136: if (wizardPanel != null)
0137: wizardPanel.updateButtons();
0138: updateExpressionLabels();
0139: }
0140:
0141: public void insertUpdate(DocumentEvent e) {
0142: if (wizardPanel != null)
0143: wizardPanel.updateButtons();
0144: updateExpressionLabels();
0145: }
0146:
0147: public void removeUpdate(DocumentEvent e) {
0148: if (wizardPanel != null)
0149: wizardPanel.updateButtons();
0150: updateExpressionLabels();
0151: }
0152: });
0153:
0154: // These are the combobox values
0155: Vector values = new Vector();
0156:
0157: Report report = MainFrame.getMainInstance()
0158: .getActiveReportFrame().getReport();
0159:
0160: values.addAll(report.getFields());
0161: values.addAll(report.getVariables());
0162: values.addAll(report.getParameters());
0163:
0164: jList1.setModel(new DefaultListModel());
0165: jList2.setModel(new DefaultListModel());
0166: jList3.setModel(new DefaultListModel());
0167:
0168: // If the cell should appear like a combobox in its
0169: // non-editing state, also set the combobox renderer
0170: //col.setCellRenderer(new TableComboBoxRenderer(values));
0171:
0172: updateTemplatesList();
0173:
0174: String fileName = report.getFilename();
0175: File f = new File(fileName);
0176: String baseFileName = f.getName();
0177: String pathFile = f.getParent();
0178: if (pathFile.length() > 0 && !pathFile.endsWith(File.separator)) {
0179: pathFile += File.separator;
0180: }
0181:
0182: if (baseFileName.indexOf(".") > 0)
0183: baseFileName = baseFileName.substring(0, baseFileName
0184: .lastIndexOf("."));
0185:
0186: File f2 = null;
0187: for (int i = 0;; ++i) {
0188: fileName = baseFileName + "_subreport" + i + ".jrxml";
0189:
0190: f2 = new File(pathFile, fileName);
0191: if (!f2.exists())
0192: break;
0193: }
0194:
0195: jTextFieldReportFileName.setText(f2.getName());
0196:
0197: }
0198:
0199: /** This method is called from within the constructor to
0200: * initialize the form.
0201: * WARNING: Do NOT modify this code. The content of this method is
0202: * always regenerated by the Form Editor.
0203: */
0204: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0205: private void initComponents() {
0206: java.awt.GridBagConstraints gridBagConstraints;
0207:
0208: jPanel0 = new javax.swing.JPanel();
0209: jPanel61 = new javax.swing.JPanel();
0210: jLabel12 = new javax.swing.JLabel();
0211: jComboBoxConnection = new javax.swing.JComboBox();
0212: jButtonNewConnection = new javax.swing.JButton();
0213: jLabel2 = new javax.swing.JLabel();
0214: jPanel41 = new javax.swing.JPanel();
0215: jRSQLExpressionArea1 = new it.businesslogic.ireport.gui.JRTextExpressionArea();
0216: jTextFieldBean = new javax.swing.JTextField();
0217: jPanel5 = new javax.swing.JPanel();
0218: jButtonLoadQuery = new javax.swing.JButton();
0219: jButtonSaveQuery = new javax.swing.JButton();
0220: jPanel6 = new javax.swing.JPanel();
0221: buttonGroup1 = new javax.swing.ButtonGroup();
0222: jPanel1 = new javax.swing.JPanel();
0223: jScrollPane1 = new javax.swing.JScrollPane();
0224: jList1 = new javax.swing.JList();
0225: jScrollPane2 = new javax.swing.JScrollPane();
0226: jList2 = new javax.swing.JList();
0227: jPanelButtons = new javax.swing.JPanel();
0228: jButton1 = new javax.swing.JButton();
0229: jButton2 = new javax.swing.JButton();
0230: jButton3 = new javax.swing.JButton();
0231: jButton4 = new javax.swing.JButton();
0232: jPanel2 = new javax.swing.JPanel();
0233: jRadioButtonColumnarLayout = new javax.swing.JRadioButton();
0234: jRadioButtonTabularLayout = new javax.swing.JRadioButton();
0235: jPanel7 = new javax.swing.JPanel();
0236: jScrollPane3 = new javax.swing.JScrollPane();
0237: jList3 = new javax.swing.JList();
0238: jPanel4 = new javax.swing.JPanel();
0239: jLabelImage = new javax.swing.JLabel();
0240: jPanel3 = new javax.swing.JPanel();
0241: jLabel3 = new javax.swing.JLabel();
0242: jTextFieldReportFileName = new javax.swing.JTextField();
0243: jRadioButton4 = new javax.swing.JRadioButton();
0244: jLabel1 = new javax.swing.JLabel();
0245: jRadioButton5 = new javax.swing.JRadioButton();
0246: jLabel2e = new javax.swing.JLabel();
0247: jButton5 = new javax.swing.JButton();
0248: buttonGroup2 = new javax.swing.ButtonGroup();
0249:
0250: jPanel0.setLayout(new java.awt.GridBagLayout());
0251:
0252: jPanel0
0253: .addPropertyChangeListener(new java.beans.PropertyChangeListener() {
0254: public void propertyChange(
0255: java.beans.PropertyChangeEvent evt) {
0256: jPanel0PropertyChange(evt);
0257: }
0258: });
0259:
0260: jPanel61.setMinimumSize(new java.awt.Dimension(10, 30));
0261: jPanel61.setPreferredSize(new java.awt.Dimension(10, 30));
0262: jPanel0.add(jPanel61, new java.awt.GridBagConstraints());
0263:
0264: jLabel12.setText("Connection / Datasource");
0265: gridBagConstraints = new java.awt.GridBagConstraints();
0266: gridBagConstraints.gridx = 0;
0267: gridBagConstraints.gridy = 4;
0268: gridBagConstraints.gridwidth = 2;
0269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0270: gridBagConstraints.weightx = 1.0;
0271: gridBagConstraints.insets = new java.awt.Insets(0, 20, 2, 0);
0272: jPanel0.add(jLabel12, gridBagConstraints);
0273:
0274: jComboBoxConnection
0275: .setModel(new javax.swing.DefaultComboBoxModel(
0276: new String[] { "Item 1", "Item 2", "Item 3",
0277: "Item 4" }));
0278: jComboBoxConnection.setMinimumSize(new java.awt.Dimension(51,
0279: 22));
0280: jComboBoxConnection
0281: .addActionListener(new java.awt.event.ActionListener() {
0282: public void actionPerformed(
0283: java.awt.event.ActionEvent evt) {
0284: jComboBoxConnectionActionPerformed(evt);
0285: }
0286: });
0287:
0288: gridBagConstraints = new java.awt.GridBagConstraints();
0289: gridBagConstraints.gridx = 0;
0290: gridBagConstraints.gridy = 5;
0291: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0292: gridBagConstraints.weightx = 1.0;
0293: gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 0);
0294: jPanel0.add(jComboBoxConnection, gridBagConstraints);
0295:
0296: jButtonNewConnection.setText("New");
0297: jButtonNewConnection
0298: .addActionListener(new java.awt.event.ActionListener() {
0299: public void actionPerformed(
0300: java.awt.event.ActionEvent evt) {
0301: jButtonNewConnectionActionPerformed(evt);
0302: }
0303: });
0304:
0305: gridBagConstraints = new java.awt.GridBagConstraints();
0306: gridBagConstraints.gridx = 1;
0307: gridBagConstraints.gridy = 5;
0308: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 20);
0309: jPanel0.add(jButtonNewConnection, gridBagConstraints);
0310:
0311: jLabel2.setText("Query");
0312: gridBagConstraints = new java.awt.GridBagConstraints();
0313: gridBagConstraints.gridx = 0;
0314: gridBagConstraints.gridy = 8;
0315: gridBagConstraints.gridwidth = 2;
0316: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0317: gridBagConstraints.weightx = 1.0;
0318: gridBagConstraints.insets = new java.awt.Insets(30, 20, 2, 0);
0319: jPanel0.add(jLabel2, gridBagConstraints);
0320:
0321: jPanel41.setLayout(new java.awt.GridBagLayout());
0322:
0323: jPanel41.setMinimumSize(new java.awt.Dimension(391, 120));
0324: jPanel41.setPreferredSize(new java.awt.Dimension(391, 120));
0325: jRSQLExpressionArea1.setBorder(javax.swing.BorderFactory
0326: .createEtchedBorder());
0327: jRSQLExpressionArea1.setElectricScroll(0);
0328: jRSQLExpressionArea1.setMinimumSize(new java.awt.Dimension(300,
0329: 100));
0330: jRSQLExpressionArea1.setPreferredSize(new java.awt.Dimension(
0331: 300, 100));
0332: gridBagConstraints = new java.awt.GridBagConstraints();
0333: gridBagConstraints.gridx = 0;
0334: gridBagConstraints.gridy = 0;
0335: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0336: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0337: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0338: gridBagConstraints.weightx = 1.0;
0339: gridBagConstraints.weighty = 1.0;
0340: jPanel41.add(jRSQLExpressionArea1, gridBagConstraints);
0341:
0342: jTextFieldBean
0343: .addActionListener(new java.awt.event.ActionListener() {
0344: public void actionPerformed(
0345: java.awt.event.ActionEvent evt) {
0346: jTextFieldBeanActionPerformed(evt);
0347: }
0348: });
0349:
0350: gridBagConstraints = new java.awt.GridBagConstraints();
0351: gridBagConstraints.gridx = 0;
0352: gridBagConstraints.gridy = 0;
0353: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0354: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0355: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0356: gridBagConstraints.weightx = 1.0;
0357: gridBagConstraints.weighty = 1.0;
0358: jPanel41.add(jTextFieldBean, gridBagConstraints);
0359:
0360: jPanel5.setLayout(new java.awt.GridBagLayout());
0361:
0362: jButtonLoadQuery
0363: .setIcon(new javax.swing.ImageIcon(
0364: getClass()
0365: .getResource(
0366: "/it/businesslogic/ireport/icons/menu/folder_database.png")));
0367: jButtonLoadQuery.setText("Load query");
0368: jButtonLoadQuery.setMargin(new java.awt.Insets(2, 4, 2, 4));
0369: jButtonLoadQuery
0370: .addActionListener(new java.awt.event.ActionListener() {
0371: public void actionPerformed(
0372: java.awt.event.ActionEvent evt) {
0373: jButtonLoadQueryActionPerformed(evt);
0374: }
0375: });
0376:
0377: gridBagConstraints = new java.awt.GridBagConstraints();
0378: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0379: gridBagConstraints.weightx = 1.0;
0380: jPanel5.add(jButtonLoadQuery, gridBagConstraints);
0381:
0382: jButtonSaveQuery
0383: .setIcon(new javax.swing.ImageIcon(
0384: getClass()
0385: .getResource(
0386: "/it/businesslogic/ireport/icons/menu/database_save.png")));
0387: jButtonSaveQuery.setText("Save query");
0388: jButtonSaveQuery.setMargin(new java.awt.Insets(2, 4, 2, 4));
0389: jButtonSaveQuery
0390: .addActionListener(new java.awt.event.ActionListener() {
0391: public void actionPerformed(
0392: java.awt.event.ActionEvent evt) {
0393: jButtonSaveQueryActionPerformed(evt);
0394: }
0395: });
0396:
0397: gridBagConstraints = new java.awt.GridBagConstraints();
0398: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
0399: jPanel5.add(jButtonSaveQuery, gridBagConstraints);
0400:
0401: gridBagConstraints = new java.awt.GridBagConstraints();
0402: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0403: gridBagConstraints.weightx = 1.0;
0404: jPanel41.add(jPanel5, gridBagConstraints);
0405:
0406: gridBagConstraints = new java.awt.GridBagConstraints();
0407: gridBagConstraints.gridy = 10;
0408: gridBagConstraints.gridwidth = 2;
0409: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0410: gridBagConstraints.weightx = 1.0;
0411: gridBagConstraints.weighty = 1.0;
0412: gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 20);
0413: jPanel0.add(jPanel41, gridBagConstraints);
0414:
0415: jPanel6.setLayout(new java.awt.GridBagLayout());
0416:
0417: gridBagConstraints = new java.awt.GridBagConstraints();
0418: gridBagConstraints.gridx = 0;
0419: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0420: gridBagConstraints.weightx = 1.0;
0421: jPanel0.add(jPanel6, gridBagConstraints);
0422:
0423: jPanel1.setLayout(new java.awt.GridBagLayout());
0424:
0425: jScrollPane1.setViewportView(jList1);
0426:
0427: gridBagConstraints = new java.awt.GridBagConstraints();
0428: gridBagConstraints.gridx = 0;
0429: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0430: gridBagConstraints.weightx = 0.5;
0431: gridBagConstraints.weighty = 1.0;
0432: gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 5);
0433: jPanel1.add(jScrollPane1, gridBagConstraints);
0434:
0435: jScrollPane2.setViewportView(jList2);
0436:
0437: gridBagConstraints = new java.awt.GridBagConstraints();
0438: gridBagConstraints.gridx = 2;
0439: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0440: gridBagConstraints.weightx = 0.5;
0441: gridBagConstraints.weighty = 1.0;
0442: gridBagConstraints.insets = new java.awt.Insets(10, 5, 10, 10);
0443: jPanel1.add(jScrollPane2, gridBagConstraints);
0444:
0445: jPanelButtons.setLayout(new java.awt.GridBagLayout());
0446:
0447: jButton1.setText(">");
0448: jButton1.setMargin(new java.awt.Insets(2, 0, 2, 0));
0449: jButton1.setMinimumSize(new java.awt.Dimension(28, 28));
0450: jButton1.setPreferredSize(new java.awt.Dimension(28, 28));
0451: jButton1.addActionListener(new java.awt.event.ActionListener() {
0452: public void actionPerformed(java.awt.event.ActionEvent evt) {
0453: jButton1ActionPerformed(evt);
0454: }
0455: });
0456:
0457: gridBagConstraints = new java.awt.GridBagConstraints();
0458: gridBagConstraints.gridx = 0;
0459: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0460: gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 0);
0461: jPanelButtons.add(jButton1, gridBagConstraints);
0462:
0463: jButton2.setText(">>");
0464: jButton2.setMargin(new java.awt.Insets(2, 0, 2, 0));
0465: jButton2.setMinimumSize(new java.awt.Dimension(28, 28));
0466: jButton2.setPreferredSize(new java.awt.Dimension(28, 28));
0467: jButton2.addActionListener(new java.awt.event.ActionListener() {
0468: public void actionPerformed(java.awt.event.ActionEvent evt) {
0469: jButton2ActionPerformed(evt);
0470: }
0471: });
0472:
0473: gridBagConstraints = new java.awt.GridBagConstraints();
0474: gridBagConstraints.gridx = 0;
0475: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0476: gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 0);
0477: jPanelButtons.add(jButton2, gridBagConstraints);
0478:
0479: jButton3.setText("<<");
0480: jButton3.setMargin(new java.awt.Insets(2, 0, 2, 0));
0481: jButton3.setMinimumSize(new java.awt.Dimension(28, 28));
0482: jButton3.setPreferredSize(new java.awt.Dimension(28, 28));
0483: jButton3.addActionListener(new java.awt.event.ActionListener() {
0484: public void actionPerformed(java.awt.event.ActionEvent evt) {
0485: jButton3ActionPerformed(evt);
0486: }
0487: });
0488:
0489: gridBagConstraints = new java.awt.GridBagConstraints();
0490: gridBagConstraints.gridx = 0;
0491: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0492: gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 0);
0493: jPanelButtons.add(jButton3, gridBagConstraints);
0494:
0495: jButton4.setText("<");
0496: jButton4.setMargin(new java.awt.Insets(2, 0, 2, 0));
0497: jButton4.setMinimumSize(new java.awt.Dimension(28, 28));
0498: jButton4.setPreferredSize(new java.awt.Dimension(28, 28));
0499: jButton4.addActionListener(new java.awt.event.ActionListener() {
0500: public void actionPerformed(java.awt.event.ActionEvent evt) {
0501: jButton4ActionPerformed(evt);
0502: }
0503: });
0504:
0505: gridBagConstraints = new java.awt.GridBagConstraints();
0506: gridBagConstraints.gridx = 0;
0507: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0508: gridBagConstraints.insets = new java.awt.Insets(8, 0, 8, 0);
0509: jPanelButtons.add(jButton4, gridBagConstraints);
0510:
0511: gridBagConstraints = new java.awt.GridBagConstraints();
0512: gridBagConstraints.gridx = 1;
0513: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0514: gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
0515: jPanel1.add(jPanelButtons, gridBagConstraints);
0516:
0517: jPanel2.setLayout(new java.awt.GridBagLayout());
0518:
0519: buttonGroup1.add(jRadioButtonColumnarLayout);
0520: jRadioButtonColumnarLayout.setSelected(true);
0521: jRadioButtonColumnarLayout.setText("Columnar layout");
0522: jRadioButtonColumnarLayout.setBorder(javax.swing.BorderFactory
0523: .createEmptyBorder(0, 0, 0, 0));
0524: jRadioButtonColumnarLayout.setMargin(new java.awt.Insets(0, 0,
0525: 0, 0));
0526: jRadioButtonColumnarLayout
0527: .addActionListener(new java.awt.event.ActionListener() {
0528: public void actionPerformed(
0529: java.awt.event.ActionEvent evt) {
0530: jRadioButtonColumnarLayoutActionPerformed(evt);
0531: }
0532: });
0533:
0534: gridBagConstraints = new java.awt.GridBagConstraints();
0535: gridBagConstraints.gridx = 0;
0536: gridBagConstraints.gridy = 1;
0537: gridBagConstraints.gridwidth = 2;
0538: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0539: gridBagConstraints.weightx = 1.0;
0540: gridBagConstraints.insets = new java.awt.Insets(30, 20, 0, 0);
0541: jPanel2.add(jRadioButtonColumnarLayout, gridBagConstraints);
0542:
0543: buttonGroup1.add(jRadioButtonTabularLayout);
0544: jRadioButtonTabularLayout.setText("Tabular layout");
0545: jRadioButtonTabularLayout.setBorder(javax.swing.BorderFactory
0546: .createEmptyBorder(0, 0, 0, 0));
0547: jRadioButtonTabularLayout.setMargin(new java.awt.Insets(0, 0,
0548: 0, 0));
0549: jRadioButtonTabularLayout
0550: .addActionListener(new java.awt.event.ActionListener() {
0551: public void actionPerformed(
0552: java.awt.event.ActionEvent evt) {
0553: jRadioButtonTabularLayoutActionPerformed(evt);
0554: }
0555: });
0556:
0557: gridBagConstraints = new java.awt.GridBagConstraints();
0558: gridBagConstraints.gridx = 0;
0559: gridBagConstraints.gridy = 2;
0560: gridBagConstraints.gridwidth = 2;
0561: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0562: gridBagConstraints.weightx = 1.0;
0563: gridBagConstraints.insets = new java.awt.Insets(4, 20, 0, 0);
0564: jPanel2.add(jRadioButtonTabularLayout, gridBagConstraints);
0565:
0566: jPanel7.setLayout(new java.awt.BorderLayout());
0567:
0568: jPanel7.setMinimumSize(new java.awt.Dimension(150, 23));
0569: jPanel7.setPreferredSize(new java.awt.Dimension(150, 0));
0570: jScrollPane3.setMinimumSize(new java.awt.Dimension(100, 23));
0571: jList3
0572: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
0573: public void valueChanged(
0574: javax.swing.event.ListSelectionEvent evt) {
0575: jList3ValueChanged(evt);
0576: }
0577: });
0578:
0579: jScrollPane3.setViewportView(jList3);
0580:
0581: jPanel7.add(jScrollPane3, java.awt.BorderLayout.CENTER);
0582:
0583: gridBagConstraints = new java.awt.GridBagConstraints();
0584: gridBagConstraints.gridx = 0;
0585: gridBagConstraints.gridy = 5;
0586: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
0587: gridBagConstraints.weighty = 1.0;
0588: gridBagConstraints.insets = new java.awt.Insets(8, 20, 10, 0);
0589: jPanel2.add(jPanel7, gridBagConstraints);
0590:
0591: jPanel4.setLayout(new java.awt.GridBagLayout());
0592:
0593: jLabelImage
0594: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
0595: jLabelImage.setText(" ");
0596: jLabelImage
0597: .setVerticalAlignment(javax.swing.SwingConstants.TOP);
0598: jLabelImage.setOpaque(true);
0599: gridBagConstraints = new java.awt.GridBagConstraints();
0600: gridBagConstraints.gridx = 0;
0601: gridBagConstraints.gridy = 0;
0602: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0603: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0604: gridBagConstraints.weightx = 1.0;
0605: gridBagConstraints.weighty = 1.0;
0606: jPanel4.add(jLabelImage, gridBagConstraints);
0607:
0608: gridBagConstraints = new java.awt.GridBagConstraints();
0609: gridBagConstraints.gridx = 1;
0610: gridBagConstraints.gridy = 5;
0611: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0612: gridBagConstraints.weightx = 1.0;
0613: gridBagConstraints.weighty = 1.0;
0614: gridBagConstraints.insets = new java.awt.Insets(8, 10, 10, 10);
0615: jPanel2.add(jPanel4, gridBagConstraints);
0616:
0617: jPanel3.setLayout(new java.awt.GridBagLayout());
0618:
0619: jLabel3.setText("Save the subreport as...");
0620: gridBagConstraints = new java.awt.GridBagConstraints();
0621: gridBagConstraints.gridx = 0;
0622: gridBagConstraints.gridwidth = 2;
0623: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0624: gridBagConstraints.insets = new java.awt.Insets(2, 20, 2, 0);
0625: jPanel3.add(jLabel3, gridBagConstraints);
0626:
0627: gridBagConstraints = new java.awt.GridBagConstraints();
0628: gridBagConstraints.gridx = 0;
0629: gridBagConstraints.gridy = 2;
0630: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0631: gridBagConstraints.weightx = 1.0;
0632: gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 0);
0633: jPanel3.add(jTextFieldReportFileName, gridBagConstraints);
0634:
0635: buttonGroup2.add(jRadioButton4);
0636: jRadioButton4.setSelected(true);
0637: jRadioButton4
0638: .setText("Store the directory name in a parameter");
0639: jRadioButton4.setBorder(javax.swing.BorderFactory
0640: .createEmptyBorder(0, 0, 0, 0));
0641: jRadioButton4.setFocusPainted(false);
0642: jRadioButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
0643: jRadioButton4.setMinimumSize(new java.awt.Dimension(115, 20));
0644: jRadioButton4.setPreferredSize(new java.awt.Dimension(115, 20));
0645: jRadioButton4
0646: .addItemListener(new java.awt.event.ItemListener() {
0647: public void itemStateChanged(
0648: java.awt.event.ItemEvent evt) {
0649: jRadioButton1ItemStateChanged2(evt);
0650: }
0651: });
0652: jRadioButton4
0653: .addActionListener(new java.awt.event.ActionListener() {
0654: public void actionPerformed(
0655: java.awt.event.ActionEvent evt) {
0656: jRadioButton1ActionPerformed2(evt);
0657: }
0658: });
0659:
0660: gridBagConstraints = new java.awt.GridBagConstraints();
0661: gridBagConstraints.gridx = 0;
0662: gridBagConstraints.gridwidth = 2;
0663: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0664: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
0665: gridBagConstraints.weightx = 1.0;
0666: gridBagConstraints.insets = new java.awt.Insets(40, 20, 0, 0);
0667: jPanel3.add(jRadioButton4, gridBagConstraints);
0668:
0669: jLabel1.setText("$P{SUBREPORT_DIR} + /name.jasper");
0670: gridBagConstraints = new java.awt.GridBagConstraints();
0671: gridBagConstraints.gridx = 0;
0672: gridBagConstraints.gridwidth = 2;
0673: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0674: gridBagConstraints.insets = new java.awt.Insets(2, 40, 0, 0);
0675: jPanel3.add(jLabel1, gridBagConstraints);
0676:
0677: buttonGroup2.add(jRadioButton5);
0678: jRadioButton5.setText("Use a static absolute path reference");
0679: jRadioButton5.setBorder(javax.swing.BorderFactory
0680: .createEmptyBorder(0, 0, 0, 0));
0681: jRadioButton5.setFocusPainted(false);
0682: jRadioButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
0683: jRadioButton5.setMinimumSize(new java.awt.Dimension(115, 20));
0684: jRadioButton5.setPreferredSize(new java.awt.Dimension(115, 20));
0685: jRadioButton5
0686: .addItemListener(new java.awt.event.ItemListener() {
0687: public void itemStateChanged(
0688: java.awt.event.ItemEvent evt) {
0689: jRadioButton2jRadioButton1ItemStateChanged1(evt);
0690: }
0691: });
0692: jRadioButton5
0693: .addActionListener(new java.awt.event.ActionListener() {
0694: public void actionPerformed(
0695: java.awt.event.ActionEvent evt) {
0696: jRadioButton2jRadioButton1ActionPerformed1(evt);
0697: }
0698: });
0699:
0700: gridBagConstraints = new java.awt.GridBagConstraints();
0701: gridBagConstraints.gridx = 0;
0702: gridBagConstraints.gridwidth = 2;
0703: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0704: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
0705: gridBagConstraints.weightx = 1.0;
0706: gridBagConstraints.insets = new java.awt.Insets(20, 20, 0, 0);
0707: jPanel3.add(jRadioButton5, gridBagConstraints);
0708:
0709: jLabel2e.setText("path reference");
0710: gridBagConstraints = new java.awt.GridBagConstraints();
0711: gridBagConstraints.gridx = 0;
0712: gridBagConstraints.gridwidth = 2;
0713: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0714: gridBagConstraints.insets = new java.awt.Insets(2, 40, 0, 0);
0715: jPanel3.add(jLabel2e, gridBagConstraints);
0716:
0717: jButton5.setText("Browse...");
0718: jButton5.addActionListener(new java.awt.event.ActionListener() {
0719: public void actionPerformed(java.awt.event.ActionEvent evt) {
0720: jButton5ActionPerformed(evt);
0721: }
0722: });
0723:
0724: gridBagConstraints = new java.awt.GridBagConstraints();
0725: gridBagConstraints.gridy = 2;
0726: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 10);
0727: jPanel3.add(jButton5, gridBagConstraints);
0728:
0729: setLayout(new java.awt.BorderLayout());
0730:
0731: }// </editor-fold>//GEN-END:initComponents
0732:
0733: private void jButtonSaveQueryActionPerformed(
0734: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveQueryActionPerformed
0735: Misc.saveSQLQuery(jRSQLExpressionArea1.getText(), this );
0736: }//GEN-LAST:event_jButtonSaveQueryActionPerformed
0737:
0738: private void jButtonLoadQueryActionPerformed(
0739: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLoadQueryActionPerformed
0740: String query = Misc.loadSQLQuery(this );
0741:
0742: if (query != null) {
0743: jRSQLExpressionArea1.setText(query);
0744: }
0745: }//GEN-LAST:event_jButtonLoadQueryActionPerformed
0746:
0747: private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
0748:
0749: // jfilechooser...
0750: JFileChooser jfc = new JFileChooser();
0751: File original_file = null;
0752: try {
0753: original_file = new File(MainFrame.getMainInstance()
0754: .getActiveReportFrame().getReport().getFilename());
0755: if (original_file != null
0756: && original_file.getParentFile() != null) {
0757: jfc.setCurrentDirectory(original_file.getParentFile());
0758: }
0759: } catch (Exception ex) {
0760:
0761: }
0762:
0763: jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {
0764: public boolean accept(java.io.File file) {
0765: String filename = file.getName().toLowerCase();
0766: return (filename.endsWith(".jrxml") || file
0767: .isDirectory());
0768: }
0769:
0770: public String getDescription() {
0771: return "JasperReports Report file *jrxml";
0772: }
0773: });
0774:
0775: if (jfc.showSaveDialog(this ) == JFileChooser.APPROVE_OPTION) {
0776:
0777: if (original_file != null
0778: && original_file.equals(jfc.getSelectedFile())) {
0779: JOptionPane
0780: .showMessageDialog(
0781: this ,
0782: I18n
0783: .getString(
0784: "messages.subreportWizardNewReport.duplicatedFile",
0785: "Master and report files can not be the same file!"));
0786: return;
0787: }
0788:
0789: String s = jfc.getSelectedFile().getPath();
0790: if (original_file != null
0791: && original_file.getParentFile() != null) {
0792: if (original_file.getParentFile().equals(
0793: jfc.getSelectedFile().getParentFile())) {
0794: s = jfc.getSelectedFile().getName();
0795: }
0796: }
0797: if (!s.toLowerCase().endsWith(".jrxml")) {
0798: if (!s.endsWith("."))
0799: s += ".";
0800: s += "jrmxl";
0801: }
0802: jTextFieldReportFileName.setText(s);
0803: }
0804: if (wizardPanel != null)
0805: wizardPanel.updateButtons();
0806:
0807: }//GEN-LAST:event_jButton5ActionPerformed
0808:
0809: private void jList3ValueChanged(
0810: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList3ValueChanged
0811: if (jList3.getSelectedIndex() >= 0) {
0812: IReportTemplate tf = (IReportTemplate) jList3
0813: .getSelectedValue();
0814: // Take the image...
0815:
0816: this .jLabelImage.setIcon(tf.getIcon());
0817: if (tf.getIcon() == null) {
0818: this .jLabelImage.setText(" ");
0819: } else {
0820: this .jLabelImage.setText("");
0821: }
0822:
0823: this .jLabelImage.updateUI();
0824: if (wizardPanel != null)
0825: wizardPanel.updateButtons();
0826: }
0827: }//GEN-LAST:event_jList3ValueChanged
0828:
0829: private void jRadioButtonTabularLayoutActionPerformed(
0830: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonTabularLayoutActionPerformed
0831: updateTemplatesList();
0832: }//GEN-LAST:event_jRadioButtonTabularLayoutActionPerformed
0833:
0834: private void jRadioButtonColumnarLayoutActionPerformed(
0835: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonColumnarLayoutActionPerformed
0836: updateTemplatesList();
0837: }//GEN-LAST:event_jRadioButtonColumnarLayoutActionPerformed
0838:
0839: private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
0840: int index = jList2.getSelectedIndex();
0841: if (index < 0)
0842: return;
0843:
0844: Object[] objs = jList2.getSelectedValues();
0845: for (int i = 0; i < objs.length; ++i) {
0846: Object obj = objs[i];
0847: ((javax.swing.DefaultListModel) jList1.getModel())
0848: .addElement(obj);
0849: ((javax.swing.DefaultListModel) jList2.getModel())
0850: .removeElement(obj);
0851: }
0852: if (jList1.getModel().getSize() > 0)
0853: jList1.setSelectedIndex(0);
0854: wizardPanel.updateButtons();
0855: }//GEN-LAST:event_jButton4ActionPerformed
0856:
0857: private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
0858: javax.swing.DefaultListModel list2 = (javax.swing.DefaultListModel) jList2
0859: .getModel();
0860: javax.swing.DefaultListModel list1 = (javax.swing.DefaultListModel) jList1
0861: .getModel();
0862:
0863: for (int i = 0; i < list2.getSize(); ++i) {
0864: list1.addElement(list2.getElementAt(i));
0865: }
0866: list2.removeAllElements();
0867: if (list1.size() > 0)
0868: jList1.setSelectedIndex(0);
0869: wizardPanel.updateButtons();
0870: }//GEN-LAST:event_jButton3ActionPerformed
0871:
0872: private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
0873: javax.swing.DefaultListModel list1 = (javax.swing.DefaultListModel) jList1
0874: .getModel();
0875: javax.swing.DefaultListModel list2 = (javax.swing.DefaultListModel) jList2
0876: .getModel();
0877:
0878: for (int i = 0; i < list1.getSize(); ++i) {
0879: list2.addElement(list1.getElementAt(i));
0880: }
0881: list1.removeAllElements();
0882: wizardPanel.updateButtons();
0883: }//GEN-LAST:event_jButton2ActionPerformed
0884:
0885: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
0886: int index = jList1.getSelectedIndex();
0887: if (index < 0)
0888: return;
0889:
0890: Object[] objs = jList1.getSelectedValues();
0891: for (int i = 0; i < objs.length; ++i) {
0892: Object obj = objs[i];
0893: ((javax.swing.DefaultListModel) jList2.getModel())
0894: .addElement(obj);
0895: ((javax.swing.DefaultListModel) jList1.getModel())
0896: .removeElement(obj);
0897: }
0898: if (jList1.getModel().getSize() > 0)
0899: jList1.setSelectedIndex(0);
0900: wizardPanel.updateButtons();
0901: }//GEN-LAST:event_jButton1ActionPerformed
0902:
0903: private void jTextFieldBeanActionPerformed(
0904: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldBeanActionPerformed
0905: jComboBoxConnectionActionPerformed(null);
0906: }//GEN-LAST:event_jTextFieldBeanActionPerformed
0907:
0908: private void jButtonNewConnectionActionPerformed(
0909: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewConnectionActionPerformed
0910: it.businesslogic.ireport.connection.gui.ConnectionDialog cd = new it.businesslogic.ireport.connection.gui.ConnectionDialog(
0911: wizardDialog, true);
0912:
0913: cd.setVisible(true);
0914:
0915: IReportConnection con = null;
0916: if (cd.getDialogResult() == JOptionPane.OK_OPTION) {
0917: con = cd.getIReportConnection();
0918: MainFrame.getMainInstance().getConnections()
0919: .addElement(con);
0920:
0921: if (MainFrame.getMainInstance().getConnections().size() == 1) {
0922: MainFrame.getMainInstance().setActiveConnection(con);
0923: } else {
0924: MainFrame.getMainInstance().saveiReportConfiguration();
0925: }
0926:
0927: this .updateConnections();
0928: this .jComboBoxConnection.setSelectedItem(con);
0929: }
0930: }//GEN-LAST:event_jButtonNewConnectionActionPerformed
0931:
0932: public void updateConnections() {
0933: Object ircDefault = MainFrame.getMainInstance().getProperties()
0934: .get("DefaultConnection");
0935: jComboBoxConnection.removeAllItems();
0936:
0937: jComboBoxConnection.addItem(new NullConnection());
0938:
0939: Enumeration e = MainFrame.getMainInstance().getConnections()
0940: .elements();
0941: while (e.hasMoreElements()) {
0942: IReportConnection irc = (IReportConnection) e.nextElement();
0943: jComboBoxConnection.addItem(irc);
0944: }
0945:
0946: if (ircDefault != null) {
0947: jComboBoxConnection.setSelectedItem(ircDefault);
0948: }
0949: }
0950:
0951: private void jComboBoxConnectionActionPerformed(
0952: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxConnectionActionPerformed
0953: boolean canNext = false;
0954: if (jComboBoxConnection.getSelectedItem() != null) {
0955: IReportConnection irc = (IReportConnection) jComboBoxConnection
0956: .getSelectedItem();
0957:
0958: if (irc.isJDBCConnection()) {
0959: jLabel2.setText("SQL query");
0960: jTextFieldBean.setVisible(false);
0961: jRSQLExpressionArea1.setVisible(true);
0962: if (jRSQLExpressionArea1.getText().length() > 0)
0963: canNext = true;
0964: } else if (irc instanceof JRHibernateConnection) {
0965: jLabel2.setText("HQL query");
0966: jTextFieldBean.setVisible(false);
0967: jRSQLExpressionArea1.setVisible(true);
0968: if (jRSQLExpressionArea1.getText().length() > 0)
0969: canNext = true;
0970: } else if (irc instanceof it.businesslogic.ireport.connection.JRDataSourceProviderConnection) {
0971: jLabel2.setText(" ");
0972: jTextFieldBean.setVisible(false);
0973: jRSQLExpressionArea1.setVisible(false);
0974: canNext = true;
0975: } else if (irc instanceof it.businesslogic.ireport.connection.JavaBeanDataSourceConnection) {
0976: jLabel2.setText("JavaBean class");
0977: jRSQLExpressionArea1.setVisible(false);
0978: jTextFieldBean.setVisible(true);
0979: if (jTextFieldBean.getText().length() > 0)
0980: canNext = true;
0981: } else if (irc instanceof it.businesslogic.ireport.connection.JRCSVDataSourceConnection) {
0982: jLabel2.setText(" ");
0983: jTextFieldBean.setVisible(false);
0984: jRSQLExpressionArea1.setVisible(false);
0985: canNext = true;
0986: } else if (irc instanceof it.businesslogic.ireport.connection.NullConnection) {
0987: jLabel2.setText(" ");
0988: jTextFieldBean.setVisible(false);
0989: jRSQLExpressionArea1.setVisible(false);
0990: canNext = true;
0991: } else {
0992: jLabel2
0993: .setText("You can't use the wizard with this kind of datasource");
0994: jRSQLExpressionArea1.setVisible(false);
0995: jTextFieldBean.setVisible(false);
0996: canNext = false;
0997: }
0998: } else {
0999: jLabel2
1000: .setText("Please create a new connection / datasource.");
1001: jRSQLExpressionArea1.setVisible(false);
1002: jTextFieldBean.setVisible(false);
1003: }
1004: jPanel5.setVisible(jRSQLExpressionArea1.isVisible());
1005: if (wizardPanel != null)
1006: wizardPanel.updateButtons();
1007: }//GEN-LAST:event_jComboBoxConnectionActionPerformed
1008:
1009: private void jRadioButton2jRadioButton1ActionPerformed1(
1010: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2jRadioButton1ActionPerformed1
1011: // TODO add your handling code here:
1012: }//GEN-LAST:event_jRadioButton2jRadioButton1ActionPerformed1
1013:
1014: private void jRadioButton2jRadioButton1ItemStateChanged1(
1015: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton2jRadioButton1ItemStateChanged1
1016: // TODO add your handling code here:
1017: }//GEN-LAST:event_jRadioButton2jRadioButton1ItemStateChanged1
1018:
1019: private void jRadioButton1ActionPerformed2(
1020: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed2
1021: // TODO add your handling code here:
1022: }//GEN-LAST:event_jRadioButton1ActionPerformed2
1023:
1024: private void jRadioButton1ItemStateChanged2(
1025: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged2
1026: // TODO add your handling code here:
1027: }//GEN-LAST:event_jRadioButton1ItemStateChanged2
1028:
1029: private void jPanel0PropertyChange(
1030: java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jPanel0PropertyChange
1031:
1032: }//GEN-LAST:event_jPanel0PropertyChange
1033:
1034: // Variables declaration - do not modify//GEN-BEGIN:variables
1035: private javax.swing.ButtonGroup buttonGroup1;
1036: private javax.swing.ButtonGroup buttonGroup2;
1037: private javax.swing.JButton jButton1;
1038: private javax.swing.JButton jButton2;
1039: private javax.swing.JButton jButton3;
1040: private javax.swing.JButton jButton4;
1041: private javax.swing.JButton jButton5;
1042: private javax.swing.JButton jButtonLoadQuery;
1043: private javax.swing.JButton jButtonNewConnection;
1044: private javax.swing.JButton jButtonSaveQuery;
1045: private javax.swing.JComboBox jComboBoxConnection;
1046: private javax.swing.JLabel jLabel1;
1047: private javax.swing.JLabel jLabel12;
1048: private javax.swing.JLabel jLabel2;
1049: private javax.swing.JLabel jLabel2e;
1050: private javax.swing.JLabel jLabel3;
1051: private javax.swing.JLabel jLabelImage;
1052: private javax.swing.JList jList1;
1053: private javax.swing.JList jList2;
1054: private javax.swing.JList jList3;
1055: private javax.swing.JPanel jPanel0;
1056: private javax.swing.JPanel jPanel1;
1057: private javax.swing.JPanel jPanel2;
1058: private javax.swing.JPanel jPanel3;
1059: private javax.swing.JPanel jPanel4;
1060: private javax.swing.JPanel jPanel41;
1061: private javax.swing.JPanel jPanel5;
1062: private javax.swing.JPanel jPanel6;
1063: private javax.swing.JPanel jPanel61;
1064: private javax.swing.JPanel jPanel7;
1065: private javax.swing.JPanel jPanelButtons;
1066: private it.businesslogic.ireport.gui.JRTextExpressionArea jRSQLExpressionArea1;
1067: private javax.swing.JRadioButton jRadioButton4;
1068: private javax.swing.JRadioButton jRadioButton5;
1069: private javax.swing.JRadioButton jRadioButtonColumnarLayout;
1070: private javax.swing.JRadioButton jRadioButtonTabularLayout;
1071: private javax.swing.JScrollPane jScrollPane1;
1072: private javax.swing.JScrollPane jScrollPane2;
1073: private javax.swing.JScrollPane jScrollPane3;
1074: private javax.swing.JTextField jTextFieldBean;
1075: private javax.swing.JTextField jTextFieldReportFileName;
1076:
1077: // End of variables declaration//GEN-END:variables
1078:
1079: public String[] getStepsNames() {
1080:
1081: String[] names = new String[4];
1082: //
1083: names[0] = I18n.getString(
1084: "subreportWizardNewReport.stepsnames.query",
1085: "Query/datasource");
1086: names[1] = I18n.getString(
1087: "subreportWizardNewReport.stepsnames.template",
1088: "Template");
1089: names[2] = I18n.getString(
1090: "subreportWizardNewReport.stepsnames.expression",
1091: "Expression");
1092: //names[3] = I18n.getString("subreportWizardNewReport.stepsnames.finish","Finish");
1093: //names[0] = "Query/datasource";
1094: //names[1] = "Fields";
1095: //names[2] = "Template";
1096: //names[3] = "Expression";
1097: //names[3] = "Finish";
1098: //
1099:
1100: return names;
1101: }
1102:
1103: public String getStepDescription(int step) {
1104:
1105: //
1106: if (step == 0)
1107: return I18n
1108: .getString(
1109: "subreportWizardExistingReport.stepdescription.step0",
1110: "How fill the subreport");
1111: //"How fill the subreport";
1112: if (step == 1)
1113: return I18n
1114: .getString(
1115: "subreportWizardExistingReport.stepdescription.step0",
1116: "Select the subreport fields");
1117: //"Select the subreport fields";
1118: if (step == 2)
1119: return I18n
1120: .getString(
1121: "subreportWizardExistingReport.stepdescription.step0",
1122: "Choose a template");
1123: //"Choose a template";
1124: if (step == 3)
1125: return I18n
1126: .getString(
1127: "subreportWizardExistingReport.stepdescription.step0",
1128: "Subreport expession");
1129: //"Subreport expession";
1130: //
1131:
1132: return "";
1133: }
1134:
1135: public void initWizard() {
1136: updateConnections();
1137: }
1138:
1139: public void finish(int currentStep) {
1140: if (currentStep < 0) {
1141: if (t != null && t.isAlive()) {
1142: t.interrupt();
1143: return;
1144: }
1145: }
1146: if (currentStep >= 0) {
1147: try {
1148: Report finalReport = createReport(
1149: ((IReportTemplate) jList3.getSelectedValue())
1150: .getXmlFile(),
1151: jRadioButtonColumnarLayout.isSelected() ? 1 : 0);
1152:
1153: if (jRadioButton4.isSelected()) {
1154: Report report = MainFrame.getMainInstance()
1155: .getActiveReportFrame().getReport();
1156: Vector v = report.getParameters();
1157: boolean found = false;
1158: for (int i = 0; i < report.getParameters().size(); ++i) {
1159: it.businesslogic.ireport.JRParameter param = (it.businesslogic.ireport.JRParameter) report
1160: .getParameters().elementAt(i);
1161:
1162: if (param.getName().equals("SUBREPORT_DIR")) {
1163: found = true;
1164:
1165: break;
1166: }
1167: }
1168: if (!found) {
1169: it.businesslogic.ireport.JRParameter param = new it.businesslogic.ireport.JRParameter(
1170: "SUBREPORT_DIR", "java.lang.String");
1171: //File f = new File( getReportFileName() );
1172:
1173: String s = MainFrame.getMainInstance()
1174: .getTranslatedCompileDirectory();
1175:
1176: if (s.length() > 0
1177: && !s.endsWith(File.separator))
1178: s += File.separator;
1179:
1180: s = Misc.string_replace("\\\\", "\\", s);
1181: s = "\"" + s + "\"";
1182:
1183: /*
1184: String s = f.getParent(); //Path();
1185: if (s!= null)
1186: {
1187: if (s.length() > 0 && !s.endsWith(File.separator))
1188: {
1189: s += File.separator;
1190: }
1191: }
1192: else
1193: {
1194: s = "";
1195: }
1196: s = Misc.string_replace("\\\\","\\",s);
1197: s = "\"" + s + "\"";
1198: */
1199: param.setDefaultValueExpression(s);
1200: report.addParameter(param);
1201: }
1202: getSubReportElement().setSubreportExpression(
1203: jLabel1.getText());
1204: } else {
1205: getSubReportElement().setSubreportExpression(
1206: jLabel2e.getText());
1207: }
1208: getSubReportElement().setSubreportExpressionClass(
1209: "java.lang.String");
1210:
1211: MainFrame.getMainInstance().openNewReportWindow(
1212: finalReport);
1213:
1214: } catch (Exception ex) {
1215: javax.swing.JOptionPane.showMessageDialog(getParent(),
1216: ex.getMessage() + "", I18n.getString(
1217: "message.title.error", "Error"),
1218: javax.swing.JOptionPane.ERROR_MESSAGE);
1219: ex.printStackTrace();
1220: }
1221: }
1222:
1223: this .getWizardDialog().setVisible(false);
1224: this .getWizardDialog().dispose();
1225: }
1226:
1227: public boolean nextStep(int nextStep) {
1228:
1229: if (nextStep == 0) // First step == 0
1230: {
1231:
1232: } else if (nextStep == 1) {
1233: // We must retrive fields...
1234: wizardPanel.getJButtonNext().setEnabled(false);
1235: wizardPanel.getJButtonPrev().setEnabled(false);
1236: wizardPanel.getJButtonFinish().setEnabled(false);
1237: t = new Thread(this );
1238: t.start();
1239: return false;
1240: } else if (nextStep == 2) {
1241:
1242: updateExpressionLabels();
1243: }
1244: return true;
1245: }
1246:
1247: public boolean previousStep(int previousStep) {
1248: return true;
1249: }
1250:
1251: public boolean canFinish(int currentStep) {
1252:
1253: if (currentStep < 3)
1254: return false;
1255: if (jTextFieldReportFileName.getText().trim().length() > 0) {
1256: String s = jTextFieldReportFileName.getText().trim();
1257: String s2 = MainFrame.getMainInstance()
1258: .getActiveReportFrame().getReport().getFilename();
1259: if (s.indexOf(File.separator) >= 0) {
1260: return (!s.equals(s2));
1261: } else {
1262: File f = new File(s2);
1263: return (!f.getName().equals(s));
1264: }
1265: }
1266: return false;
1267: }
1268:
1269: public boolean canNext(int currentStep) {
1270:
1271: if (currentStep == 0) {
1272: if (jComboBoxConnection.getSelectedItem() != null) {
1273: IReportConnection irc = (IReportConnection) jComboBoxConnection
1274: .getSelectedItem();
1275:
1276: if (irc.isJDBCConnection()) {
1277: if (jRSQLExpressionArea1.getText().length() > 0)
1278: return true;
1279: } else if (irc instanceof JRHibernateConnection) {
1280: jLabel2.setText("HQL query");
1281: jTextFieldBean.setVisible(false);
1282: jRSQLExpressionArea1.setVisible(true);
1283: if (jRSQLExpressionArea1.getText().length() > 0)
1284: return true;
1285: } else if (irc instanceof it.businesslogic.ireport.connection.JRDataSourceProviderConnection) {
1286: return true;
1287: } else if (irc instanceof it.businesslogic.ireport.connection.JavaBeanDataSourceConnection) {
1288: if (jTextFieldBean.getText().length() > 0)
1289: return true;
1290: } else if (irc instanceof it.businesslogic.ireport.connection.JRCSVDataSourceConnection) {
1291: return true;
1292: } else if (irc instanceof it.businesslogic.ireport.connection.NullConnection) {
1293: return true;
1294: } else {
1295: return false;
1296: }
1297: }
1298: return false;
1299: } else if (currentStep == 1) {
1300: IReportConnection irc = (IReportConnection) jComboBoxConnection
1301: .getSelectedItem();
1302: if (irc instanceof it.businesslogic.ireport.connection.NullConnection)
1303: return true;
1304: return jList2.getModel().getSize() > 0;
1305: } else if (currentStep == 2) {
1306: return jList3.getSelectedIndex() >= 0;
1307: }
1308: return false;
1309: }
1310:
1311: public boolean canPrevious(int currentStep) {
1312: return (currentStep > 0);
1313: }
1314:
1315: public JPanel getStepPanel(int step) {
1316:
1317: if (step == 0)
1318: return jPanel0;
1319: if (step == 1)
1320: return jPanel1;
1321: if (step == 2)
1322: return jPanel2;
1323: if (step == 3)
1324: return jPanel3;
1325: //if (step == 4) return jPanel4;
1326: return null;
1327: }
1328:
1329: public String getReportFileName() {
1330: return reportFileName;
1331: }
1332:
1333: public void setReportFileName(String reportFileName) {
1334: this .reportFileName = reportFileName;
1335: }
1336:
1337: public SubReportElement getSubReportElement() {
1338: return subReportElement;
1339: }
1340:
1341: public void setSubReportElement(SubReportElement subReportElement) {
1342: this .subReportElement = subReportElement;
1343: }
1344:
1345: public BaseWizardPanel getWizardPanel() {
1346: return wizardPanel;
1347: }
1348:
1349: public void setWizardPanel(BaseWizardPanel wizardPanel) {
1350: this .wizardPanel = wizardPanel;
1351: }
1352:
1353: public javax.swing.JDialog getWizardDialog() {
1354: return wizardDialog;
1355: }
1356:
1357: public void setWizardDialog(javax.swing.JDialog wizardDialog) {
1358: this .wizardDialog = wizardDialog;
1359: }
1360:
1361: /** When an object implementing interface <code>Runnable</code> is used
1362: * to create a thread, starting the thread causes the object's
1363: * <code>run</code> method to be called in that separately executing
1364: * thread.
1365: * <p>
1366: * The general contract of the method <code>run</code> is that it may
1367: * take any action whatsoever.
1368: *
1369: * @see java.lang.Thread#run()
1370: *
1371: */
1372: public void run() {
1373:
1374: Thread.currentThread().setContextClassLoader(
1375: MainFrame.getMainInstance().getReportClassLoader());
1376: // This method is invoked to read fields....
1377: try {
1378: IReportConnection irc = (IReportConnection) jComboBoxConnection
1379: .getSelectedItem();
1380:
1381: DefaultListModel dlm1 = (DefaultListModel) jList1
1382: .getModel();
1383: dlm1.removeAllElements();
1384:
1385: DefaultListModel dlm2 = (DefaultListModel) jList2
1386: .getModel();
1387: dlm2.removeAllElements();
1388: // Get fields....
1389: java.util.List fields = WizardDialog.readFields(irc,
1390: jRSQLExpressionArea1.getText(), jTextFieldBean
1391: .getText());
1392:
1393: if (fields == null) {
1394: cancelElaborationStep1();
1395: return;
1396: }
1397:
1398: for (int i = 0; i < fields.size(); ++i) {
1399: it.businesslogic.ireport.JRField field = (JRField) fields
1400: .get(i);
1401: // Check if parameter already exists...
1402: boolean found = false;
1403: for (int k = 0; i < dlm1.size(); ++k) {
1404: it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField) dlm1
1405: .getElementAt(k);
1406: if (f.getName().equalsIgnoreCase(field.getName())) {
1407: found = true;
1408: break;
1409: }
1410: }
1411: if (!found) {
1412: //this.getJReportFrame().getReport().getFields().addElement(field);
1413: dlm1.addElement(field);
1414: }
1415: if (jList1.getModel().getSize() > 0)
1416: jList1.setSelectedIndex(0);
1417: }
1418:
1419: wizardPanel.goStep(1);
1420:
1421: } catch (Exception ex) {
1422: java.io.StringWriter sw = new java.io.StringWriter();
1423: ex.printStackTrace(new java.io.PrintWriter(sw));
1424: javax.swing.JOptionPane.showMessageDialog(getParent(), sw
1425: .getBuffer()
1426: + "", I18n
1427: .getString("message.title.error", "Error"),
1428: javax.swing.JOptionPane.ERROR_MESSAGE);
1429: cancelElaborationStep1();
1430: return;
1431: }
1432:
1433: }
1434:
1435: public void cancelElaborationStep1() {
1436: wizardPanel.updateButtons();
1437: }
1438:
1439: public void updateTemplatesList() {
1440: if (templates == null) {
1441: loadTemplateFiles();
1442: if (templates == null)
1443: return;
1444: }
1445:
1446: ((javax.swing.DefaultListModel) jList3.getModel())
1447: .removeAllElements();
1448:
1449: for (int i = 0; i < templates.size(); ++i) {
1450: IReportTemplate itemplate = (IReportTemplate) templates
1451: .elementAt(i);
1452:
1453: if (jRadioButtonTabularLayout.isSelected()
1454: && itemplate.getType() != IReportTemplate.TABULAR)
1455: continue;
1456: if (jRadioButtonColumnarLayout.isSelected()
1457: && itemplate.getType() != IReportTemplate.COLUMNAR)
1458: continue;
1459: //if (jComboBoxTemplates.getItemCount()<2 || (jComboBoxTemplates.getSelectedIndex() == 0 && itemplate.getType() != IReportTemplate.COLUMNAR) ) continue;
1460: //if (jComboBoxTemplates.getSelectedIndex() == 1 && itemplate.getType() != IReportTemplate.TABULAR) continue;
1461: /*
1462: TemplateFile tf = new TemplateFile();
1463: tf.file = templates[i];
1464:
1465: tf.name = templates[i].getName().substring(0, templates[i].getName().length()-4);
1466: */
1467: ((javax.swing.DefaultListModel) jList3.getModel())
1468: .addElement(itemplate);
1469: }
1470: if (((javax.swing.DefaultListModel) jList3.getModel())
1471: .getSize() > 0)
1472: jList3.setSelectedIndex(0);
1473: jList3.updateUI();
1474: }
1475:
1476: public void loadTemplateFiles() {
1477: templates = new Vector();
1478: String templates_dir = MainFrame.IREPORT_HOME_DIR; //System.getProperty("ireport.home",".");
1479: templates_dir += File.separator + "templates";
1480: //System.out.println("Templates: " + templates_dir);
1481: //C:\\documenti\\progetti\\ireport\\iReport2\\templates
1482: try {
1483: File f = new File(templates_dir);
1484: File[] templates_files = null;
1485: if (f.exists() && f.isDirectory()) {
1486: templates_files = f.listFiles(new FilenameFilter() {
1487: public boolean accept(File dir, String name) {
1488: if (name.endsWith("T.xml")
1489: || name.endsWith("C.xml")) {
1490: return true;
1491: }
1492: return false;
1493: }
1494: });
1495: } else {
1496: templates_dir = MainFrame.IREPORT_HOME_DIR; //System.getProperty("ireport.home",".");
1497: templates_dir += File.separator + "etc"
1498: + File.separator + "templates";
1499: f = new File(templates_dir);
1500: if (f.exists() && f.isDirectory()) {
1501: templates_files = f.listFiles(new FilenameFilter() {
1502: public boolean accept(File dir, String name) {
1503: if (name.endsWith("T.xml")
1504: || name.endsWith("C.xml")) {
1505: return true;
1506: }
1507: return false;
1508: }
1509: });
1510: }
1511: }
1512:
1513: for (int i = 0; templates_files != null
1514: && i < templates_files.length; ++i) {
1515: IReportTemplate itemplate = new IReportTemplate();
1516: itemplate.setXmlFile(templates_files[i] + "");
1517: itemplate.setName(templates_files[i].getName());
1518: itemplate.setType(templates_files[i].getName()
1519: .toLowerCase().endsWith("c.xml") ? 0 : 1);
1520: try {
1521: String iconname = templates_files[i] + "";
1522: iconname = Misc.changeFileExtension(iconname,
1523: ".gif");
1524: itemplate.setIcon(new javax.swing.ImageIcon(
1525: iconname));
1526: } catch (Exception ex) {
1527: }
1528:
1529: templates.add(itemplate);
1530: }
1531:
1532: } catch (Exception ex) {
1533: }
1534:
1535: // try to look in the classpath...
1536: try {
1537: Vector xml_template_files = new Vector();
1538: Enumeration enum_pl = this .getClass().getClassLoader()
1539: .getResources("ireport/template.xml");
1540: while (enum_pl.hasMoreElements()) {
1541: Object oobj = enum_pl.nextElement();
1542: xml_template_files.add(oobj);
1543: }
1544:
1545: for (int i = 0; i < xml_template_files.size(); ++i) {
1546:
1547: Object source = xml_template_files.elementAt(i);
1548: // Create a Xerces DOM Parser
1549: DOMParser parser = new DOMParser();
1550: // Parse the Document
1551: // and traverse the DOM
1552: try {
1553:
1554: parser
1555: .setEntityResolver(new org.xml.sax.EntityResolver() {
1556: /* Code by Teodor Danciu */
1557: public org.xml.sax.InputSource resolveEntity(
1558: String publicId, String systemId)
1559: throws SAXException//, java.io.IOException
1560: {
1561: org.xml.sax.InputSource inputSource = null;
1562:
1563: if (systemId != null) {
1564: String dtd = null;
1565:
1566: if (systemId
1567: .equals("http://ireport.sourceforge.net/dtds/iReportTemplate.dtd")) {
1568: dtd = "it/businesslogic/ireport/dtds/iReportTemplate.dtd";
1569: } else {
1570: return new org.xml.sax.InputSource(
1571: systemId);
1572: }
1573:
1574: ClassLoader classLoader = this
1575: .getClass()
1576: .getClassLoader();
1577:
1578: java.io.InputStream is = classLoader
1579: .getResourceAsStream(dtd);
1580: if (is != null) {
1581: inputSource = new org.xml.sax.InputSource(
1582: is);
1583: }
1584:
1585: }
1586:
1587: return inputSource;
1588: }
1589: });
1590: /* End Code by Teodor Danciu */
1591: InputStream input_source = null;
1592: if (source instanceof java.io.File) {
1593: input_source = new FileInputStream(
1594: (java.io.File) source);
1595:
1596: } else if (source instanceof java.net.URL) {
1597:
1598: input_source = ((java.net.URL) source)
1599: .openStream();
1600:
1601: }
1602:
1603: parser.parse(new org.xml.sax.InputSource(
1604: input_source));
1605: Document document = parser.getDocument();
1606:
1607: //System.out.println("traverse");
1608: Node node = document.getDocumentElement();
1609:
1610: NodeList list = XPathAPI.selectNodeList(node,
1611: "/iReportTemplateSet/iReportTemplate");
1612: Node childnode = null;
1613:
1614: for (int n = 0; n < list.getLength(); n++) {
1615: IReportTemplate ireportTemplate = new IReportTemplate();
1616: childnode = XPathAPI.selectSingleNode(list
1617: .item(n), "@name");
1618: if (childnode != null)
1619: ireportTemplate.setName(childnode
1620: .getNodeValue());
1621: if (XPathAPI.eval(list.item(n),
1622: "@type = 'Tabular'").equals(
1623: XBoolean.S_TRUE)) {
1624: ireportTemplate
1625: .setType(IReportTemplate.TABULAR);
1626: } else {
1627: ireportTemplate
1628: .setType(IReportTemplate.COLUMNAR);
1629: }
1630: childnode = XPathAPI.selectSingleNode(list
1631: .item(n), "XmlFile/text()");
1632: if (childnode != null)
1633: ireportTemplate.setXmlFile(childnode
1634: .getNodeValue());
1635: childnode = XPathAPI.selectSingleNode(list
1636: .item(n), "IconFile/text()");
1637: if (childnode != null) {
1638: try {
1639: ireportTemplate
1640: .setIcon(new ImageIcon(
1641: getClass()
1642: .getClassLoader()
1643: .getResource(
1644: childnode
1645: .getNodeValue())));
1646: } catch (DOMException e) {
1647: // Don't care
1648: e.printStackTrace();
1649: }
1650: }
1651:
1652: templates.add(ireportTemplate);
1653: }
1654: } catch (SAXException e) {
1655: System.err.println(e);
1656: } catch (java.io.IOException e) {
1657: System.err.println(e);
1658: }
1659: } // End cycle on iReport plugin files...
1660:
1661: } catch (Exception ex) {
1662: MainFrame.getMainInstance().logOnConsole(
1663: "Error searching ireport/template.xml resources\n");
1664: }
1665:
1666: }
1667:
1668: public void updateExpressionLabels() {
1669: String fileName = jTextFieldReportFileName.getText().trim();
1670:
1671: if (fileName.length() == 0) {
1672: jLabel1.setText("");
1673: jLabel2e.setText("");
1674: } else {
1675: File f = new File(fileName);
1676:
1677: String s = f.getName();
1678: if (!s.toLowerCase().endsWith(".jasper")) {
1679: if (s.lastIndexOf(".") > 0) {
1680: s = s.substring(0, s.lastIndexOf("."));
1681: }
1682: s += ".jasper";
1683: }
1684:
1685: jLabel1.setText("$P{SUBREPORT_DIR} + \"" + s + "\"");
1686:
1687: String s2 = MainFrame.getMainInstance()
1688: .getTranslatedCompileDirectory();
1689: f = new File(fileName);
1690:
1691: f = new File(s2, Misc.string_replace(".jasper", ".jrxml", f
1692: .getName()));
1693: s2 = Misc.string_replace("\\\\", "\\", "" + f);
1694: jLabel2e.setText("\"" + s2 + "\"");
1695: }
1696:
1697: }
1698:
1699: /*
1700: *
1701: * type=1 -> TABULAR
1702: * type=2 -> COLUMNAR
1703: */
1704: public Report createReport(String templateFileName, int reportType)
1705: throws Exception {
1706:
1707: Report template = new Report(templateFileName);
1708:
1709: template.incrementReportChanges();
1710:
1711: String s = jTextFieldReportFileName.getText().trim();
1712: String s2 = MainFrame.getMainInstance().getActiveReportFrame()
1713: .getReport().getFilename();
1714: if (s.indexOf(File.separator) >= 0) {
1715: template.setFilename(s);
1716: } else {
1717: File f = new File(s2);
1718: s2 = f.getParent();
1719: if (s2.length() > 0 && !s2.endsWith(File.separator))
1720: s2 = s2 + File.separator;
1721: s2 += s;
1722: template.setFilename(s2);
1723: }
1724:
1725: // remove all bands except column header and detail...
1726:
1727: //2. Find detail and column header bands...
1728: Band detail = null;
1729: Band columns = null;
1730:
1731: Enumeration e = template.getBands().elements();
1732: while (e.hasMoreElements()) {
1733: Band band = (Band) e.nextElement();
1734: if (band.getName().equals("detail")) {
1735: detail = band;
1736: } else if (band.getName().equals("columnHeader")) {
1737: columns = band;
1738: }
1739: }
1740:
1741: // 1. Normalize position to band...
1742: e = template.getElements().elements();
1743: while (e.hasMoreElements()) {
1744: ReportElement rElement = (ReportElement) e.nextElement();
1745: rElement.trasform(new java.awt.Point(0, -template
1746: .getBandYLocation(rElement.getBand())),
1747: TransformationType.TRANSFORMATION_MOVE);
1748: }
1749:
1750: if (reportType == 0) // TABULAR
1751: {
1752: //1. Adding fields...
1753: int currentx = template.getLeftMargin() + 10;
1754: int currenty = 10;
1755: e = template.getElements().elements();
1756: StaticTextReportElement detailLabel = null;
1757: TextFieldReportElement detailField = null;
1758: while (e.hasMoreElements()
1759: && (detailLabel == null || detailField == null)) {
1760: ReportElement rElement = (ReportElement) e
1761: .nextElement();
1762: if (rElement instanceof StaticTextReportElement) {
1763: StaticTextReportElement stre = (StaticTextReportElement) rElement;
1764: if (stre.getText().equalsIgnoreCase("DetailLabel"))
1765: detailLabel = stre;
1766: } else if (rElement instanceof TextFieldReportElement) {
1767: TextFieldReportElement tfre = (TextFieldReportElement) rElement;
1768: if (tfre.getText().equalsIgnoreCase("DetailField"))
1769: detailField = tfre;
1770: }
1771: }
1772:
1773: if (detailField != null)
1774: template.getElements().removeElement(detailField);
1775: if (detailLabel != null)
1776: template.getElements().removeElement(detailLabel);
1777:
1778: if (detailField == null)
1779: detailField = new TextFieldReportElement(0, 0, 100, 20);
1780: if (detailLabel == null)
1781: detailLabel = new StaticTextReportElement(0, 0, 100, 18);
1782:
1783: int nfields = jList2.getModel().getSize();
1784: int fwidth = template.getColumnWidth()
1785: / ((nfields <= 0) ? 1 : nfields);
1786:
1787: for (int i = 0; i < jList2.getModel().getSize(); ++i) {
1788: // FIELD
1789: it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField) jList2
1790: .getModel().getElementAt(i);
1791: template.addField(f);
1792:
1793: TextFieldReportElement re = (TextFieldReportElement) detailField
1794: .cloneMe();
1795: re.setPosition(new java.awt.Point(currentx, detailField
1796: .getPosition().y));
1797: re.setWidth(fwidth);
1798: re.updateBounds();
1799: re.setText("$F{" + f.getName() + "}");
1800:
1801: re.setBand(detail);
1802: re.setMatchingClassExpression(f.getClassType(), true);
1803: template.getElements().addElement(re);
1804:
1805: // COLUMN LABEL...
1806: StaticTextReportElement sre = (StaticTextReportElement) detailLabel
1807: .cloneMe();
1808: sre.setPosition(new java.awt.Point(currentx,
1809: detailLabel.getPosition().y));
1810: sre.setWidth(fwidth);
1811: sre.updateBounds();
1812: sre.setText("" + f.getName() + "");
1813: sre.setBand(columns);
1814: template.getElements().addElement(sre);
1815:
1816: currentx += fwidth;
1817: currentx = Math
1818: .min(template.getWidth()
1819: - template.getRightMargin() + 10 - 30,
1820: currentx);
1821: }
1822: } else {
1823: //1. Adding fields...
1824: int currentx = template.getLeftMargin() + 10;
1825: int currenty = 10;
1826: e = template.getElements().elements();
1827: StaticTextReportElement detailLabel = null;
1828: TextFieldReportElement detailField = null;
1829: while (e.hasMoreElements()
1830: && (detailLabel == null || detailField == null)) {
1831: ReportElement rElement = (ReportElement) e
1832: .nextElement();
1833: if (rElement instanceof StaticTextReportElement) {
1834: StaticTextReportElement stre = (StaticTextReportElement) rElement;
1835: if (stre.getText().equalsIgnoreCase("DetailLabel"))
1836: detailLabel = stre;
1837: } else if (rElement instanceof TextFieldReportElement) {
1838: TextFieldReportElement tfre = (TextFieldReportElement) rElement;
1839: if (tfre.getText().equalsIgnoreCase("DetailField"))
1840: detailField = tfre;
1841: }
1842: }
1843:
1844: if (detailField != null)
1845: template.getElements().removeElement(detailField);
1846: if (detailLabel != null)
1847: template.getElements().removeElement(detailLabel);
1848:
1849: if (detailField == null)
1850: detailField = new TextFieldReportElement(0, 0, 100, 20);
1851: if (detailLabel == null)
1852: detailLabel = new StaticTextReportElement(0, 0, 100, 18);
1853:
1854: int nfields = jList2.getModel().getSize();
1855:
1856: int fwidth = template.getColumnWidth()
1857: / ((nfields <= 0) ? 1 : nfields);
1858: int ffheight = detailField.getPosition().y;
1859:
1860: for (int i = 0; i < jList2.getModel().getSize(); ++i) {
1861: // FIELD
1862: it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField) jList2
1863: .getModel().getElementAt(i);
1864: template.addField(f);
1865:
1866: TextFieldReportElement re = (TextFieldReportElement) detailField
1867: .cloneMe();
1868: re.setPosition(new java.awt.Point(detailField
1869: .getPosition().x, ffheight));
1870: re.updateBounds();
1871: re.setText("$F{" + f.getName() + "}");
1872:
1873: re.setBand(detail);
1874: re.setMatchingClassExpression(f.getClassType(), true);
1875:
1876: template.getElements().addElement(re);
1877:
1878: // COLUMN LABEL...
1879: StaticTextReportElement sre = (StaticTextReportElement) detailLabel
1880: .cloneMe();
1881: sre.setPosition(new java.awt.Point(detailLabel
1882: .getPosition().x, ffheight));
1883: sre.setWidth(fwidth);
1884: sre.updateBounds();
1885: sre.setText("" + f.getName() + "");
1886: sre.setBand(detail);
1887: template.getElements().addElement(sre);
1888:
1889: ffheight += detailField.position.y + detailField.height
1890: - 10;
1891: }
1892: if (nfields != 0)
1893: detail.setHeight(ffheight);
1894:
1895: }
1896:
1897: // Remove template groups...****************
1898: e = template.getElements().elements();
1899: Vector elements_to_delete = new Vector();
1900: while (e.hasMoreElements()) {
1901: ReportElement rElement = (ReportElement) e.nextElement();
1902: if (rElement.getBand() != detail
1903: && rElement.getBand() != columns) {
1904: elements_to_delete.addElement(rElement);
1905: }
1906: }
1907:
1908: e = elements_to_delete.elements();
1909: while (e.hasMoreElements()) {
1910: template.getElements().removeElement(e.nextElement());
1911: }
1912:
1913: Group g;
1914: if ((g = template.getGroupByName("Group1")) != null) {
1915: template.getBands().removeElement(g.getGroupFooter());
1916: template.getBands().removeElement(g.getGroupHeader());
1917: template.getGroups().removeElement(g);
1918: }
1919: if ((g = template.getGroupByName("Group2")) != null) {
1920: template.getBands().removeElement(g.getGroupFooter());
1921: template.getBands().removeElement(g.getGroupHeader());
1922: template.getGroups().removeElement(g);
1923: }
1924: if ((g = template.getGroupByName("Group3")) != null) {
1925: template.getBands().removeElement(g.getGroupFooter());
1926: template.getBands().removeElement(g.getGroupHeader());
1927: template.getGroups().removeElement(g);
1928: }
1929:
1930: if ((g = template.getGroupByName("Group4")) != null) {
1931: template.getBands().removeElement(g.getGroupFooter());
1932: template.getBands().removeElement(g.getGroupHeader());
1933: template.getGroups().removeElement(g);
1934: }
1935:
1936: e = template.getBands().elements();
1937: while (e.hasMoreElements()) {
1938: Band band = (Band) e.nextElement();
1939: if (band != detail && band != columns) {
1940: band.setHeight(0);
1941: }
1942: }
1943:
1944: // Remove margins...
1945:
1946: int leftMargin = template.getLeftMargin();
1947: template.setWidth(template.getWidth()
1948: - template.getLeftMargin() - template.getRightMargin());
1949: template.setLeftMargin(0);
1950: template.setRightMargin(0);
1951: template.setHeight(template.getHeight()
1952: - template.getTopMargin() - template.getBottomMargin());
1953: template.setTopMargin(0);
1954: template.setBottomMargin(0);
1955:
1956: e = template.getElements().elements();
1957: while (e.hasMoreElements()) {
1958: ReportElement rElement = (ReportElement) e.nextElement();
1959: rElement.trasform(new java.awt.Point(-leftMargin, template
1960: .getBandYLocation(rElement.getBand())),
1961: TransformationType.TRANSFORMATION_MOVE);
1962: }
1963:
1964: if (jComboBoxConnection.getSelectedItem() instanceof JDBCConnection) {
1965: getSubReportElement().setConnectionExpression(
1966: "$P{REPORT_CONNECTION}");
1967: getSubReportElement().setUseConnection(true);
1968: template.setQuery(jRSQLExpressionArea1.getText());
1969:
1970: } else if (jComboBoxConnection.getSelectedItem() instanceof JRHibernateConnection) {
1971: template.setQuery(jRSQLExpressionArea1.getText());
1972: template.setQueryLanguage("hql");
1973: } else if (jComboBoxConnection.getSelectedItem() instanceof NullConnection) {
1974: template.setWhenNoDataType("AllSectionsNoDetail");
1975: }
1976:
1977: //System.out.println("Saving: " + template.getFilename());
1978: template.saveXMLFile();
1979: return template;
1980: }
1981:
1982: public void applyI18n() {
1983: // Start autogenerated code ----------------------
1984: jRadioButton4.setText(I18n.getString(
1985: "subreportWizardNewReport.radioButton4",
1986: "Store the directory name in a parameter"));
1987: jRadioButton5.setText(I18n.getString(
1988: "subreportWizardNewReport.radioButton5",
1989: "Use a static absolute path reference"));
1990: jRadioButtonColumnarLayout.setText(I18n.getString(
1991: "subreportWizardNewReport.radioButtonColumnarLayout",
1992: "Columnar layout"));
1993: jRadioButtonTabularLayout.setText(I18n.getString(
1994: "subreportWizardNewReport.radioButtonTabularLayout",
1995: "Tabular layout"));
1996: // End autogenerated code ----------------------
1997: // Start autogenerated code ----------------------
1998: jButton1.setText(I18n.getString(
1999: "subreportWizardNewReport.button1", ">"));
2000: jButton2.setText(I18n.getString(
2001: "subreportWizardNewReport.button2", ">>"));
2002: jButton3.setText(I18n.getString(
2003: "subreportWizardNewReport.button3", "<<"));
2004: jButton4.setText(I18n.getString(
2005: "subreportWizardNewReport.button4", "<"));
2006: jButton5.setText(I18n.getString(
2007: "subreportWizardNewReport.button5", "Browse..."));
2008: jButtonLoadQuery.setText(I18n.getString(
2009: "subreportWizardNewReport.buttonLoadQuery",
2010: "Load query"));
2011: jButtonNewConnection.setText(I18n.getString(
2012: "subreportWizardNewReport.buttonNewConnection", "New"));
2013: jButtonSaveQuery.setText(I18n.getString(
2014: "subreportWizardNewReport.buttonSaveQuery",
2015: "Save query"));
2016: jLabel1.setText(I18n.getString(
2017: "subreportWizardNewReport.label1",
2018: "$P{SUBREPORT_DIR} + /name.jasper"));
2019: jLabel12.setText(I18n.getString(
2020: "subreportWizardNewReport.label12",
2021: "Connection / Datasource"));
2022: jLabel2.setText(I18n.getString(
2023: "subreportWizardNewReport.label2", "Query"));
2024: jLabel2e.setText(I18n.getString(
2025: "subreportWizardNewReport.label2e", "path reference"));
2026: jLabel3.setText(I18n.getString(
2027: "subreportWizardNewReport.label3",
2028: "Save the subreport as..."));
2029: jLabelImage.setText(I18n.getString(
2030: "subreportWizardNewReport.labelImage", " "));
2031: // End autogenerated code ----------------------
2032: }
2033: }
2034:
2035: class TemplateFile {
2036:
2037: public File file = null;
2038: public String name = "";
2039:
2040: public String toString() {
2041: return name;
2042: }
2043: }
|