Skip to content

Commit

Permalink
MONDRIAN: Fixed Workbench issue
Browse files Browse the repository at this point in the history
Sourceforge [ 2153653 ] Database preferences not enforced when modified.

[git-p4: depot-paths = "//open/mondrian/": change = 11698]
  • Loading branch information
e-cuellar committed Oct 8, 2008
1 parent 34ff91d commit 67cd535
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 42 deletions.
15 changes: 4 additions & 11 deletions src/main/mondrian/gui/PreferencesDialog.java
Expand Up @@ -11,7 +11,6 @@
*/
package mondrian.gui;

import java.awt.Dimension;

/**
*
Expand All @@ -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() {
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/main/mondrian/gui/SchemaExplorer.java
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/main/mondrian/gui/SchemaPropertyCellEditor.java
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/mondrian/gui/SchemaTreeCellRenderer.java
Expand Up @@ -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
89 changes: 58 additions & 31 deletions src/main/mondrian/gui/Workbench.java
Expand Up @@ -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();
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 67cd535

Please sign in to comment.