001: /*
002: * Copyright (C) 2005-2007 JasperSoft http://www.jaspersoft.com
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * This program is distributed WITHOUT ANY WARRANTY; and without the
010: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
011: * See the GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License
014: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
015: * or write to:
016: *
017: * Free Software Foundation, Inc.,
018: * 59 Temple Place - Suite 330,
019: * Boston, MA USA 02111-1307
020: *
021: *
022: * EJBQLBeanInspectorPanel.java
023: *
024: * Created on December 7, 2006, 1:27 PM
025: *
026: * To change this template, choose Tools | Template Manager
027: * and open the template in the editor.
028: */
029:
030: package it.businesslogic.ireport.data;
031:
032: import it.businesslogic.ireport.JRField;
033: import it.businesslogic.ireport.data.ejbql.EJBQLFieldsReader;
034: import it.businesslogic.ireport.gui.MainFrame;
035: import java.util.ArrayList;
036: import java.util.List;
037: import java.util.Vector;
038:
039: /**
040: *
041: * @author gtoffoli
042: */
043: public class EJBQLBeanInspectorPanel extends BeanInspectorPanel {
044:
045: /** Creates a new instance of EJBQLBeanInspectorPanel */
046: public EJBQLBeanInspectorPanel() {
047: super ();
048:
049: }
050:
051: /**
052: * Ad hoc queryChanged method for EJBQL queries....
053: */
054: public void queryChanged(String newQuery) {
055:
056: lastExecution++;
057: int this Execution = lastExecution;
058: // Execute a thread to perform the query change...
059:
060: String error_msg = "";
061: lastExecution++;
062:
063: int in = lastExecution;
064:
065: getReportQueryDialog().getJLabelStatusSQL().setText(
066: "Executing EJBQL query....");
067: /////////////////////////////
068:
069: try {
070: Thread.currentThread().setContextClassLoader(
071: MainFrame.getMainInstance().getReportClassLoader());
072: } catch (Exception ex) {
073: ex.printStackTrace();
074: }
075:
076: if (in < lastExecution)
077: return; //Abort, new execution requested
078:
079: EJBQLFieldsReader ejbqlFR = new EJBQLFieldsReader(newQuery,
080: getReportQueryDialog().getSubDataset().getParameters());
081:
082: try {
083: Vector fields = ejbqlFR.readFields();
084:
085: List columns = new ArrayList();
086: for (int i = 0; i < fields.size(); ++i) {
087: JRField field = (JRField) fields.elementAt(i);
088: columns.add(new Object[] { field, field.getClassType(),
089: field.getDescription() });
090: }
091: Vector v = null;
092: if (ejbqlFR.getSingleClassName() != null) {
093: v = new Vector();
094: v.add(ejbqlFR.getSingleClassName());
095: }
096:
097: System.out.println("Single class name: "
098: + ejbqlFR.getSingleClassName());
099:
100: setBeanExplorerFromWorker(v, true, false);
101: setColumnsFromWorker(columns);
102:
103: } catch (Exception ex) {
104: ex.printStackTrace();
105: setBeanExplorerFromWorker(null, true, false);
106: setColumnErrorFromWork("Error: " + ex.getMessage());
107: }
108:
109: getReportQueryDialog().getJLabelStatusSQL().setText("Ready");
110: }
111:
112: }
|