KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > data > MDXFieldsProvider


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  *
21  *
22  * SQLFieldsProvider.java
23  *
24  * Created on December 7, 2006, 9:22 AM
25  *
26  * To change this template, choose Tools | Template Manager
27  * and open the template in the editor.
28  */

29
30 package it.businesslogic.ireport.data;
31
32 import it.businesslogic.ireport.FieldsProvider;
33 import it.businesslogic.ireport.FieldsProviderEditor;
34 import it.businesslogic.ireport.IReportConnection;
35 import it.businesslogic.ireport.connection.JRXMLADataSourceConnection;
36 import it.businesslogic.ireport.data.olap.OlapBrowser;
37 import it.businesslogic.ireport.gui.MainFrame;
38 import it.businesslogic.ireport.gui.ReportQueryDialog;
39 import it.businesslogic.ireport.util.I18n;
40 import java.awt.Component JavaDoc;
41 import java.util.Map JavaDoc;
42 import net.sf.jasperreports.engine.JRDataset;
43 import net.sf.jasperreports.engine.JRException;
44 import net.sf.jasperreports.engine.JRField;
45 import rex.event.RexWizardEvent;
46 import rex.event.RexWizardListener;
47 import rex.graphics.mdxeditor.RexWizard;
48
49 /**
50  *
51  * @author gtoffoli
52  */

53 public class MDXFieldsProvider implements FieldsProvider, RexWizardListener {
54     
55     private OlapBrowser olapBrowser = null;
56     protected String JavaDoc getQueryFromRex = "";
57     
58     public static boolean useVisualDesigner = true;
59     
60     static {
61         
62         java.util.Properties JavaDoc p = new java.util.Properties JavaDoc();
63         try {
64             p.load( MDXFieldsProvider.class.getClass().getResourceAsStream("/it/businesslogic/ireport/data/fieldsprovider.properties") );
65
66             if (p.getProperty("mdx").equals("0"))
67             {
68                 useVisualDesigner = false;
69                 System.out.println("ReX designer disabled");
70             }
71         } catch (Exception JavaDoc ex)
72         {
73             ex.printStackTrace();
74         }
75         
76     }
77     
78     
79     
80     /** Creates a new instance of SQLFieldsProvider */
81     public MDXFieldsProvider() {
82     }
83
84     /**
85      * Returns true if the provider supports the {@link #getFields(IReportConnection,JRDataset,Map) getFields}
86      * operation. By returning true in this method the data source provider indicates
87      * that it is able to introspect the data source and discover the available fields.
88      *
89      * @return true if the getFields() operation is supported.
90      */

91     public boolean supportsGetFieldsOperation() {
92         return false;
93     }
94     
95     public JRField[] getFields(IReportConnection con, JRDataset reportDataset, Map JavaDoc parameters) throws JRException, UnsupportedOperationException JavaDoc {
96         return null;
97     }
98
99     public boolean supportsAutomaticQueryExecution() {
100         return true;
101     }
102
103     public boolean hasQueryDesigner() {
104         return useVisualDesigner;
105     }
106
107     public boolean hasEditorComponent() {
108         return true;
109     }
110
111     /**
112      * Copyright (C) 2006 CINCOM SYSTEMS, INC.
113      * All Rights Reserved
114      * www.cincom.com
115      */

116     
117    /*
118      * Opens the Rex MDX Query Editor
119      * @param MdxQuery
120      * @retrun mdx Query from REX
121      * sending the Query to Rex and bringing back the modified MDX query
122      */

123     boolean gotMdxResult = false;
124     public String JavaDoc designQuery(IReportConnection con, String JavaDoc query, ReportQueryDialog reportQueryDialog) throws JRException, UnsupportedOperationException JavaDoc {
125         
126         String JavaDoc newMDXQuery = query;
127         if (query == null) newMDXQuery = "";
128         
129         if (con instanceof JRXMLADataSourceConnection)
130         {
131             String JavaDoc strURL = ((JRXMLADataSourceConnection)con).getUrl();
132         
133             String JavaDoc strDataSource = ((JRXMLADataSourceConnection)con).getDatasource();
134
135             String JavaDoc strCatalog = ((JRXMLADataSourceConnection)con).getCatalog();
136
137             String JavaDoc strCubeName=((JRXMLADataSourceConnection)con).getCube();
138             
139             //invoke MDXEditor
140

141             RexWizard mdxWizard= new RexWizard(strURL, strDataSource, strCatalog,
142                     strCubeName,newMDXQuery);
143             // Passing the MDX Query to Rex Wizard
144
mdxWizard.addRexWizardListener(this);
145
146             mdxWizard.showDialog();
147             
148             //Wait for the return value....
149
//System.out.println("Waiting for MDX query");
150
//System.out.flush();
151
//while (!gotMdxResult)
152
//{
153
// Thread.yield();
154
//}
155

156             //System.out.println("My MDX query " + getQueryFromRex);
157
//System.out.flush();
158
//condition added to handle Cancel click's in RexWizard
159
if (getQueryFromRex.length() > 0){
160                 return getQueryFromRex;
161             }
162         }
163         else
164         {
165             javax.swing.JOptionPane.showMessageDialog(MainFrame.getMainInstance(),
166                         I18n.getString("messages.reportQueryDialog.connectionNotSupported","In order to use the MDX query designer, you need an XMLA datasource active."),
167                         "",javax.swing.JOptionPane.WARNING_MESSAGE );
168                 return null;
169             
170         }
171         
172         return query;
173     }
174     
175     /**
176      * Rex Passes the MDX query to Report Query Dialog
177      */

178      public void getMdx(RexWizardEvent evt){
179
180           getQueryFromRex = evt.getQuery();
181           gotMdxResult = true;
182
183      }
184
185 /* end of modifications */
186
187     public FieldsProviderEditor getEditorComponent(ReportQueryDialog reportQueryDialog) {
188         
189         if (olapBrowser == null)
190         {
191             olapBrowser = new OlapBrowser();
192             olapBrowser.setReportQueryDialog(reportQueryDialog);
193             if (reportQueryDialog != null)
194             {
195                 olapBrowser.setJTableFields( reportQueryDialog.getFieldsTable() );
196             }
197         }
198         return olapBrowser;
199     }
200     
201 }
202
Popular Tags