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: * SQLFieldsProvider.java
023: *
024: * Created on December 7, 2006, 9:22 AM
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.FieldsProvider;
033: import it.businesslogic.ireport.FieldsProviderEditor;
034: import it.businesslogic.ireport.IReportConnection;
035: import it.businesslogic.ireport.connection.JRXMLADataSourceConnection;
036: import it.businesslogic.ireport.data.olap.CustomHTTPAuthenticator;
037: import it.businesslogic.ireport.data.olap.OlapBrowser;
038: import it.businesslogic.ireport.gui.MainFrame;
039: import it.businesslogic.ireport.gui.ReportQueryDialog;
040: import it.businesslogic.ireport.util.I18n;
041:
042: import java.awt.Component;
043: import java.net.Authenticator;
044: import java.util.Map;
045: import net.sf.jasperreports.engine.JRDataset;
046: import net.sf.jasperreports.engine.JRException;
047: import net.sf.jasperreports.engine.JRField;
048: import rex.event.RexWizardEvent;
049: import rex.event.RexWizardListener;
050: import rex.graphics.mdxeditor.RexWizard;
051:
052: /**
053: *
054: * @author gtoffoli
055: */
056: public class MDXFieldsProvider implements FieldsProvider,
057: RexWizardListener {
058:
059: private OlapBrowser olapBrowser = null;
060: protected String getQueryFromRex = "";
061:
062: public static boolean useVisualDesigner = true;
063:
064: static {
065:
066: java.util.Properties p = new java.util.Properties();
067: try {
068: p
069: .load(MDXFieldsProvider.class
070: .getClass()
071: .getResourceAsStream(
072: "/it/businesslogic/ireport/data/fieldsprovider.properties"));
073:
074: if (p.getProperty("mdx").equals("0")) {
075: useVisualDesigner = false;
076: System.out.println("ReX designer disabled");
077: }
078: } catch (Exception ex) {
079: ex.printStackTrace();
080: }
081:
082: }
083:
084: /** Creates a new instance of SQLFieldsProvider */
085: public MDXFieldsProvider() {
086: }
087:
088: /**
089: * Returns true if the provider supports the {@link #getFields(IReportConnection,JRDataset,Map) getFields}
090: * operation. By returning true in this method the data source provider indicates
091: * that it is able to introspect the data source and discover the available fields.
092: *
093: * @return true if the getFields() operation is supported.
094: */
095: public boolean supportsGetFieldsOperation() {
096: return false;
097: }
098:
099: public JRField[] getFields(IReportConnection con,
100: JRDataset reportDataset, Map parameters)
101: throws JRException, UnsupportedOperationException {
102: return null;
103: }
104:
105: public boolean supportsAutomaticQueryExecution() {
106: return true;
107: }
108:
109: public boolean hasQueryDesigner() {
110: return useVisualDesigner;
111: }
112:
113: public boolean hasEditorComponent() {
114: return true;
115: }
116:
117: /**
118: * Copyright (C) 2006 CINCOM SYSTEMS, INC.
119: * All Rights Reserved
120: * www.cincom.com
121: */
122:
123: /*
124: * Opens the Rex MDX Query Editor
125: * @param MdxQuery
126: * @retrun mdx Query from REX
127: * sending the Query to Rex and bringing back the modified MDX query
128: */
129: boolean gotMdxResult = false;
130:
131: public String designQuery(IReportConnection con, String query,
132: ReportQueryDialog reportQueryDialog) throws JRException,
133: UnsupportedOperationException {
134:
135: String newMDXQuery = query;
136: if (query == null)
137: newMDXQuery = "";
138:
139: if (con instanceof JRXMLADataSourceConnection) {
140: String strURL = ((JRXMLADataSourceConnection) con).getUrl();
141:
142: String strDataSource = ((JRXMLADataSourceConnection) con)
143: .getDatasource();
144:
145: String strCatalog = ((JRXMLADataSourceConnection) con)
146: .getCatalog();
147:
148: String strCubeName = ((JRXMLADataSourceConnection) con)
149: .getCube();
150:
151: String username = ((JRXMLADataSourceConnection) con)
152: .getUsername();
153: if (username != null && username.length() > 0) {
154:
155: Authenticator.setDefault(new CustomHTTPAuthenticator(
156: username, ((JRXMLADataSourceConnection) con)
157: .getPassword()));
158: }
159:
160: //invoke MDXEditor
161: RexWizard mdxWizard = new RexWizard(strURL, strDataSource,
162: strCatalog, strCubeName, newMDXQuery, I18n
163: .getCurrentLocale());
164: // Passing the MDX Query to Rex Wizard
165: mdxWizard.addRexWizardListener(this );
166:
167: mdxWizard.showDialog();
168:
169: //Wait for the return value....
170: //System.out.println("Waiting for MDX query");
171: //System.out.flush();
172: //while (!gotMdxResult)
173: //{
174: // Thread.yield();
175: //}
176:
177: //System.out.println("My MDX query " + getQueryFromRex);
178: //System.out.flush();
179: //condition added to handle Cancel click's in RexWizard
180: if (getQueryFromRex.length() > 0) {
181: return getQueryFromRex;
182: }
183: } else {
184: javax.swing.JOptionPane
185: .showMessageDialog(
186: MainFrame.getMainInstance(),
187: I18n
188: .getString(
189: "messages.reportQueryDialog.connectionNotSupported",
190: "In order to use the MDX query designer, you need an XMLA datasource active."),
191: "", javax.swing.JOptionPane.WARNING_MESSAGE);
192: return null;
193:
194: }
195:
196: return query;
197: }
198:
199: /**
200: * Rex Passes the MDX query to Report Query Dialog
201: */
202: public void getMdx(RexWizardEvent evt) {
203:
204: getQueryFromRex = evt.getQuery();
205: gotMdxResult = true;
206:
207: }
208:
209: /* end of modifications */
210:
211: public FieldsProviderEditor getEditorComponent(
212: ReportQueryDialog reportQueryDialog) {
213:
214: if (olapBrowser == null) {
215: olapBrowser = new OlapBrowser();
216: olapBrowser.setReportQueryDialog(reportQueryDialog);
217: if (reportQueryDialog != null) {
218: olapBrowser.setJTableFields(reportQueryDialog
219: .getFieldsTable());
220: }
221: }
222: return olapBrowser;
223: }
224:
225: }
|