001: /*
002: * EJBQLConnectionEditor.java
003: *
004: * Created on March 27, 2007, 1:18 PM
005: */
006:
007: package it.businesslogic.ireport.connection.gui;
008:
009: import it.businesslogic.ireport.IReportConnection;
010: import it.businesslogic.ireport.IReportConnectionEditor;
011: import it.businesslogic.ireport.connection.JRXMLADataSourceConnection;
012: import it.businesslogic.ireport.data.olap.CustomHTTPAuthenticator;
013: import it.businesslogic.ireport.util.I18n;
014: import java.net.Authenticator;
015: import javax.swing.JOptionPane;
016: import rex.graphics.datasourcetree.elements.DataSourceTreeElement;
017:
018: /**
019: *
020: * @author gtoffoli
021: */
022: public class XMLADataSourceConnectionEditor extends javax.swing.JPanel
023: implements IReportConnectionEditor {
024:
025: private IReportConnection iReportConnection = null;
026: private boolean init = false;
027:
028: /** Creates new form EJBQLConnectionEditor */
029: public XMLADataSourceConnectionEditor() {
030: initComponents();
031: applyI18n();
032: }
033:
034: /** This method is called from within the constructor to
035: * initialize the form.
036: * WARNING: Do NOT modify this code. The content of this method is
037: * always regenerated by the Form Editor.
038: */
039: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
040: private void initComponents() {
041: java.awt.GridBagConstraints gridBagConstraints;
042:
043: jPanelXMLA = new javax.swing.JPanel();
044: jLabelXMLAUrl = new javax.swing.JLabel();
045: jTextFieldXMLAUrl = new javax.swing.JTextField();
046: jButtonGetXMLAMetadata = new javax.swing.JButton();
047: jLabelXMLADatasource = new javax.swing.JLabel();
048: jComboBoxXMLADatasource = new javax.swing.JComboBox();
049: jLabelXMLACatalog = new javax.swing.JLabel();
050: jComboBoxXMLACatalog = new javax.swing.JComboBox();
051: jSeparator8 = new javax.swing.JSeparator();
052: jLabelXMLACube = new javax.swing.JLabel();
053: jComboBoxXMLACube = new javax.swing.JComboBox();
054: jSeparator10 = new javax.swing.JSeparator();
055: jPanel16 = new javax.swing.JPanel();
056: jLabel26 = new javax.swing.JLabel();
057: jLabel27 = new javax.swing.JLabel();
058: jTextFieldUsername1 = new javax.swing.JTextField();
059: jTextFieldPassword1 = new javax.swing.JPasswordField();
060: jCheckBoxSavePassword1 = new javax.swing.JCheckBox();
061: jLabelAttention = new javax.swing.JLabel();
062:
063: setLayout(new java.awt.BorderLayout());
064:
065: jPanelXMLA.setLayout(new java.awt.GridBagLayout());
066:
067: jLabelXMLAUrl.setText("Url of XML/A server");
068: gridBagConstraints = new java.awt.GridBagConstraints();
069: gridBagConstraints.gridx = 0;
070: gridBagConstraints.gridwidth = 2;
071: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
072: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
073: gridBagConstraints.weightx = 1.0;
074: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
075: jPanelXMLA.add(jLabelXMLAUrl, gridBagConstraints);
076:
077: jTextFieldXMLAUrl
078: .setText("http://localhost:8080/mondrian/xmla");
079: gridBagConstraints = new java.awt.GridBagConstraints();
080: gridBagConstraints.gridx = 0;
081: gridBagConstraints.gridwidth = 2;
082: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
083: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
084: gridBagConstraints.weightx = 1.0;
085: gridBagConstraints.insets = new java.awt.Insets(2, 4, 4, 4);
086: jPanelXMLA.add(jTextFieldXMLAUrl, gridBagConstraints);
087:
088: jButtonGetXMLAMetadata.setText("Get metadata");
089: jButtonGetXMLAMetadata
090: .addActionListener(new java.awt.event.ActionListener() {
091: public void actionPerformed(
092: java.awt.event.ActionEvent evt) {
093: jButtonGetXMLAMetadataActionPerformed(evt);
094: }
095: });
096:
097: gridBagConstraints = new java.awt.GridBagConstraints();
098: gridBagConstraints.gridx = 0;
099: gridBagConstraints.gridwidth = 2;
100: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
101: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
102: jPanelXMLA.add(jButtonGetXMLAMetadata, gridBagConstraints);
103:
104: jLabelXMLADatasource.setText("Datasource");
105: gridBagConstraints = new java.awt.GridBagConstraints();
106: gridBagConstraints.gridx = 0;
107: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
108: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
109: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
110: jPanelXMLA.add(jLabelXMLADatasource, gridBagConstraints);
111:
112: jComboBoxXMLADatasource.setMinimumSize(new java.awt.Dimension(
113: 23, 22));
114: gridBagConstraints = new java.awt.GridBagConstraints();
115: gridBagConstraints.gridx = 1;
116: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
117: gridBagConstraints.weightx = 1.0;
118: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
119: jPanelXMLA.add(jComboBoxXMLADatasource, gridBagConstraints);
120:
121: jLabelXMLACatalog.setText("Catalog");
122: gridBagConstraints = new java.awt.GridBagConstraints();
123: gridBagConstraints.gridx = 0;
124: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
126: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
127: jPanelXMLA.add(jLabelXMLACatalog, gridBagConstraints);
128:
129: jComboBoxXMLACatalog.setMinimumSize(new java.awt.Dimension(23,
130: 22));
131: gridBagConstraints = new java.awt.GridBagConstraints();
132: gridBagConstraints.gridx = 1;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
134: gridBagConstraints.weightx = 1.0;
135: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
136: jPanelXMLA.add(jComboBoxXMLACatalog, gridBagConstraints);
137:
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 0;
140: gridBagConstraints.gridwidth = 2;
141: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142: gridBagConstraints.weightx = 1.0;
143: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
144: jPanelXMLA.add(jSeparator8, gridBagConstraints);
145:
146: jLabelXMLACube.setText("Cube");
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
152: jPanelXMLA.add(jLabelXMLACube, gridBagConstraints);
153:
154: jComboBoxXMLACube
155: .setMinimumSize(new java.awt.Dimension(23, 22));
156: gridBagConstraints = new java.awt.GridBagConstraints();
157: gridBagConstraints.gridx = 1;
158: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
160: gridBagConstraints.weightx = 1.0;
161: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
162: jPanelXMLA.add(jComboBoxXMLACube, gridBagConstraints);
163:
164: gridBagConstraints = new java.awt.GridBagConstraints();
165: gridBagConstraints.gridx = 0;
166: gridBagConstraints.gridwidth = 2;
167: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168: gridBagConstraints.weightx = 1.0;
169: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
170: jPanelXMLA.add(jSeparator10, gridBagConstraints);
171:
172: jPanel16.setLayout(new java.awt.GridBagLayout());
173:
174: jLabel26.setText("Username");
175: gridBagConstraints = new java.awt.GridBagConstraints();
176: gridBagConstraints.gridx = 0;
177: gridBagConstraints.gridy = 5;
178: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179: gridBagConstraints.insets = new java.awt.Insets(2, 6, 0, 0);
180: jPanel16.add(jLabel26, gridBagConstraints);
181:
182: jLabel27.setText("Password");
183: gridBagConstraints = new java.awt.GridBagConstraints();
184: gridBagConstraints.gridx = 0;
185: gridBagConstraints.gridy = 6;
186: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187: gridBagConstraints.insets = new java.awt.Insets(2, 6, 0, 0);
188: jPanel16.add(jLabel27, gridBagConstraints);
189:
190: gridBagConstraints = new java.awt.GridBagConstraints();
191: gridBagConstraints.gridx = 1;
192: gridBagConstraints.gridy = 5;
193: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
194: gridBagConstraints.weightx = 1.0;
195: gridBagConstraints.insets = new java.awt.Insets(2, 6, 0, 0);
196: jPanel16.add(jTextFieldUsername1, gridBagConstraints);
197:
198: jTextFieldPassword1.setFont(new java.awt.Font("Tahoma", 0, 11));
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 1;
201: gridBagConstraints.gridy = 6;
202: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203: gridBagConstraints.weightx = 1.0;
204: gridBagConstraints.insets = new java.awt.Insets(2, 6, 0, 0);
205: jPanel16.add(jTextFieldPassword1, gridBagConstraints);
206:
207: jCheckBoxSavePassword1.setText("Save password");
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 2;
210: gridBagConstraints.gridy = 6;
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
212: gridBagConstraints.insets = new java.awt.Insets(2, 6, 0, 6);
213: jPanel16.add(jCheckBoxSavePassword1, gridBagConstraints);
214:
215: jLabelAttention
216: .setIcon(new javax.swing.ImageIcon(
217: getClass()
218: .getResource(
219: "/it/businesslogic/ireport/icons/problems/warning.png")));
220: jLabelAttention
221: .setText("<html>ATTENTION! Passwords are stored in clear text. If you dont specify a password now, iReport will ask you for one only when required and will not save it.");
222: gridBagConstraints = new java.awt.GridBagConstraints();
223: gridBagConstraints.gridx = 0;
224: gridBagConstraints.gridwidth = 3;
225: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
226: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
227: gridBagConstraints.weightx = 1.0;
228: gridBagConstraints.weighty = 1.0;
229: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
230: jPanel16.add(jLabelAttention, gridBagConstraints);
231:
232: gridBagConstraints = new java.awt.GridBagConstraints();
233: gridBagConstraints.gridx = 0;
234: gridBagConstraints.gridwidth = 2;
235: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
236: gridBagConstraints.weightx = 1.0;
237: gridBagConstraints.weighty = 1.0;
238: jPanelXMLA.add(jPanel16, gridBagConstraints);
239:
240: add(jPanelXMLA, java.awt.BorderLayout.NORTH);
241:
242: }// </editor-fold>//GEN-END:initComponents
243:
244: // Variables declaration - do not modify//GEN-BEGIN:variables
245: private javax.swing.JButton jButtonGetXMLAMetadata;
246: private javax.swing.JCheckBox jCheckBoxSavePassword1;
247: private javax.swing.JComboBox jComboBoxXMLACatalog;
248: private javax.swing.JComboBox jComboBoxXMLACube;
249: private javax.swing.JComboBox jComboBoxXMLADatasource;
250: private javax.swing.JLabel jLabel26;
251: private javax.swing.JLabel jLabel27;
252: private javax.swing.JLabel jLabelAttention;
253: private javax.swing.JLabel jLabelXMLACatalog;
254: private javax.swing.JLabel jLabelXMLACube;
255: private javax.swing.JLabel jLabelXMLADatasource;
256: private javax.swing.JLabel jLabelXMLAUrl;
257: private javax.swing.JPanel jPanel16;
258: private javax.swing.JPanel jPanelXMLA;
259: private javax.swing.JSeparator jSeparator10;
260: private javax.swing.JSeparator jSeparator8;
261: private javax.swing.JPasswordField jTextFieldPassword1;
262: private javax.swing.JTextField jTextFieldUsername1;
263: private javax.swing.JTextField jTextFieldXMLAUrl;
264:
265: // End of variables declaration//GEN-END:variables
266:
267: public void setIReportConnection(IReportConnection c) {
268:
269: this .iReportConnection = c;
270: if (iReportConnection instanceof JRXMLADataSourceConnection) {
271: /**
272: * Copyright (C) 2005, 2006 CINCOM SYSTEMS, INC.
273: * All Rights Reserved
274: * www.cincom.com
275: *
276: */
277: JRXMLADataSourceConnection con = (JRXMLADataSourceConnection) iReportConnection;
278: this .jTextFieldXMLAUrl.setText(con.getUrl());
279: this .jComboBoxXMLADatasource.removeAllItems();
280: this .jComboBoxXMLADatasource.addItem(con.getDatasource());
281: this .jComboBoxXMLACatalog.removeAllItems();
282: this .jComboBoxXMLACatalog.addItem(con.getCatalog());
283: this .jComboBoxXMLACube.removeAllItems();
284: this .jComboBoxXMLACube.addItem(con.getCube());
285:
286: this .jTextFieldUsername1.setText(con.getUsername());
287: if (con.isSavePassword())
288: this .jTextFieldPassword1.setText(con.getPassword());
289: else
290: this .jTextFieldPassword1.setText("");
291: this .jCheckBoxSavePassword1.setSelected(con
292: .isSavePassword());
293: }
294: }
295:
296: public IReportConnection getIReportConnection() {
297:
298: /**
299: * Copyright (C) 2005, 2006 CINCOM SYSTEMS, INC.
300: * All Rights Reserved
301: * www.cincom.com
302: *
303: */
304: IReportConnection irConn = new JRXMLADataSourceConnection();
305:
306: if (this .jTextFieldXMLAUrl.getText().trim().length() == 0) {
307: javax.swing.JOptionPane
308: .showMessageDialog(
309: this ,
310: I18n
311: .getString(
312: "messages.connectionDialog.xmla.invalidURL",
313: "Please specify a valid server URL"),
314: I18n
315: .getString(
316: "messages.connectionDialog.xmla.invalidProperty",
317: "Invalid property!"),
318: javax.swing.JOptionPane.WARNING_MESSAGE);
319: return null;
320: }
321:
322: ((JRXMLADataSourceConnection) irConn)
323: .setUrl(this .jTextFieldXMLAUrl.getText().trim());
324:
325: if (this .jComboBoxXMLADatasource.getSelectedIndex() < 0) {
326: javax.swing.JOptionPane
327: .showMessageDialog(
328: this ,
329: I18n
330: .getString(
331: "messages.connectionDialog.xmla.invalidDatasource",
332: "Please specify a valid Datasource"),
333: I18n
334: .getString(
335: "messages.connectionDialog.setJDBCConnectionCaption",
336: "Invalid JDBC connection!"),
337: javax.swing.JOptionPane.WARNING_MESSAGE);
338: return null;
339: }
340:
341: ((JRXMLADataSourceConnection) irConn)
342: .setDatasource(((String) this .jComboBoxXMLADatasource
343: .getSelectedItem()).trim());
344:
345: if (this .jComboBoxXMLACatalog.getSelectedIndex() < 0) {
346: javax.swing.JOptionPane
347: .showMessageDialog(
348: this ,
349: I18n
350: .getString(
351: "messages.connectionDialog.xmla.invalidCatalog",
352: "Please specify a valid Catalog"),
353: I18n
354: .getString(
355: "messages.connectionDialog.setJDBCConnectionCaption",
356: "Invalid JDBC connection!"),
357: javax.swing.JOptionPane.WARNING_MESSAGE);
358: return null;
359: }
360:
361: ((JRXMLADataSourceConnection) irConn)
362: .setCatalog(((String) this .jComboBoxXMLACatalog
363: .getSelectedItem()).trim());
364:
365: if (this .jComboBoxXMLACube.getSelectedIndex() < 0) {
366: javax.swing.JOptionPane
367: .showMessageDialog(
368: this ,
369: I18n
370: .getString(
371: "messages.connectionDialog.xmla.invalidCube",
372: "Please specify a valid Cube"),
373: I18n
374: .getString(
375: "messages.connectionDialog.setJDBCConnectionCaption",
376: "Invalid JDBC connection!"),
377: javax.swing.JOptionPane.WARNING_MESSAGE);
378: return null;
379: }
380:
381: ((JRXMLADataSourceConnection) irConn)
382: .setCube(((String) this .jComboBoxXMLACube
383: .getSelectedItem()).trim());
384:
385: ((JRXMLADataSourceConnection) irConn)
386: .setUsername(this .jTextFieldUsername1.getText().trim());
387: if (jCheckBoxSavePassword1.isSelected())
388: ((JRXMLADataSourceConnection) irConn)
389: .setPassword(this .jTextFieldPassword1.getText());
390: else
391: ((JRXMLADataSourceConnection) irConn).setPassword("");
392: ((JRXMLADataSourceConnection) irConn)
393: .setSavePassword(jCheckBoxSavePassword1.isSelected());
394:
395: iReportConnection = irConn;
396: return iReportConnection;
397: }
398:
399: public void applyI18n() {
400: // Start autogenerated code ----------------------
401: jLabelAttention
402: .setText("<html>"
403: + I18n
404: .getString(
405: "connectionDialog.textArea1",
406: "ATTENTION! Passwords are stored in clear text. If you dont specify a password now, iReport will ask you for one only when required and will not save it."));
407: jLabelXMLAUrl
408: .setText(I18n.getString(
409: "connectionDialog.labelXMLAUrl",
410: "Url of XML/A server"));
411: jButtonGetXMLAMetadata.setText(I18n.getString(
412: "connectionDialog.buttonGetXMLAMetadata",
413: "Get metadata"));
414: jLabelXMLADatasource.setText(I18n.getString(
415: "connectionDialog.labelXMLADatasource", "Datasource"));
416: jLabelXMLACatalog.setText(I18n.getString(
417: "connectionDialog.labelXMLACatalog", "Catalog"));
418: jLabelXMLACube.setText(I18n.getString(
419: "connectionDialog.labelXMLACube", "Cube"));
420: }
421:
422: /**
423: * Copyright (C) 2005, 2006 CINCOM SYSTEMS, INC.
424: * All Rights Reserved
425: * www.cincom.com
426: *
427: */
428: private class jComboBoxCatListener implements
429: java.awt.event.ActionListener {
430: public void actionPerformed(java.awt.event.ActionEvent evt) {
431: jComboBoxCatActionPerformed(evt);
432: }
433: }
434:
435: jComboBoxCatListener catListener = new jComboBoxCatListener();
436:
437: private class jComboBoxdsListener implements
438: java.awt.event.ActionListener {
439: public void actionPerformed(java.awt.event.ActionEvent evt) {
440: jComboBoxDatasourceActionPerformed(evt);
441: }
442: }
443:
444: jComboBoxdsListener dsListener = new jComboBoxdsListener();
445:
446: private void jComboBoxDatasourceActionPerformed(
447: java.awt.event.ActionEvent evt) {
448:
449: jComboBoxXMLACatalog.removeActionListener(catListener);
450: if (this .jComboBoxXMLADatasource.getItemCount() == 0
451: || this .jComboBoxXMLADatasource.getSelectedIndex() == -1) {
452: return;
453: }
454: String urlstr = this .jTextFieldXMLAUrl.getText().trim();
455: rex.metadata.ServerMetadata smd = new rex.metadata.ServerMetadata(
456: urlstr, this );
457: if (smd.isValidUrl() == false) {
458: JOptionPane.showMessageDialog(this , I18n.getString(
459: "messages.connectionDialog.xmla.invalidUrl",
460: "Unable to connect to XMLA server."), "",
461: JOptionPane.INFORMATION_MESSAGE);
462: return;
463: }
464:
465: this .jComboBoxXMLACatalog.removeAllItems();
466: this .jComboBoxXMLACube.removeAllItems();
467:
468: DataSourceTreeElement dste[] = smd.discoverDataSources();
469:
470: if (dste == null || dste.length == 0) {
471: JOptionPane.showMessageDialog(this , I18n.getString(
472: "messages.connectionDialog.xmla.noDatasource",
473: "No Datasources found."), "",
474: JOptionPane.INFORMATION_MESSAGE);
475: return;
476: }
477: //filling catalogs
478: boolean found = false;
479: int intI = 0;
480: while (!found && intI < dste.length) {
481: if (dste[intI].getDataSourceInfo().compareTo(
482: (String) this .jComboBoxXMLADatasource
483: .getSelectedItem()) == 0) {
484: found = true;
485: } else {
486: intI++;
487: }
488: }
489: if (!found) {
490: return;
491: }
492: rex.graphics.datasourcetree.elements.DataSourceTreeElement catalogs[] = dste[intI]
493: .getChildren();
494: if (catalogs == null || catalogs.length == 0) {
495: JOptionPane.showMessageDialog(this , I18n.getString(
496: "messages.connectionDialog.xmla.noCatalogs",
497: "No catalogs found for selected datasource."), "",
498: JOptionPane.INFORMATION_MESSAGE);
499: return;
500: }
501: this .jComboBoxXMLACatalog.removeAllItems();
502:
503: for (intI = 0; intI < catalogs.length; intI++) {
504: this .jComboBoxXMLACatalog
505: .addItem(((rex.graphics.datasourcetree.elements.CatalogElement) catalogs[intI])
506: .toString());
507: }
508:
509: found = false;
510: intI = 0;
511: while (!found && intI < catalogs.length) {
512: if (catalogs[intI].toString().trim().compareTo(
513: (String) this .jComboBoxXMLACatalog
514: .getSelectedItem()) == 0) {
515: found = true;
516: } else {
517: intI++;
518: }
519: }
520: if (!found) {
521: return;
522: }
523: rex.graphics.datasourcetree.elements.DataSourceTreeElement cubes[] = catalogs[intI]
524: .getChildren();
525: if (cubes == null || cubes.length == 0) {
526: return;
527: }
528: this .jComboBoxXMLACube.removeAllItems();
529: for (intI = 0; intI < cubes.length; intI++) {
530: this .jComboBoxXMLACube
531: .addItem(((rex.graphics.datasourcetree.elements.CubeElement) cubes[intI])
532: .toString());
533: }
534: jComboBoxXMLACatalog.addActionListener(catListener);
535:
536: }
537:
538: private void jComboBoxCatActionPerformed(
539: java.awt.event.ActionEvent evt) {
540:
541: jComboBoxXMLADatasource.removeActionListener(dsListener);
542:
543: if (this .jComboBoxXMLACatalog.getItemCount() == 0
544: || this .jComboBoxXMLACatalog.getSelectedIndex() == -1) {
545: return;
546: }
547: String urlstr = this .jTextFieldXMLAUrl.getText().trim();
548: rex.metadata.ServerMetadata smd = new rex.metadata.ServerMetadata(
549: urlstr, this );
550: if (smd.isValidUrl() == false) {
551: JOptionPane.showMessageDialog(this , I18n.getString(
552: "messages.connectionDialog.xmla.invalidUrl",
553: "Unable to connect to XMLA server."), "",
554: JOptionPane.INFORMATION_MESSAGE);
555: return;
556: }
557:
558: this .jComboBoxXMLACube.removeAllItems();
559:
560: rex.graphics.datasourcetree.elements.DataSourceTreeElement dste[] = smd
561: .discoverDataSources();
562: if (dste == null || dste.length == 0) {
563: JOptionPane.showMessageDialog(this , I18n.getString(
564: "messages.connectionDialog.xmla.noDatasource",
565: "No Datasources found."), "",
566: JOptionPane.INFORMATION_MESSAGE);
567: return;
568: }
569: boolean found = false;
570: int intI = 0;
571: while (!found && intI < dste.length) {
572: if (dste[intI].getDataSourceInfo().compareTo(
573: (String) this .jComboBoxXMLADatasource
574: .getSelectedItem()) == 0) {
575: found = true;
576: } else {
577: intI++;
578: }
579: }
580: if (!found) {
581: return;
582: }
583: rex.graphics.datasourcetree.elements.DataSourceTreeElement catalogs[] = dste[intI]
584: .getChildren();
585: if (catalogs == null || catalogs.length == 0) {
586: JOptionPane.showMessageDialog(this , I18n.getString(
587: "messages.connectionDialog.xmla.noCatalogs",
588: "No catalogs found for selected datasource."), "",
589: JOptionPane.INFORMATION_MESSAGE);
590: return;
591: }
592: //add catalogs
593: this .jComboBoxXMLACatalog.removeAllItems();
594: for (intI = 0; intI < catalogs.length; intI++) {
595: this .jComboBoxXMLACatalog
596: .addItem(((rex.graphics.datasourcetree.elements.CatalogElement) catalogs[intI])
597: .toString());
598: }
599: found = false;
600: intI = 0;
601: while (!found && intI < catalogs.length) {
602: if (catalogs[intI].toString().compareTo(
603: (String) this .jComboBoxXMLACatalog
604: .getSelectedItem()) == 0) {
605: found = true;
606: } else {
607: intI++;
608: found = false;
609: }
610: }
611: if (!found) {
612: return;
613: }
614: rex.graphics.datasourcetree.elements.DataSourceTreeElement cubes[] = catalogs[intI]
615: .getChildren();
616: if (cubes == null || cubes.length == 0) {
617: JOptionPane.showMessageDialog(this , I18n.getString(
618: "messages.connectionDialog.xmla.noCubes",
619: "No cubes found for selected datasource."), "",
620: JOptionPane.INFORMATION_MESSAGE);
621: return;
622: }
623: this .jComboBoxXMLACube.removeAllItems();
624: for (intI = 0; intI < cubes.length; intI++) {
625: this .jComboBoxXMLACube
626: .addItem(((rex.graphics.datasourcetree.elements.CubeElement) cubes[intI])
627: .toString());
628: }
629: jComboBoxXMLADatasource.addActionListener(dsListener);
630:
631: }
632:
633: private void jButtonGetXMLAMetadataActionPerformed(
634: java.awt.event.ActionEvent evt) {
635: jComboBoxXMLADatasource.removeActionListener(dsListener);
636: jComboBoxXMLACatalog.removeActionListener(catListener);
637:
638: String urlstr = this .jTextFieldXMLAUrl.getText().trim();
639:
640: Authenticator.setDefault(new CustomHTTPAuthenticator(
641: jTextFieldUsername1.getText(), new String(
642: jTextFieldPassword1.getPassword())));
643:
644: rex.metadata.ServerMetadata smd = new rex.metadata.ServerMetadata(
645: urlstr, this );
646:
647: if (smd.isValidUrl() == false) {
648: JOptionPane.showMessageDialog(this , I18n.getString(
649: "messages.connectionDialog.xmla.invalidUrl",
650: "Unable to connect to XMLA server."), "",
651: JOptionPane.INFORMATION_MESSAGE);
652: return;
653: }
654: this .jComboBoxXMLADatasource.removeAllItems();
655: this .jComboBoxXMLACatalog.removeAllItems();
656: this .jComboBoxXMLACube.removeAllItems();
657: rex.graphics.datasourcetree.elements.DataSourceTreeElement dste[] = smd
658: .discoverDataSources();
659: if (dste == null) {
660: JOptionPane.showMessageDialog(this ,
661: "No Datasources found.", "",
662: JOptionPane.INFORMATION_MESSAGE);
663: return;
664: }
665: for (int i = 0; i < dste.length; i++) {
666: this .jComboBoxXMLADatasource.addItem(dste[i]
667: .getDataSourceInfo());
668: }
669: rex.graphics.datasourcetree.elements.DataSourceTreeElement catalogs[] = dste[0]
670: .getChildren();
671: if (catalogs == null || catalogs.length == 0) {
672: return;
673: }
674: this .jComboBoxXMLACatalog.removeAllItems();
675: for (int i = 0; i < catalogs.length; i++) {
676: this .jComboBoxXMLACatalog
677: .addItem(((rex.graphics.datasourcetree.elements.CatalogElement) catalogs[i])
678: .toString());
679: }
680: //get Cube information for the selected catalog...
681: rex.graphics.datasourcetree.elements.DataSourceTreeElement cubes[] = catalogs[0]
682: .getChildren();
683: if (cubes == null || cubes.length == 0) {
684: return;
685: }
686: this .jComboBoxXMLACube.removeAllItems();
687: for (int i = 0; i < cubes.length; i++) {
688: this .jComboBoxXMLACube
689: .addItem(((rex.graphics.datasourcetree.elements.CubeElement) cubes[i])
690: .toString());
691: }
692: jComboBoxXMLADatasource.addActionListener(dsListener);
693: jComboBoxXMLACatalog.addActionListener(catListener);
694: }
695:
696: }
|