Skip to content

Commit

Permalink
MONDRIAN: Workbench updates
Browse files Browse the repository at this point in the history
Editing for the following elements
    Formula element in Named Set 
    Formula element in Calculated Member
    SQL element on Views

CDATA elements are viewed and edited in a more visible fashion

Special characters in CDATA content are no longer converted to their encoded values

Better editing for Relations : Tables, Joins, Views
    Relations don’t default to Table
    Can’t add a Level or a Measure before defining a Relation

JDBC column metadata is loaded in a lazy fashion to deal with databases with large numbers of tables and columns, or databases such as PostgreSQL that have slow metadata operations

Column types are visible when selecting columns in the Schema Explorer and JDBC Explorer

'Preferences' renamed 'Connection'

Test Connection: validates database connection and entered schemas

[git-p4: depot-paths = "//open/mondrian/": change = 12567]
  • Loading branch information
Sherman Wood committed Apr 7, 2009
1 parent 6f4e343 commit 138d6c0
Show file tree
Hide file tree
Showing 20 changed files with 1,861 additions and 598 deletions.
1 change: 0 additions & 1 deletion misc/workbench-manifest.mf
@@ -1,6 +1,5 @@
Manifest-Version: 1.0
Main-Class: mondrian.gui.Workbench
Class-Path: . jlfgr-1_0.jar eigenbase-xom.jar eigenbase-resgen.jar eigenbase-properties.jar log4j-1.2.9.jar javacup.jar jmi.jar mm.mysql-2.0.14-bin.jar mof.jar junit.jar mondrian.jar

Name: Mondrian Workbench

223 changes: 208 additions & 15 deletions src/main/mondrian/gui/JDBCExplorer.java
Expand Up @@ -9,45 +9,238 @@
*/
package mondrian.gui;

import java.sql.Connection;

import java.util.Enumeration;
import java.util.Vector;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.MutableTreeNode;
import org.apache.log4j.Logger;

