Skip to content

Commit

Permalink
MONDRIAN: Use maintain workbench properties in user's home directory/…
Browse files Browse the repository at this point in the history
….schemaWorkbench. Expend Preferences dialog. Errors in QueryPanel don't show whole stack trace.

[git-p4: depot-paths = "//open/mondrian/": change = 9240]
  • Loading branch information
Sherman Wood committed May 11, 2007
1 parent cf817e9 commit 35acc8e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 36 deletions.
34 changes: 19 additions & 15 deletions demo/workbench.bat
@@ -1,26 +1,31 @@
@echo off
rem @echo off

rem Example Schema Workbench launch script
rem Schema Workbench launch script


rem base Mondrian JARs need to be included

set CP=../lib/commons-dbcp.jar;../lib/commons-collections.jar;../lib/commons-pool.jar
set CP=%CP%;../lib/eigenbase-properties.jar;../lib/eigenbase-resgen.jar;../lib/eigenbase-xom.jar
set CP=%CP%;../lib/javacup.jar;../lib/log4j-1.2.9.jar;../lib/mondrian.jar
set CP=%CP%;../lib/jlfgr-1_0.jar;../lib/jmi.jar;lib/mof.jar;../lib/commons-math-1.0.jar
set CP=%CP%;../lib/commons-vfs.jar;../lib/commons-logging.jar
set CP=lib/commons-dbcp.jar;lib/commons-collections.jar;lib/commons-pool.jar
set CP=%CP%;lib/eigenbase-properties.jar;lib/eigenbase-resgen.jar;lib/eigenbase-xom.jar
set CP=%CP%;lib/javacup.jar;lib/log4j-1.2.12.jar;lib/mondrian.jar
set CP=%CP%;lib/jlfgr-1_0.jar;lib/jmi.jar;lib/mof.jar;lib/commons-math-1.0.jar
set CP=%CP%;lib/commons-vfs.jar;lib/commons-logging.jar

rem Workbench GUI code and resources

set CP=%CP%;../lib/workbench.jar
set CP=%CP%;lib/workbench.jar

rem put a log4j.properties or log4j.xml into the same directory as this batch file
rem to have it automatically included to configure Log4J
rem Have a .schemaWorkbench directory for local

rem you should also put mondrian.properties on the calsspath for it to be picked up
for /F "delims=/" %%i in ('echo %USERPROFILE%') do set ROOT=%%~si

set CP=%CP%;.
if not exist %ROOT%\.schemaWorkbench mkdir %ROOT%\.schemaWorkbench
if not exist %ROOT%\.schemaWorkbench\log4j.xml copy log4j.xml %ROOT%\.schemaWorkbench
if not exist %ROOT%\.schemaWorkbench\mondrian.properties copy ..\mondrian.properties %ROOT%\.schemaWorkbench

rem put mondrian.properties on the classpath for it to be picked up

set CP=%ROOT%/.schemaWorkbench;%CP%

rem or
rem set the log4j.properties system property
Expand All @@ -29,7 +34,6 @@ rem in the java command below to adjust workbench logging

rem add all needed JDBC drivers to the classpath

set CP=%CP%;../testlib/mysql-connector-java-3.1.11-bin.jar
set CP=%CP%;../testlib/postgresql-driver-jdbc3-74-214.jar
for %%i in ("drivers\*.jar") do call "cpappend.bat" %%i

java -Xms100m -Xmx500m -cp "%CP%" mondrian.gui.Workbench
java -Xms100m -Xmx500m -cp "%CP%" -Dlog4j.configuration=file:///%ROOT%\.schemaWorkbench\log4j.xml mondrian.gui.Workbench
32 changes: 18 additions & 14 deletions src/main/mondrian/gui/PreferencesDialog.java
Expand Up @@ -11,6 +11,8 @@
*/
package mondrian.gui;

import java.awt.Dimension;

