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.JDBCConnection;
012: import it.businesslogic.ireport.connection.MondrianConnection;
013: import it.businesslogic.ireport.gui.MainFrame;
014: import it.businesslogic.ireport.util.I18n;
015: import java.util.Vector;
016:
017: /**
018: *
019: * @author gtoffoli
020: */
021: public class MondrianConnectionEditor extends javax.swing.JPanel
022: implements IReportConnectionEditor {
023:
024: private IReportConnection iReportConnection = null;
025: private boolean init = false;
026:
027: /** Creates new form EJBQLConnectionEditor */
028: public MondrianConnectionEditor() {
029: initComponents();
030:
031: Vector conns = MainFrame.getMainInstance().getConnections();
032: for (int i = 0; i < conns.size(); ++i) {
033: IReportConnection con = (IReportConnection) conns
034: .elementAt(i);
035: if (con instanceof JDBCConnection) {
036: jComboBoxMondrianJdbc.addItem(con.getName());
037: }
038: }
039:
040: if (jComboBoxMondrianJdbc.getItemCount() > 0) {
041: jComboBoxMondrianJdbc.setSelectedIndex(0);
042: }
043:
044: applyI18n();
045: }
046:
047: /** This method is called from within the constructor to
048: * initialize the form.
049: * WARNING: Do NOT modify this code. The content of this method is
050: * always regenerated by the Form Editor.
051: */
052: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
053: private void initComponents() {
054: java.awt.GridBagConstraints gridBagConstraints;
055:
056: jPanelMondrian = new javax.swing.JPanel();
057: jLabel20 = new javax.swing.JLabel();
058: jComboBoxMondrianJdbc = new javax.swing.JComboBox();
059: jLabel19 = new javax.swing.JLabel();
060: jTextFieldCatalogURI = new javax.swing.JTextField();
061: jButtonBrowseCatalog = new javax.swing.JButton();
062: jPanel14 = new javax.swing.JPanel();
063:
064: setLayout(new java.awt.BorderLayout());
065:
066: jPanelMondrian.setLayout(new java.awt.GridBagLayout());
067:
068: jLabel20.setText("Jdbc Connection");
069: gridBagConstraints = new java.awt.GridBagConstraints();
070: gridBagConstraints.gridx = 0;
071: gridBagConstraints.gridwidth = 2;
072: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
073: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
074: gridBagConstraints.weightx = 1.0;
075: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
076: jPanelMondrian.add(jLabel20, gridBagConstraints);
077:
078: gridBagConstraints = new java.awt.GridBagConstraints();
079: gridBagConstraints.gridx = 0;
080: gridBagConstraints.gridwidth = 2;
081: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
082: gridBagConstraints.weightx = 1.0;
083: gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 4);
084: jPanelMondrian.add(jComboBoxMondrianJdbc, gridBagConstraints);
085:
086: jLabel19.setText("Catalog URI (i.e. file:/path/schema.xml) ");
087: gridBagConstraints = new java.awt.GridBagConstraints();
088: gridBagConstraints.gridx = 0;
089: gridBagConstraints.gridwidth = 2;
090: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
091: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
092: gridBagConstraints.weightx = 1.0;
093: gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 4);
094: jPanelMondrian.add(jLabel19, gridBagConstraints);
095:
096: jTextFieldCatalogURI.setMargin(new java.awt.Insets(0, 5, 2, 4));
097: gridBagConstraints = new java.awt.GridBagConstraints();
098: gridBagConstraints.gridx = 0;
099: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100: gridBagConstraints.weightx = 1.0;
101: gridBagConstraints.insets = new java.awt.Insets(0, 4, 3, 4);
102: jPanelMondrian.add(jTextFieldCatalogURI, gridBagConstraints);
103:
104: jButtonBrowseCatalog.setText("Browse...");
105: jButtonBrowseCatalog
106: .addActionListener(new java.awt.event.ActionListener() {
107: public void actionPerformed(
108: java.awt.event.ActionEvent evt) {
109: jButtonBrowseCatalogActionPerformed(evt);
110: }
111: });
112:
113: gridBagConstraints = new java.awt.GridBagConstraints();
114: gridBagConstraints.gridx = 1;
115: jPanelMondrian.add(jButtonBrowseCatalog, gridBagConstraints);
116:
117: gridBagConstraints = new java.awt.GridBagConstraints();
118: gridBagConstraints.gridx = 0;
119: gridBagConstraints.weighty = 1.0;
120: jPanelMondrian.add(jPanel14, gridBagConstraints);
121:
122: add(jPanelMondrian, java.awt.BorderLayout.CENTER);
123:
124: }// </editor-fold>//GEN-END:initComponents
125:
126: // Variables declaration - do not modify//GEN-BEGIN:variables
127: private javax.swing.JButton jButtonBrowseCatalog;
128: private javax.swing.JComboBox jComboBoxMondrianJdbc;
129: private javax.swing.JLabel jLabel19;
130: private javax.swing.JLabel jLabel20;
131: private javax.swing.JPanel jPanel14;
132: private javax.swing.JPanel jPanelMondrian;
133: private javax.swing.JTextField jTextFieldCatalogURI;
134:
135: // End of variables declaration//GEN-END:variables
136:
137: public void setIReportConnection(IReportConnection c) {
138: this .iReportConnection = c;
139:
140: if (iReportConnection instanceof MondrianConnection) {
141: MondrianConnection con = (MondrianConnection) iReportConnection;
142: this .jTextFieldCatalogURI
143: .setText(it.businesslogic.ireport.util.Misc
144: .nvl(con.getProperties().get(
145: MondrianConnection.CATALOG_URI), ""));
146: jComboBoxMondrianJdbc.setSelectedItem(con
147: .getConnectionName());
148: }
149: }
150:
151: public IReportConnection getIReportConnection() {
152:
153: if (this .jComboBoxMondrianJdbc.getSelectedIndex() < 0) {
154: javax.swing.JOptionPane
155: .showMessageDialog(
156: this ,
157: I18n
158: .getString(
159: "messages.connectionDialog.setJDBCConnection",
160: "You have to choose a JDBC connection in order to configure the Mondrian OLAP connection.\nIf JDBC connection are not yet available, please create one before creating this connection."),
161: I18n
162: .getString(
163: "messages.connectionDialog.setJDBCConnectionCaption",
164: "Invalid JDBC connection!"),
165: javax.swing.JOptionPane.WARNING_MESSAGE);
166: return null;
167: }
168:
169: if (this .jTextFieldCatalogURI.getText().trim().length() == 0) {
170: javax.swing.JOptionPane
171: .showMessageDialog(
172: this ,
173: I18n
174: .getString(
175: "messages.connectionDialog.setCatalogUri",
176: "Please set the Catalog URI"),
177: I18n
178: .getString(
179: "messages.connectionDialog.setCatalogUriCaption",
180: "Invalid URI!"),
181: javax.swing.JOptionPane.WARNING_MESSAGE);
182: return null;
183: }
184:
185: IReportConnection irConn = new MondrianConnection();
186: irConn.getProperties().put(MondrianConnection.CATALOG_URI,
187: jTextFieldCatalogURI.getText().trim());
188: irConn.getProperties().put(MondrianConnection.CONNECTION_NAME,
189: jComboBoxMondrianJdbc.getSelectedItem() + "");
190:
191: iReportConnection = irConn;
192: return iReportConnection;
193: }
194:
195: public void applyI18n() {
196: jButtonBrowseCatalog.setText(I18n.getString(
197: "connectionDialog.buttonBrowseCatalog", "Browse..."));
198: jLabel19.setText(I18n.getString("connectionDialog.label19",
199: "Catalog URI (i.e. file:/path/schema.xml)"));
200: jLabel20.setText(I18n.getString("connectionDialog.label20",
201: "Jdbc Connection"));
202:
203: }
204:
205: private void jButtonBrowseCatalogActionPerformed(
206: java.awt.event.ActionEvent evt) {
207:
208: String fileName = "";
209: javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(
210: MainFrame.getMainInstance().getCurrentDirectory());
211:
212: jfc.setDialogTitle("Select file....");
213:
214: jfc
215: .addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
216: public boolean accept(java.io.File file) {
217: String filename = file.getName();
218: return (filename.toLowerCase().endsWith(".xml") || file
219: .isDirectory());
220: }
221:
222: public String getDescription() {
223: return "XML *.xml";
224: }
225: });
226:
227: jfc.setMultiSelectionEnabled(false);
228: jfc.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
229: if (jfc.showOpenDialog(this ) == javax.swing.JOptionPane.OK_OPTION) {
230: java.io.File file = jfc.getSelectedFile();
231: try {
232: jTextFieldCatalogURI.setText(file.toURI() + "");
233: } catch (Exception ex) {
234: }
235: }
236:
237: }
238:
239: }
|