/**
*
* @author sean
* @version $Id$
*/
public class JDBCExplorer extends javax.swing.JPanel {
public class JDBCExplorer extends javax.swing.JPanel
implements TreeWillExpandListener {

private static final Logger LOGGER = Logger.getLogger(JDBCExplorer.class);

Connection connection;
JDBCMetaData jdbcMetaData;
JDBCTreeModel model;

/** Creates new form JDBCExplorer */
Workbench workbench;

DefaultMutableTreeNode root;

DefaultTreeModel treeModel;

/** Creates new form JDBCExplorer
public JDBCExplorer() {
initComponents();
}
*/

public JDBCExplorer(Connection c) {
this();
setConnection(c);
public JDBCExplorer(JDBCMetaData jdbcMetaData, Workbench wb) {
workbench = wb;
initComponents();
setMetaData(jdbcMetaData);
}

public void setConnection(Connection c) {
public void setMetaData(JDBCMetaData jdbcMetaData) {
try {
this.connection = c;
this.jdbcMetaData = jdbcMetaData;

Node rootNode = new Node(null, NodeType.ROOT, null);
root = new DefaultMutableTreeNode(rootNode);

model = new JDBCTreeModel(c);
for (String schemaName : jdbcMetaData.getAllSchemas()) {
Node cat = new Node(schemaName, NodeType.CATALOG, null);

tree.setModel(model);
//tree.addTreeSelectionListener(this);
DefaultMutableTreeNode catTreeNode = new DefaultMutableTreeNode(cat);
cat.treeNode = catTreeNode;
root.add(catTreeNode);

Vector<String> tables = jdbcMetaData.getAllTables(schemaName);
for (String tableName : tables) {
Node table = new Node(tableName, NodeType.TABLE, null);
DefaultMutableTreeNode tableTreeNode = new DefaultMutableTreeNode(table);
table.treeNode = tableTreeNode;
catTreeNode.add(tableTreeNode);
}

cat.gotChildren = true;
}
rootNode.gotChildren = true;

treeModel = new DefaultTreeModel(root, true);
tree.setModel(treeModel);
tree.addTreeWillExpandListener(this);

updater = new JTreeUpdater(tree);
} catch (Exception ex) {
LOGGER.error(ex);
}
}

public void resetMetaData(JDBCMetaData jdbcMetaData) {
setMetaData(jdbcMetaData);
}

public JTreeUpdater getTreeUpdater() {
return updater;
}

public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
// The children are lazy loaded
LOGGER.debug("path = " + event.getPath()
+ ", last object is a "
+ event.getPath().getLastPathComponent().getClass().getName());

DefaultMutableTreeNode theTreeNode =
(DefaultMutableTreeNode) event.getPath().getLastPathComponent();
Node theNode = (Node) theTreeNode.getUserObject();
theNode.setChildren();

logNode(theTreeNode, "will Expand");
}

private void logNode(DefaultMutableTreeNode theTreeNode, String message) {
if (!LOGGER.isDebugEnabled()) {
return;
}

DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) theTreeNode.getParent();

Node theNode = (Node) theTreeNode.getUserObject();
Node theParentNode = parentNode == null ? null : (Node) parentNode.getUserObject();

Enumeration children = theTreeNode.children();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(message + ": " + theNode + ", " + theNode.type
+ ", parent " + theParentNode +
(theParentNode == null ? "" : ", " + theParentNode.type));
while (children.hasMoreElements()) {
Object o = children.nextElement();
Node child = (Node) ((DefaultMutableTreeNode) o).getUserObject();
LOGGER.debug("\t" + child.toString() + ", " + child.type);
}
}
}

public void treeWillCollapse(TreeExpansionEvent arg0)
throws ExpandVetoException {}

enum NodeType {
CATALOG,
TABLE,
COLUMN,
ROOT
}

class Node {
String name;
NodeType type;
boolean gotChildren = false;
DefaultMutableTreeNode treeNode;
JDBCMetaData.DbColumn columnInfo;

public Node(String n,
NodeType t,
DefaultMutableTreeNode tn) {
name = n;
type = t;
treeNode = tn;
}

public Node(String n,
NodeType t,
DefaultMutableTreeNode tn,
JDBCMetaData.DbColumn ci) {
name = n;
type = t;
treeNode = tn;
columnInfo = ci;
}

public String toString() {
if (type == NodeType.ROOT) {
return workbench.getResourceConverter().getFormattedString(
"jdbcExplorer.root.name", "All Schemas", null);
}

StringBuffer sb = new StringBuffer();

if (name == null || name.trim().length() == 0) {
switch (type) {
case CATALOG:
sb.append(workbench
.getResourceConverter()
.getFormattedString(
"jdbcExplorer.default.name.catalog",
"Default Schema",
null));
break;
case TABLE:
sb.append(workbench
.getResourceConverter()
.getFormattedString(
"jdbcExplorer.default.name.table",
"Table",
null));
break;
case COLUMN:
sb.append(workbench
.getResourceConverter()
.getFormattedString(
"jdbcExplorer.default.name.column",
"Column",
null));
break;
}
} else {
sb.append(name);
}

if (type != NodeType.COLUMN) {
return sb.toString();
}

// now for columns

sb.append(" - ")
.append(columnInfo.displayType());

return sb.toString();
}

public Enumeration setChildren() {
if (!gotChildren) {
if (type == NodeType.TABLE) {
DefaultMutableTreeNode theParentTreeNode = (DefaultMutableTreeNode) treeNode.getParent();

Node theParentNode = (Node) theParentTreeNode.getUserObject();

// This is a table, parent is a schema

Vector<String> columnNames = jdbcMetaData.getAllColumns(theParentNode.name, name);
for (String columnName : columnNames) {
JDBCMetaData.DbColumn columnInfo = jdbcMetaData.getColumnDefinition(theParentNode.name, name, columnName);
Node column = new Node(columnName, NodeType.COLUMN, treeNode, columnInfo);
MutableTreeNode columnTreeNode = new DefaultMutableTreeNode(column, false);
treeNode.add(columnTreeNode);
}
}
}
gotChildren = true;
return treeNode.children();
}
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
Expand Down Expand Up @@ -79,6 +272,6 @@ private void initComponents() {//GEN-BEGIN:initComponents
private javax.swing.JSplitPane jSplitPane1;
// End of variables declaration//GEN-END:variables

private JTreeUpdater updater;
}

// End JDBCExplorer.java
// End JDBCExplorer.java

0 comments on commit 138d6c0

Please sign in to comment.