/**
*
* @author sean
Expand Down Expand Up @@ -75,7 +77,10 @@ private void initComponents() {//GEN-BEGIN:initComponents
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
urlTextField = new javax.swing.JTextField();

// Set the url text field to 50 to drive the width of the dialog
urlTextField = new javax.swing.JTextField(50);

usernameTextField = new javax.swing.JTextField();
passwordTextField = new javax.swing.JTextField();
driverClassTextField = new javax.swing.JTextField();
Expand Down Expand Up @@ -127,8 +132,7 @@ public void windowClosing(java.awt.event.WindowEvent evt) {
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
jPanel1.add(jLabel4, gridBagConstraints);

urlTextField.setText("jdbc:");

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
Expand Down Expand Up @@ -178,10 +182,10 @@ public void windowClosing(java.awt.event.WindowEvent evt) {
gridBagConstraints.weighty = 1.0;
getContentPane().add(jTabbedPane1, gridBagConstraints);

acceptButton.setText("Accept");
acceptButton.addActionListener(new java.awt.event.ActionListener() {
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acceptButtonActionPerformed(evt);
cancelButtonActionPerformed(evt);
}
});

Expand All @@ -190,22 +194,22 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
getContentPane().add(acceptButton, gridBagConstraints);
getContentPane().add(cancelButton, gridBagConstraints);

cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
acceptButton.setText("Accept");
acceptButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
acceptButtonActionPerformed(evt);
}
});

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
getContentPane().add(cancelButton, gridBagConstraints);
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 80);
getContentPane().add(acceptButton, gridBagConstraints);

pack();
}//GEN-END:initComponents
Expand Down
11 changes: 10 additions & 1 deletion src/main/mondrian/gui/QueryPanel.java
Expand Up @@ -218,7 +218,16 @@ private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN

PrintStream p = new PrintStream(os);

ex.printStackTrace(p);
Throwable e = ex;
while (e != null) {
p.println(e.getLocalizedMessage());
LOGGER.error("", e);
Throwable prev = e;
e = e.getCause();
if (e == prev)
break;
p.println();
}

resultTextPane.setText(os.toString());
}
Expand Down
46 changes: 40 additions & 6 deletions src/main/mondrian/gui/Workbench.java
Expand Up @@ -55,6 +55,9 @@
* @author sean
*/
public class Workbench extends javax.swing.JFrame {

public static String WORKBENCH_USER_HOME_DIR;
public static String WORKBENCH_CONFIG_FILE;

private static final String LAST_USED1 = "lastUsed1";
private static final String LAST_USED1_URL = "lastUsedUrl1";
Expand Down Expand Up @@ -92,6 +95,10 @@ public class Workbench extends javax.swing.JFrame {
public Workbench() {
myClassLoader = this.getClass().getClassLoader();

// Setting User home directory
WORKBENCH_USER_HOME_DIR = System.getProperty("user.home") + File.separator + ".schemaWorkbench";
WORKBENCH_CONFIG_FILE = WORKBENCH_USER_HOME_DIR + File.separator + "workbench.properties";

loadWorkbenchProperties();
initDataSource();
initComponents();
Expand All @@ -102,7 +109,6 @@ public Workbench() {
ImageIcon icon = new javax.swing.ImageIcon(myClassLoader.getResource(resources.getString("cube")));

this.setIconImage(icon.getImage());
//openSchemaFrame(new File("C:/Documents and Settings/sarora/My Documents/Inventory.xml"), false); //===
}

/**
Expand All @@ -113,12 +119,16 @@ private void loadWorkbenchProperties() {
try {
String resourceName = "mondrian.gui.resources.workbenchInfo";
resBundle = ResourceBundle.getBundle(resourceName);
workbenchProperties.load(new FileInputStream(new File("workbench.properties")));

File f = new File(WORKBENCH_CONFIG_FILE);
if (f.exists()) {
workbenchProperties.load(new FileInputStream(f));
} else {
LOGGER.debug(WORKBENCH_CONFIG_FILE + " does not exist");
}
} catch (Exception e) {
//e.printStackTrace();

// TODO deal with exception
LOGGER.error(e);
LOGGER.error("loadWorkbenchProperties", e);

}
}
Expand All @@ -128,12 +138,36 @@ private void loadWorkbenchProperties() {
*/
private void storeWorkbenchProperties() {
//save properties to file
File dir = new File(WORKBENCH_USER_HOME_DIR);
try {
if (dir.exists()) {
if (!dir.isDirectory() ) {
javax.swing.JOptionPane.showMessageDialog( this,
WORKBENCH_USER_HOME_DIR + " is not a directory!\nPlease rename this file and retry to save config!","",JOptionPane.ERROR_MESSAGE);
return;
}
}
else {
dir.mkdirs();
}
} catch (Exception ex) {
LOGGER.error(ex);
javax.swing.JOptionPane.showMessageDialog( this,
"An error is occurred creating workbench config directory:\n" + WORKBENCH_USER_HOME_DIR +
"\n" + ex.getLocalizedMessage(),"",JOptionPane.ERROR_MESSAGE);
return;
}

OutputStream out = null;
try {
out = (OutputStream) new FileOutputStream(new File("workbench.properties"));
out = (OutputStream) new FileOutputStream(new File(WORKBENCH_CONFIG_FILE));
workbenchProperties.store(out, "Workbench configuration");
} catch (Exception e) {
LOGGER.error(e);
//TODO deal with exception
javax.swing.JOptionPane.showMessageDialog( this,
"An error is occurred creating workbench config file:\n" + WORKBENCH_CONFIG_FILE +
"\n" + e.getLocalizedMessage(),"",JOptionPane.ERROR_MESSAGE);
} finally {
try {
out.close();
Expand Down

0 comments on commit 35acc8e

Please sign in to comment.