From 67cd535d64e13ffea234235b511ae0963f7ab72f Mon Sep 17 00:00:00 2001 From: Ezequiel Cuellar Date: Wed, 8 Oct 2008 12:18:34 -0800 Subject: [PATCH] MONDRIAN: Fixed Workbench issue Sourceforge [ 2153653 ] Database preferences not enforced when modified. [git-p4: depot-paths = "//open/mondrian/": change = 11698] --- src/main/mondrian/gui/PreferencesDialog.java | 15 +--- src/main/mondrian/gui/SchemaExplorer.java | 19 ++++ .../gui/SchemaPropertyCellEditor.java | 6 ++ .../mondrian/gui/SchemaTreeCellRenderer.java | 6 ++ src/main/mondrian/gui/Workbench.java | 89 ++++++++++++------- 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/src/main/mondrian/gui/PreferencesDialog.java b/src/main/mondrian/gui/PreferencesDialog.java index 8454b6487d..673449457c 100644 --- a/src/main/mondrian/gui/PreferencesDialog.java +++ b/src/main/mondrian/gui/PreferencesDialog.java @@ -11,7 +11,6 @@ */ package mondrian.gui; -import java.awt.Dimension; /** * @@ -25,6 +24,8 @@ public class PreferencesDialog extends javax.swing.JDialog { public PreferencesDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); + pack(); + setLocationRelativeTo(parent); } public boolean accepted() { @@ -223,12 +224,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed accepted = true; - hide(); + setVisible(false); } //GEN-LAST:event_acceptButtonActionPerformed private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed accepted = false; - hide(); + setVisible(false); } //GEN-LAST:event_cancelButtonActionPerformed /** Closes the dialog */ @@ -237,14 +238,6 @@ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_clos dispose(); } //GEN-LAST:event_closeDialog - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - new PreferencesDialog(new javax.swing.JFrame(), true).show(); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField driverClassTextField; private javax.swing.JPanel jPanel1; diff --git a/src/main/mondrian/gui/SchemaExplorer.java b/src/main/mondrian/gui/SchemaExplorer.java index 6a0c165ef5..48208ce596 100644 --- a/src/main/mondrian/gui/SchemaExplorer.java +++ b/src/main/mondrian/gui/SchemaExplorer.java @@ -3404,6 +3404,25 @@ public static String getTableNameForAlias(MondrianGuiDef.RelationOrJoin aRelOrJo } return theTableName; } + + public void resetMetaData(JDBCMetaData aMetaData) { + //EC: Updates the JDBCMetaData in the SchemaExplorer. + jdbcMetaData = aMetaData; + + //EC: Updates the database label. + String[] theArgs = { jdbcMetaData.getDbCatalogName(), jdbcMetaData.getDatabaseProductName()}; + String theLabel = getResourceConverter().getFormattedString("schemaExplorer.database.text","Database - {0} ({1})", theArgs); + databaseLabel.setText(theLabel); + + //EC: Updates the JDBCMetaData in the SchemaTreeCellRenderer. + renderer.setMetaData(aMetaData); + + //EC: Updates the JDBCMetaData in the SchemaPropertyCellEditor. + TableCellEditor theTableCellEditor = propertyTable.getDefaultEditor(Object.class); + if (theTableCellEditor instanceof SchemaPropertyCellEditor) { + ((SchemaPropertyCellEditor) theTableCellEditor).setMetaData(aMetaData); + } + } } // End SchemaExplorer.java diff --git a/src/main/mondrian/gui/SchemaPropertyCellEditor.java b/src/main/mondrian/gui/SchemaPropertyCellEditor.java index b8364e5756..431a8654f6 100644 --- a/src/main/mondrian/gui/SchemaPropertyCellEditor.java +++ b/src/main/mondrian/gui/SchemaPropertyCellEditor.java @@ -1018,6 +1018,12 @@ private I18n getResourceConverter() { return workbench.getResourceConverter(); } + public void setMetaData(JDBCMetaData aMetaData) { + //EC: Called from the SchemaExplorer.resetMetadata(). A call to the updateUI() should be + //made on the owning SchemaFrame to reflect the use of the JDBCMetaData being set. + this.jdbcMetaData = aMetaData; + } + /* // Not required for time being class MapComboBoxModel extends DefaultComboBoxModel { Map objectsMap; diff --git a/src/main/mondrian/gui/SchemaTreeCellRenderer.java b/src/main/mondrian/gui/SchemaTreeCellRenderer.java index 21c48c0447..dfef5e908f 100644 --- a/src/main/mondrian/gui/SchemaTreeCellRenderer.java +++ b/src/main/mondrian/gui/SchemaTreeCellRenderer.java @@ -275,6 +275,12 @@ public void setText(boolean invalidFlag, String myText) { } setText(myText); } + + public void setMetaData(JDBCMetaData aMetaData) { + //EC: Called from the SchemaExplorer.resetMetadata(). A call to the updateUI() should be + //made on the owning SchemaFrame to reflect the use of the JDBCMetaData being set. + this.jdbcMetaData = aMetaData; + } } // End SchemaTreeCellRenderer.java diff --git a/src/main/mondrian/gui/Workbench.java b/src/main/mondrian/gui/Workbench.java index 89ca1720e4..1ac964c1cd 100644 --- a/src/main/mondrian/gui/Workbench.java +++ b/src/main/mondrian/gui/Workbench.java @@ -959,7 +959,7 @@ private void toolbarPreferencesButtonActionPerformed(java.awt.event.ActionEvent pd.setJDBCUsername(jdbcUsername); pd.setJDBCPassword(jdbcPassword); - pd.show(); + pd.setVisible(true); if (pd.accepted()) { jdbcConnectionUrl = pd.getJDBCConnectionUrl(); @@ -971,6 +971,9 @@ private void toolbarPreferencesButtonActionPerformed(java.awt.event.ActionEvent workbenchProperties.setProperty("jdbcConnectionUrl", jdbcConnectionUrl); workbenchProperties.setProperty("jdbcUsername", jdbcUsername); workbenchProperties.setProperty("jdbcPassword", jdbcPassword); + //EC: Enforces the JDBC preferences entered througout all schemas currently opened + //in the workbench. + resetWorkbench(); } } @@ -1331,27 +1334,7 @@ private void openSchemaFrame(File file, boolean newFile) { getResourceConverter().getString("workbench.open.schema.not.found.writeable", "Alert"), JOptionPane.WARNING_MESSAGE); return; } - // check if schema file is valid by initiating a mondrian connection - try { - // this connection parses the catalog file which if invalid will throw exception - String connectString = "Provider=mondrian;" + - "Jdbc=" + jdbcConnectionUrl + ";" + - "Catalog=" + file.toURL().toString() + ";" + - "JdbcDrivers=" + jdbcDriverClassName + ";"; - - if (jdbcUsername != null && jdbcUsername.length() > 0) { - connectString = connectString + "JdbcUser=" + jdbcUsername + ";"; - } - if (jdbcPassword != null && jdbcPassword.length() > 0) { - connectString = connectString + "JdbcPassword=" + jdbcPassword + ";"; - } - - DriverManager.getConnection(connectString, null); - } catch (Exception ex) { - LOGGER.error("Exception : Schema file " + file.getAbsolutePath() + " is invalid." + ex.getMessage(), ex); - } catch (Error err) { - LOGGER.error("Error : Schema file " + file.getAbsolutePath() + " is invalid." + err.getMessage(), err); - } + checkSchemaFile(file); } final JInternalFrame schemaFrame = new JInternalFrame(); @@ -1386,14 +1369,7 @@ private void openSchemaFrame(File file, boolean newFile) { schemaFrame.show(); schemaFrame.setMaximum(true); - // display jdbc connection status warning, if connection is uncsuccessful - if (jdbcMetaData.getErrMsg() != null) { - JOptionPane.showMessageDialog(this, - getResourceConverter().getFormattedString("workbench.open.schema.jdbc.error", - "Database connection could not be done.\n{0}\nAll validations related to database will be ignored.", - new String[] { jdbcMetaData.getErrMsg() }), - getResourceConverter().getString("workbench.open.schema.jdbc.error.title", "Alert"), JOptionPane.WARNING_MESSAGE); - } + displayWarningOnFailedConnection(); final javax.swing.JMenuItem schemaMenuItem = new javax.swing.JMenuItem(); schemaMenuItem.setText(windowMenuMapIndex++ + " " + file.getName()); @@ -1525,6 +1501,57 @@ private boolean checkFileOpen(File file) { } + private void resetWorkbench() { + //EC: Updates the JDBCMetaData for each SchemaExplorer contained in each Schema Frame currently opened based + //on the JDBC preferences entered. + Iterator theSchemaFrames = schemaWindowMap.keySet().iterator(); + while (theSchemaFrames.hasNext()) { + JInternalFrame theSchemaFrame = (JInternalFrame) theSchemaFrames.next(); + SchemaExplorer theSchemaExplorer = (SchemaExplorer) theSchemaFrame.getContentPane().getComponent(0); + File theFile = theSchemaExplorer.getSchemaFile(); + checkSchemaFile(theFile); + jdbcMetaData = new JDBCMetaData(this, jdbcDriverClassName, jdbcConnectionUrl, jdbcUsername, jdbcPassword); + theSchemaExplorer.resetMetaData(jdbcMetaData); + theSchemaFrame.updateUI(); + } + //EC: If the JDBC preferences entered then display a warning. + displayWarningOnFailedConnection(); + } + + private void displayWarningOnFailedConnection() { + // display jdbc connection status warning, if connection is uncsuccessful + if (jdbcMetaData != null && jdbcMetaData.getErrMsg() != null) { + JOptionPane.showMessageDialog(this, + getResourceConverter().getFormattedString("workbench.open.schema.jdbc.error", + "Database connection could not be done.\n{0}\nAll validations related to database will be ignored.", + new String[] { jdbcMetaData.getErrMsg() }), + getResourceConverter().getString("workbench.open.schema.jdbc.error.title", "Alert"), JOptionPane.WARNING_MESSAGE); + } + } + + private void checkSchemaFile(File file) { + // check if schema file is valid by initiating a mondrian connection + try { + // this connection parses the catalog file which if invalid will throw exception + String connectString = "Provider=mondrian;" + + "Jdbc=" + jdbcConnectionUrl + ";" + + "Catalog=" + file.toURL().toString() + ";" + + "JdbcDrivers=" + jdbcDriverClassName + ";"; + + if (jdbcUsername != null && jdbcUsername.length() > 0) { + connectString = connectString + "JdbcUser=" + jdbcUsername + ";"; + } + if (jdbcPassword != null && jdbcPassword.length() > 0) { + connectString = connectString + "JdbcPassword=" + jdbcPassword + ";"; + } + DriverManager.getConnection(connectString, null); + } catch (Exception ex) { + LOGGER.error("Exception : Schema file " + file.getAbsolutePath() + " is invalid." + ex.getMessage(), ex); + } catch (Error err) { + LOGGER.error("Error : Schema file " + file.getAbsolutePath() + " is invalid." + err.getMessage(), err); + } + } + private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) { storeWorkbenchProperties(); @@ -1574,7 +1601,7 @@ public static void main(String args[]) { w.openSchemaFrame(f.getAbsoluteFile(), false); // parameter to indicate this is a new or existing catalog file } } - w.show(); + w.setVisible(true); } catch (Throwable ex) { LOGGER.error("main", ex); }