Author: kevin1219
Date: Wed Aug 27 15:05:58 2008
New Revision: 2641
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionUsageEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/HierarchyEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/EditDimensionAction.java
Log:
Fixed a NullPointerException with the DimensionUsageEditPanel.
Display errors in the table selection boxes if there are no tables in the
database.
Dimension edit panels for private dimensions now have the foreign key
selection box as well.
Modified: trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/CubeEditPanel.java Wed Aug
27 15:05:58 2008
@@ -77,9 +77,14 @@
builder.append("Table", tableChooser = new JComboBox(new
Vector<SQLTable>(tables)));
builder.append("Caption", captionField = new
JTextField(cube.getCaption()));
- SQLTable t = OLAPUtil.tableForCube(cube);
- if (t != null) {
- tableChooser.setSelectedItem(t);
+ if (tables.isEmpty()) {
+ tableChooser.addItem("Database has no tables");
+ tableChooser.setEnabled(false);
+ } else {
+ SQLTable t = OLAPUtil.tableForCube(cube);
+ if (tables.contains(t)) {
+ tableChooser.setSelectedItem(t);
+ }
}
// default measure is optional so we need to add in a null option
@@ -103,12 +108,14 @@
public boolean applyChanges() {
try {
cube.startCompoundEdit("Modify cube properties");
- SQLTable table = (SQLTable) tableChooser.getSelectedItem();
- if (table != null) {
- Table t = new Table();
- t.setName(table.getName());
- t.setSchema(OLAPUtil.getQualifier(table));
- cube.setFact(t);
+ if (tableChooser.isEnabled()) {
+ SQLTable table = (SQLTable) tableChooser.getSelectedItem();
+ if (table != null) {
+ Table t = new Table();
+ t.setName(table.getName());
+ t.setSchema(OLAPUtil.getQualifier(table));
+ cube.setFact(t);
+ }
}
cube.setName(nameField.getText());
if (!(captionField.getText().equals(""))) {
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/DimensionEditPanel.java
Wed Aug 27 15:05:58 2008
@@ -25,6 +25,11 @@
import javax.swing.JTextField;
import mondrian.olap.DimensionType;
+import ca.sqlpower.architect.ArchitectException;
+import ca.sqlpower.architect.SQLColumn;
+import ca.sqlpower.architect.SQLTable;
+import ca.sqlpower.architect.olap.OLAPUtil;
+import ca.sqlpower.architect.olap.MondrianModel.Cube;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
import ca.sqlpower.validation.Validator;
import ca.sqlpower.validation.swingui.FormValidationHandler;
@@ -42,6 +47,7 @@
private JTextField nameField;
private JTextField captionField;
private JComboBox typeBox;
+ private JComboBox foreignKeyChooser;
/**
* Validation handler for errors in the dialog
@@ -53,8 +59,10 @@
* Creates a new property editor for the given OLAP dimension.
*
* @param dimension The dimension to edit
+ * @throws ArchitectException
+ * if digging up the source table results in a database
error
*/
- public DimensionEditPanel(Dimension dimension) {
+ public DimensionEditPanel(Dimension dimension) throws
ArchitectException {
this.dimension = dimension;
FormLayout layout = new FormLayout(
@@ -65,11 +73,34 @@
builder.append("Name", nameField = new
JTextField(dimension.getName()));
builder.append("Caption", captionField = new
JTextField(dimension.getCaption()));
builder.append("Type", typeBox = new
JComboBox(DimensionType.values()));
+
if (dimension.getType() != null) {
typeBox.setSelectedItem(DimensionType.valueOf(dimension.getType()));
} else {
typeBox.setSelectedItem(DimensionType.StandardDimension);
}
+
+ // private dimensions only.
+ if (dimension.getParent() instanceof Cube) {
+ builder.append("Foreign Key", foreignKeyChooser = new
JComboBox());
+ Cube cube = (Cube) dimension.getParent();
+ SQLTable factTable = OLAPUtil.tableForCube(cube);
+ if (factTable == null) {
+ foreignKeyChooser.addItem("Parent Cube has no fact table");
+ foreignKeyChooser.setEnabled(false);
+ } else if (factTable.getColumns().isEmpty()) {
+ foreignKeyChooser.addItem("Parent Cube Fact table has no
columns");
+ foreignKeyChooser.setEnabled(false);
+ } else {
+ for (SQLColumn col : factTable.getColumns()) {
+ foreignKeyChooser.addItem(col);
+ if (col.getName().equals(dimension.getForeignKey())) {
+ foreignKeyChooser.setSelectedItem(col);
+ }
+ }
+ }
+ }
+
panel = builder.getPanel();
handler = new FormValidationHandler(status);
@@ -90,6 +121,13 @@
} else {
dimension.setType(DimensionType.StandardDimension.toString());
}
+
+ if (foreignKeyChooser != null && foreignKeyChooser.isEnabled()) {
+ SQLColumn selectedCol = (SQLColumn)
foreignKeyChooser.getSelectedItem();
+ String pk = selectedCol.getName();
+ dimension.setForeignKey(pk);
+ }
+
dimension.endCompoundEdit();
return true;
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionUsageEditPanel.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionUsageEditPanel.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/DimensionUsageEditPanel.java
Wed Aug 27 15:05:58 2008
@@ -31,7 +31,6 @@
import ca.sqlpower.architect.olap.MondrianModel.Cube;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
import ca.sqlpower.architect.olap.MondrianModel.DimensionUsage;
-import ca.sqlpower.architect.olap.MondrianModel.Table;
import ca.sqlpower.swingui.DataEntryPanel;
import com.jgoodies.forms.builder.DefaultFormBuilder;
@@ -71,11 +70,19 @@
builder.append("Foreign Key", foreignKeyChooser = new JComboBox());
Cube cube = (Cube) dimensionUsage.getParent();
- SQLTable factTable =
OLAPUtil.getSQLTableFromOLAPTable(OLAPUtil.getSession(cube).getDatabase(),
(Table) (cube.getFact()));
- for (SQLColumn col : factTable.getColumns()) {
- foreignKeyChooser.addItem(col);
- if (col.getName().equals(dimensionUsage.getForeignKey())) {
- foreignKeyChooser.setSelectedItem(col);
+ SQLTable factTable = OLAPUtil.tableForCube(cube);
+ if (factTable == null) {
+ foreignKeyChooser.addItem("Parent Cube has no fact table");
+ foreignKeyChooser.setEnabled(false);
+ } else if (factTable.getColumns().isEmpty()) {
+ foreignKeyChooser.addItem("Parent Cube Fact table has no
columns");
+ foreignKeyChooser.setEnabled(false);
+ } else {
+ for (SQLColumn col : factTable.getColumns()) {
+ foreignKeyChooser.addItem(col);
+ if (col.getName().equals(dimensionUsage.getForeignKey())) {
+ foreignKeyChooser.setSelectedItem(col);
+ }
}
}
panel = builder.getPanel();
@@ -88,9 +95,13 @@
} else {
dimensionUsage.setCaption(null);
}
- SQLColumn selectedCol = (SQLColumn)
foreignKeyChooser.getSelectedItem();
- String pk = selectedCol.getName();
- dimensionUsage.setForeignKey(pk);
+
+ if (foreignKeyChooser.isEnabled()) {
+ SQLColumn selectedCol = (SQLColumn)
foreignKeyChooser.getSelectedItem();
+ String pk = selectedCol.getName();
+ dimensionUsage.setForeignKey(pk);
+ dimension.setForeignKey(pk);
+ }
dimensionUsage.endCompoundEdit();
return true;
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/HierarchyEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/HierarchyEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/HierarchyEditPanel.java
Wed Aug 27 15:05:58 2008
@@ -22,6 +22,7 @@
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
+import java.util.Vector;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
@@ -71,6 +72,8 @@
public HierarchyEditPanel(Hierarchy hierarchy) throws
ArchitectException {
this.hierarchy = hierarchy;
+ List<SQLTable> tables = OLAPUtil.getAvailableTables(hierarchy);
+
FormLayout layout = new FormLayout(
"left:max(40dlu;pref), 3dlu, 80dlu:grow", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
@@ -82,28 +85,21 @@
hasAll.setSelected(hierarchy.getHasAll() != null ?
hierarchy.getHasAll() : true);
builder.append("All Level Name", allLevelName = new
JTextField(hierarchy.getAllLevelName() != null ?
hierarchy.getAllLevelName() : "(All)"));
- builder.append("Table", tableChooser = new JComboBox());
+ builder.append("Table", tableChooser = new JComboBox((new
Vector<SQLTable>(tables))));
builder.append("Primary Key", primaryKey = new JComboBox());
- List<SQLTable> tables = OLAPUtil.getAvailableTables(hierarchy);
if (tables.isEmpty()) {
tableChooser.addItem("Database has no tables");
tableChooser.setEnabled(false);
primaryKey.addItem("Table not selected");
primaryKey.setEnabled(false);
} else {
- for (SQLTable tab : tables) {
- tableChooser.addItem(tab);
- }
-
SQLTable t = OLAPUtil.tableForHierarchy(hierarchy);
- if (t != null && tables.contains(t)) {
+ if (tables.contains(t)) {
tableChooser.setSelectedItem(t);
} else {
t = (SQLTable) tableChooser.getSelectedItem();
}
- tableChooser.setEnabled(true);
-
updateColumns(hierarchy.getPrimaryKey());
}
Modified: trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/LevelEditPanel.java Wed
Aug 27 15:05:58 2008
@@ -76,6 +76,9 @@
if (dimensionTable != null) {
for (SQLColumn col : dimensionTable.getColumns()) {
columnChooser.addItem(col);
+ if (col.getName().equalsIgnoreCase(level.getColumn())) {
+ columnChooser.setSelectedItem(col);
+ }
}
} else {
columnChooser.addItem("Parent dimension has no table");
Modified:
trunk/src/ca/sqlpower/architect/swingui/olap/action/EditDimensionAction.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/olap/action/EditDimensionAction.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/olap/action/EditDimensionAction.java
Wed Aug 27 15:05:58 2008
@@ -25,6 +25,8 @@
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
+import ca.sqlpower.architect.ArchitectException;
+import ca.sqlpower.architect.ArchitectRuntimeException;
import ca.sqlpower.architect.olap.MondrianModel.Dimension;
import ca.sqlpower.architect.swingui.ArchitectSwingSession;
import ca.sqlpower.architect.swingui.PlayPen;
@@ -57,11 +59,15 @@
}
public void actionPerformed(ActionEvent e) {
- DataEntryPanel panel = new DimensionEditPanel(dimension);
- JDialog dialog = DataEntryPanelBuilder.createDataEntryPanelDialog(
- panel, dialogOwner, "Dimension Properties", "OK");
- dialog.setLocationRelativeTo(session.getArchitectFrame());
- dialog.setVisible(true);
+ try {
+ DataEntryPanel panel = new DimensionEditPanel(dimension);
+ JDialog dialog =
DataEntryPanelBuilder.createDataEntryPanelDialog(
+ panel, dialogOwner, "Dimension Properties", "OK");
+ dialog.setLocationRelativeTo(session.getArchitectFrame());
+ dialog.setVisible(true);
+ } catch (ArchitectException ex) {
+ throw new ArchitectRuntimeException(ex);
+ }
}
}