Author: truesweetman
Date: Thu Aug 28 11:39:05 2008
New Revision: 2650

Modified:
   trunk/src/ca/sqlpower/architect/olap/MondrianModel.java
   trunk/src/ca/sqlpower/architect/olap/xml-to-java-classes.xsl
   trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
   trunk/src/ca/sqlpower/architect/swingui/olap/OLAPTree.java
   trunk/src/ca/sqlpower/architect/swingui/olap/VirtualCubePane.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/OLAPDeleteSelectedAction.java

Log:
Implemented synchronization for CubeUsages as well as deletion for CubeUsages.

To do this, all MondrianModel getChildren()s were altered to also return objects. Also, now when you set objects (objects such as CubeUsages in VirtualCube) a fireChildAdded event is fired instead of a propertyChangeEvent. If you set an object to null, a fireChildRemoved event is fired.

Modified: trunk/src/ca/sqlpower/architect/olap/MondrianModel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/MondrianModel.java     (original)
+++ trunk/src/ca/sqlpower/architect/olap/MondrianModel.java Thu Aug 28 11:39:05 2008
@@ -892,9 +892,16 @@
     }

     public void setFact(Relation /* */ newval) {
+        int overallPosition = childPositionOffset(Relation.class);
         Relation /* */ oldval = fact;
         fact = newval;
-        pcs.firePropertyChange("fact", oldval, newval);
+        if (fact == null) {
+            fireChildRemoved(Relation.class, overallPosition, oldval);
+        } else {
+            fact.setParent(this);
+            fireChildAdded(Relation.class, overallPosition, fact);
+        }
+
     }

     /**  */
@@ -1175,6 +1182,9 @@
         if (childClass == NamedSet.class) return offset;
         offset += namedSets.size();

+        if (childClass == Relation.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -1343,9 +1353,16 @@
     }

     public void setCubeUsage(CubeUsages /* */ newval) {
+        int overallPosition = childPositionOffset(CubeUsages.class);
         CubeUsages /* */ oldval = cubeUsage;
         cubeUsage = newval;
-        pcs.firePropertyChange("cubeUsage", oldval, newval);
+        if (cubeUsage == null) {
+            fireChildRemoved(CubeUsages.class, overallPosition, oldval);
+        } else {
+            cubeUsage.setParent(this);
+            fireChildAdded(CubeUsages.class, overallPosition, cubeUsage);
+        }
+
     }

     /**  */
@@ -1632,6 +1649,9 @@
         if (childClass == NamedSet.class) return offset;
         offset += namedSets.size();

+        if (childClass == CubeUsages.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -2731,9 +2751,16 @@
     }

     public void setRelation(RelationOrJoin /* */ newval) {
+        int overallPosition = childPositionOffset(RelationOrJoin.class);
         RelationOrJoin /* */ oldval = relation;
         relation = newval;
-        pcs.firePropertyChange("relation", oldval, newval);
+        if (relation == null) {
+ fireChildRemoved(RelationOrJoin.class, overallPosition, oldval);
+        } else {
+            relation.setParent(this);
+ fireChildAdded(RelationOrJoin.class, overallPosition, relation);
+        }
+
     }

     /**  */
@@ -2884,6 +2911,9 @@
         if (childClass == MemberReaderParameter.class) return offset;
         offset += memberReaderParameters.size();

+        if (childClass == RelationOrJoin.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -3299,9 +3329,16 @@
     }

     public void setKeyExp(KeyExpression /* */ newval) {
+        int overallPosition = childPositionOffset(KeyExpression.class);
         KeyExpression /* */ oldval = keyExp;
         keyExp = newval;
-        pcs.firePropertyChange("keyExp", oldval, newval);
+        if (keyExp == null) {
+            fireChildRemoved(KeyExpression.class, overallPosition, oldval);
+        } else {
+            keyExp.setParent(this);
+            fireChildAdded(KeyExpression.class, overallPosition, keyExp);
+        }
+
     }

     /**
@@ -3315,9 +3352,16 @@
     }

     public void setNameExp(NameExpression /* */ newval) {
+        int overallPosition = childPositionOffset(NameExpression.class);
         NameExpression /* */ oldval = nameExp;
         nameExp = newval;
-        pcs.firePropertyChange("nameExp", oldval, newval);
+        if (nameExp == null) {
+ fireChildRemoved(NameExpression.class, overallPosition, oldval);
+        } else {
+            nameExp.setParent(this);
+            fireChildAdded(NameExpression.class, overallPosition, nameExp);
+        }
+
     }

     /**
@@ -3330,9 +3374,16 @@
     }

     public void setOrdinalExp(OrdinalExpression /* */ newval) {
+        int overallPosition = childPositionOffset(OrdinalExpression.class);
         OrdinalExpression /* */ oldval = ordinalExp;
         ordinalExp = newval;
-        pcs.firePropertyChange("ordinalExp", oldval, newval);
+        if (ordinalExp == null) {
+ fireChildRemoved(OrdinalExpression.class, overallPosition, oldval);
+        } else {
+            ordinalExp.setParent(this);
+ fireChildAdded(OrdinalExpression.class, overallPosition, ordinalExp);
+        }
+
     }

     /**
@@ -3346,9 +3397,16 @@
     }

     public void setParentExp(ParentExpression /* */ newval) {
+        int overallPosition = childPositionOffset(ParentExpression.class);
         ParentExpression /* */ oldval = parentExp;
         parentExp = newval;
-        pcs.firePropertyChange("parentExp", oldval, newval);
+        if (parentExp == null) {
+ fireChildRemoved(ParentExpression.class, overallPosition, oldval);
+        } else {
+            parentExp.setParent(this);
+ fireChildAdded(ParentExpression.class, overallPosition, parentExp);
+        }
+
     }

     /**  */
@@ -3359,9 +3417,16 @@
     }

     public void setClosure(Closure /* */ newval) {
+        int overallPosition = childPositionOffset(Closure.class);
         Closure /* */ oldval = closure;
         closure = newval;
-        pcs.firePropertyChange("closure", oldval, newval);
+        if (closure == null) {
+            fireChildRemoved(Closure.class, overallPosition, oldval);
+        } else {
+            closure.setParent(this);
+            fireChildAdded(Closure.class, overallPosition, closure);
+        }
+
     }

     /**  */
@@ -3469,6 +3534,21 @@
         if (childClass == Property.class) return offset;
         offset += properties.size();

+        if (childClass == KeyExpression.class) return offset;
+        offset += 1;
+
+        if (childClass == NameExpression.class) return offset;
+        offset += 1;
+
+        if (childClass == OrdinalExpression.class) return offset;
+        offset += 1;
+
+        if (childClass == ParentExpression.class) return offset;
+        offset += 1;
+
+        if (childClass == Closure.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -3607,19 +3687,52 @@
     }

     public void setTable(Table /* */ newval) {
+        int overallPosition = childPositionOffset(Table.class);
         Table /* */ oldval = table;
         table = newval;
-        pcs.firePropertyChange("table", oldval, newval);
+        if (table == null) {
+            fireChildRemoved(Table.class, overallPosition, oldval);
+        } else {
+            table.setParent(this);
+            fireChildAdded(Table.class, overallPosition, table);
+        }
+
     }

     @Override
     public List<OLAPObject> getChildren() {
-        return Collections.emptyList();
+ /* This might be noticeably more efficient if we use a data structure (ConcatenatedList?) that holds + * each list and implements optimized get() and iterator() methods instead of just making a new + * ArrayList with a copy of the union of all the other lists as we are now. */
+        List<OLAPObject> children = new ArrayList<OLAPObject>();
+
+        if (table != null) {
+               children.add(table);
+        }
+
+        return Collections.unmodifiableList(children);
     }

     @Override
     public boolean allowsChildren() {
-        return false;
+        return true;
+    }
+
+    /**
+ * Returns the position in the list that would be returned by getChildren()
+     * that the first object of type childClass is, or where it would be if
+     * there were any children of that type.
+     *
+ * @throws IllegalArgumentException if the given child class is not valid for
+     * this OLAPObject.
+     */
+ private int childPositionOffset(Class<? extends OLAPObject> childClass) {
+        int offset = 0;
+
+        if (childClass == Table.class) return offset;
+        offset += 1;
+
+        return offset;
     }

     @Override
@@ -4001,9 +4114,16 @@
     }

     public void setMeasureExp(MeasureExpression /* */ newval) {
+        int overallPosition = childPositionOffset(MeasureExpression.class);
         MeasureExpression /* */ oldval = measureExp;
         measureExp = newval;
-        pcs.firePropertyChange("measureExp", oldval, newval);
+        if (measureExp == null) {
+ fireChildRemoved(MeasureExpression.class, overallPosition, oldval);
+        } else {
+            measureExp.setParent(this);
+ fireChildAdded(MeasureExpression.class, overallPosition, measureExp);
+        }
+
     }

     /**  */
@@ -4095,6 +4215,9 @@
         if (childClass == CalculatedMemberProperty.class) return offset;
         offset += memberProperties.size();

+        if (childClass == MeasureExpression.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -4286,9 +4409,16 @@
     }

     public void setFormulaElement(Formula /* */ newval) {
+        int overallPosition = childPositionOffset(Formula.class);
         Formula /* */ oldval = formulaElement;
         formulaElement = newval;
-        pcs.firePropertyChange("formulaElement", oldval, newval);
+        if (formulaElement == null) {
+            fireChildRemoved(Formula.class, overallPosition, oldval);
+        } else {
+            formulaElement.setParent(this);
+            fireChildAdded(Formula.class, overallPosition, formulaElement);
+        }
+
     }

     /**  */
@@ -4380,6 +4510,9 @@
         if (childClass == CalculatedMemberProperty.class) return offset;
         offset += memberProperties.size();

+        if (childClass == Formula.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -4646,19 +4779,52 @@
     }

     public void setFormulaElement(Formula /* */ newval) {
+        int overallPosition = childPositionOffset(Formula.class);
         Formula /* */ oldval = formulaElement;
         formulaElement = newval;
-        pcs.firePropertyChange("formulaElement", oldval, newval);
+        if (formulaElement == null) {
+            fireChildRemoved(Formula.class, overallPosition, oldval);
+        } else {
+            formulaElement.setParent(this);
+            fireChildAdded(Formula.class, overallPosition, formulaElement);
+        }
+
     }

     @Override
     public List<OLAPObject> getChildren() {
-        return Collections.emptyList();
+ /* This might be noticeably more efficient if we use a data structure (ConcatenatedList?) that holds + * each list and implements optimized get() and iterator() methods instead of just making a new + * ArrayList with a copy of the union of all the other lists as we are now. */
+        List<OLAPObject> children = new ArrayList<OLAPObject>();
+
+        if (formulaElement != null) {
+               children.add(formulaElement);
+        }
+
+        return Collections.unmodifiableList(children);
     }

     @Override
     public boolean allowsChildren() {
-        return false;
+        return true;
+    }
+
+    /**
+ * Returns the position in the list that would be returned by getChildren()
+     * that the first object of type childClass is, or where it would be if
+     * there were any children of that type.
+     *
+ * @throws IllegalArgumentException if the given child class is not valid for
+     * this OLAPObject.
+     */
+ private int childPositionOffset(Class<? extends OLAPObject> childClass) {
+        int offset = 0;
+
+        if (childClass == Formula.class) return offset;
+        offset += 1;
+
+        return offset;
     }

     @Override
@@ -5327,9 +5493,16 @@
     }

     public void setLeft(RelationOrJoin /* */ newval) {
+        int overallPosition = childPositionOffset(RelationOrJoin.class);
         RelationOrJoin /* */ oldval = left;
         left = newval;
-        pcs.firePropertyChange("left", oldval, newval);
+        if (left == null) {
+ fireChildRemoved(RelationOrJoin.class, overallPosition, oldval);
+        } else {
+            left.setParent(this);
+            fireChildAdded(RelationOrJoin.class, overallPosition, left);
+        }
+
     }

     /**  */
@@ -5340,19 +5513,59 @@
     }

     public void setRight(RelationOrJoin /* */ newval) {
+        int overallPosition = childPositionOffset(RelationOrJoin.class);
         RelationOrJoin /* */ oldval = right;
         right = newval;
-        pcs.firePropertyChange("right", oldval, newval);
+        if (right == null) {
+ fireChildRemoved(RelationOrJoin.class, overallPosition, oldval);
+        } else {
+            right.setParent(this);
+            fireChildAdded(RelationOrJoin.class, overallPosition, right);
+        }
+
     }

     @Override
     public List<OLAPObject> getChildren() {
-        return Collections.emptyList();
+ /* This might be noticeably more efficient if we use a data structure (ConcatenatedList?) that holds + * each list and implements optimized get() and iterator() methods instead of just making a new + * ArrayList with a copy of the union of all the other lists as we are now. */
+        List<OLAPObject> children = new ArrayList<OLAPObject>();
+
+        if (left != null) {
+               children.add(left);
+        }
+
+        if (right != null) {
+               children.add(right);
+        }
+
+        return Collections.unmodifiableList(children);
     }

     @Override
     public boolean allowsChildren() {
-        return false;
+        return true;
+    }
+
+    /**
+ * Returns the position in the list that would be returned by getChildren()
+     * that the first object of type childClass is, or where it would be if
+     * there were any children of that type.
+     *
+ * @throws IllegalArgumentException if the given child class is not valid for
+     * this OLAPObject.
+     */
+ private int childPositionOffset(Class<? extends OLAPObject> childClass) {
+        int offset = 0;
+
+        if (childClass == RelationOrJoin.class) return offset;
+        offset += 1;
+
+        if (childClass == RelationOrJoin.class) return offset;
+        offset += 1;
+
+        return offset;
     }

     @Override
@@ -5489,9 +5702,16 @@
     }

     public void setFilter(SQL /* */ newval) {
+        int overallPosition = childPositionOffset(SQL.class);
         SQL /* */ oldval = filter;
         filter = newval;
-        pcs.firePropertyChange("filter", oldval, newval);
+        if (filter == null) {
+            fireChildRemoved(SQL.class, overallPosition, oldval);
+        } else {
+            filter.setParent(this);
+            fireChildAdded(SQL.class, overallPosition, filter);
+        }
+
     }

     /**  */
@@ -5642,6 +5862,9 @@
         if (childClass == AggTable.class) return offset;
         offset += aggTables.size();

+        if (childClass == SQL.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -5750,9 +5973,16 @@
     }

     public void setColumnDefs(ColumnDefs /* */ newval) {
+        int overallPosition = childPositionOffset(ColumnDefs.class);
         ColumnDefs /* */ oldval = columnDefs;
         columnDefs = newval;
-        pcs.firePropertyChange("columnDefs", oldval, newval);
+        if (columnDefs == null) {
+            fireChildRemoved(ColumnDefs.class, overallPosition, oldval);
+        } else {
+            columnDefs.setParent(this);
+            fireChildAdded(ColumnDefs.class, overallPosition, columnDefs);
+        }
+
     }

     /**  */
@@ -5763,19 +5993,59 @@
     }

     public void setRows(Rows /* */ newval) {
+        int overallPosition = childPositionOffset(Rows.class);
         Rows /* */ oldval = rows;
         rows = newval;
-        pcs.firePropertyChange("rows", oldval, newval);
+        if (rows == null) {
+            fireChildRemoved(Rows.class, overallPosition, oldval);
+        } else {
+            rows.setParent(this);
+            fireChildAdded(Rows.class, overallPosition, rows);
+        }
+
     }

     @Override
     public List<OLAPObject> getChildren() {
-        return Collections.emptyList();
+ /* This might be noticeably more efficient if we use a data structure (ConcatenatedList?) that holds + * each list and implements optimized get() and iterator() methods instead of just making a new + * ArrayList with a copy of the union of all the other lists as we are now. */
+        List<OLAPObject> children = new ArrayList<OLAPObject>();
+
+        if (columnDefs != null) {
+               children.add(columnDefs);
+        }
+
+        if (rows != null) {
+               children.add(rows);
+        }
+
+        return Collections.unmodifiableList(children);
     }

     @Override
     public boolean allowsChildren() {
-        return false;
+        return true;
+    }
+
+    /**
+ * Returns the position in the list that would be returned by getChildren()
+     * that the first object of type childClass is, or where it would be if
+     * there were any children of that type.
+     *
+ * @throws IllegalArgumentException if the given child class is not valid for
+     * this OLAPObject.
+     */
+ private int childPositionOffset(Class<? extends OLAPObject> childClass) {
+        int offset = 0;
+
+        if (childClass == ColumnDefs.class) return offset;
+        offset += 1;
+
+        if (childClass == Rows.class) return offset;
+        offset += 1;
+
+        return offset;
     }

     @Override
@@ -6456,9 +6726,16 @@
     }

     public void setFactcount(AggFactCount /* */ newval) {
+        int overallPosition = childPositionOffset(AggFactCount.class);
         AggFactCount /* */ oldval = factcount;
         factcount = newval;
-        pcs.firePropertyChange("factcount", oldval, newval);
+        if (factcount == null) {
+            fireChildRemoved(AggFactCount.class, overallPosition, oldval);
+        } else {
+            factcount.setParent(this);
+            fireChildAdded(AggFactCount.class, overallPosition, factcount);
+        }
+
     }

     /**  */
@@ -6746,6 +7023,9 @@
         if (childClass == AggLevel.class) return offset;
         offset += levels.size();

+        if (childClass == AggFactCount.class) return offset;
+        offset += 1;
+
         return offset;
     }

@@ -8360,9 +8640,16 @@
     }

     public void setUnion(Union /* */ newval) {
+        int overallPosition = childPositionOffset(Union.class);
         Union /* */ oldval = union;
         union = newval;
-        pcs.firePropertyChange("union", oldval, newval);
+        if (union == null) {
+            fireChildRemoved(Union.class, overallPosition, oldval);
+        } else {
+            union.setParent(this);
+            fireChildAdded(Union.class, overallPosition, union);
+        }
+
     }

     @Override
@@ -8399,6 +8686,9 @@

         if (childClass == SchemaGrant.class) return offset;
         offset += schemaGrants.size();
+
+        if (childClass == Union.class) return offset;
+        offset += 1;

         return offset;
     }

Modified: trunk/src/ca/sqlpower/architect/olap/xml-to-java-classes.xsl
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/xml-to-java-classes.xsl        
(original)
+++ trunk/src/ca/sqlpower/architect/olap/xml-to-java-classes.xsl Thu Aug 28 11:39:05 2008
@@ -138,7 +138,7 @@
 </xsl:template>

<!-- Private instance variable with getter/setter pair. (i.e. a bound JavaBean property) -->
-<xsl:template match="Attribute|Object">
+<xsl:template match="Attribute">
     /** <xsl:copy-of select="Doc"/> */
private <xsl:call-template name="attribute-type"/> /* */ <xsl:value-of select="@name"/>;

@@ -151,6 +151,31 @@
         <xsl:value-of select="@name"/> = newval;
pcs.firePropertyChange("<xsl:value-of select="@name"/>", oldval, newval);
     }
+</xsl:template>
+
+<!-- Private instance variable with getter/setter pair. (i.e. a bound JavaBean property) --> +<!-- This is different than attribute because objects considered children of the so the -->
+<!-- Parent must be set. -->
+<xsl:template match="Object">
+    /** <xsl:copy-of select="Doc"/> */
+ private <xsl:call-template name="attribute-type"/> /* */ <xsl:value-of select="@name"/>;
+
+ public <xsl:call-template name="attribute-type"/> /* */ get<xsl:call-template name="name-initcap"/>() {
+        return <xsl:value-of select="@name"/>;
+    }
+
+ public void set<xsl:call-template name="name-initcap"/>(<xsl:call-template name="attribute-type"/> /* */ newval) { + int overallPosition = childPositionOffset(<xsl:call-template name="attribute-type"/>.class); + <xsl:call-template name="attribute-type"/> /* */ oldval = <xsl:value-of select="@name"/>;
+        <xsl:value-of select="@name"/> = newval;
+        if (<xsl:value-of select="@name"/> == null) {
+ fireChildRemoved(<xsl:call-template name="attribute-type"/>.class, overallPosition, oldval);
+        } else {
+            <xsl:value-of select="@name"/>.setParent(this);
+ fireChildAdded(<xsl:call-template name="attribute-type"/>.class, overallPosition, <xsl:value-of select="@name"/>);
+        }
+
+    }
 </xsl:template>

<!-- Private instance variable with getter/setter pair. (i.e. a bound JavaBean property) -->
@@ -235,7 +260,7 @@

 <xsl:template name="children-methods">
     <xsl:choose>
-      <xsl:when test="Array">
+      <xsl:when test="Array|Object">
     @Override
     public List&lt;OLAPObject&gt; getChildren() {
/* This might be noticeably more efficient if we use a data structure (ConcatenatedList?) that holds
@@ -271,6 +296,10 @@
         <xsl:for-each select="Array">
if (childClass == <xsl:value-of select="@type"/>.class) return offset;
         offset += <xsl:value-of select="@name"/>.size();
+        </xsl:for-each>
+        <xsl:for-each select="Object">
+ if (childClass == <xsl:value-of select="@type"/>.class) return offset;
+        offset += 1;
         </xsl:for-each>
         return offset;
     }

Modified: trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/PlayPen.java        (original)
+++ trunk/src/ca/sqlpower/architect/swingui/PlayPen.java Thu Aug 28 11:39:05 2008
@@ -106,6 +106,8 @@
 import ca.sqlpower.architect.olap.MondrianModel;
 import ca.sqlpower.architect.olap.OLAPObject;
 import ca.sqlpower.architect.olap.MondrianModel.Cube;
+import ca.sqlpower.architect.olap.MondrianModel.CubeUsage;
+import ca.sqlpower.architect.olap.MondrianModel.CubeUsages;
 import ca.sqlpower.architect.olap.MondrianModel.DimensionUsage;
 import ca.sqlpower.architect.olap.MondrianModel.Hierarchy;
 import ca.sqlpower.architect.olap.MondrianModel.Level;
@@ -2741,6 +2743,8 @@
selectMeasure((Measure) obj, ignoredObjs, extraSelections, tree); } else if (obj instanceof VirtualCubeDimension || obj instanceof VirtualCubeMeasure) { selectItemFromVirtualCube(obj, ignoredObjs, extraSelections, tree);
+            } else if (obj instanceof CubeUsage) {
+ selectCubeUsage((CubeUsage) obj, ignoredObjs, extraSelections, tree); } else if (obj instanceof Hierarchy && obj.getParent() instanceof MondrianModel.Dimension
                     && obj.getParent().getParent() instanceof Schema) {
// Only select hierarchies from the public dimensions because the ones inside
@@ -2839,6 +2843,44 @@
     }

     /**
+     * Uses the given CubeUsage to select the matching CubeUsage and
+ * VirtualCubePane on the PlayPen. Also ensures the OLAPTree also selects
+     * the cubeUsage and the virtualCube.
+     *
+     * @param obj
+     *            The CubeUsage to be selected in the playPen.
+     * @param ignoredObjs
+     *            A list of ingored objects used for debugging.
+     * @param extraSelections
+ * A list of items that are selected, but not directly from the
+     *            user.
+     * @param tree
+     *            The OLAPTree assoicated with this PlayPen.
+     * @return The VirtualCubePane that was selected or null if none was
+     *         selected.
+     */
+ private VirtualCubePane selectCubeUsage(CubeUsage obj, List<OLAPObject> ignoredObjs, List<OLAPObject> extraSelections,
+            OLAPTree tree) {
+        if (obj.getParent() instanceof CubeUsages) {
+
+            if (obj.getParent().getParent() instanceof VirtualCube) {
+ VirtualCubePane vcp = selectVirtualCube((VirtualCube) obj.getParent().getParent(), ignoredObjs);
+                if (vcp != null) {
+ selectParents(obj, vcp.getModel(), tree, extraSelections);
+                    vcp.selectItem(obj);
+                }
+                return vcp;
+            } else {
+ throw new IllegalStateException("Parent type " + obj.getParent().getParent().getClass() + + " is not a valid parent for type " + obj.getParent().getClass() + "!");
+            }
+        } else {
+ throw new IllegalStateException("Parent type " + obj.getParent().getClass() + + " is not a valid parent for type " + obj.getClass() + "!");
+        }
+    }
+
+    /**
      * Uses the given cube to select the matching CubePane on the PlayPen.
      *
      * @param cube The Cube whose pane is to be selected.
@@ -2906,7 +2948,7 @@
             }
             return dp;
         } else {
- throw new IllegalArgumentException("Parent type " + obj.getParent().getClass() + throw new IllegalStateException("Parent type " + obj.getParent().getClass() + " is not a valid parent for type " + obj.getClass() + "!");
         }
     }
@@ -2935,7 +2977,7 @@
             }
             return cp;
         } else {
- throw new IllegalArgumentException("Parent type " + measure.getParent().getClass() + throw new IllegalStateException("Parent type " + measure.getParent().getClass() + " is not a valid parent for type " + measure.getClass() + "!");
         }
     }
@@ -2946,7 +2988,7 @@
      * OLAPTree also selects the object and the virtualCube.
      *
      * @param obj
- * The VirtualCubeMeasure or VirtualCubeDimensionto be select in + * The VirtualCubeMeasure or VirtualCubeDimension to be selected in
      *            the playPen.
      * @param ignoredObjs
      *            A list of ingored objects used for debugging.
@@ -2967,7 +3009,7 @@
             }
             return vcp;
         } else {
- throw new IllegalArgumentException("Parent type " + obj.getParent().getClass() + throw new IllegalStateException("Parent type " + obj.getParent().getClass() + " is not a valid parent for type " + obj.getClass() + "!");
         }
     }
@@ -2999,7 +3041,7 @@
             }
             return dp;
         } else {
- throw new IllegalArgumentException("Parent type " + hierarchy.getParent().getClass() + throw new IllegalStateException("Parent type " + hierarchy.getParent().getClass() + " is not a valid parent for type " + hierarchy.getClass() + "!");
         }
     }
@@ -3031,7 +3073,7 @@
             }
             return dp;
         } else {
- throw new IllegalArgumentException("Parent type " + level.getParent().getClass() + throw new IllegalStateException("Parent type " + level.getParent().getClass() + " is not a valid parent for type " + level.getClass() + "!");
         }
     }

Modified: trunk/src/ca/sqlpower/architect/swingui/olap/OLAPTree.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/OLAPTree.java  (original)
+++ trunk/src/ca/sqlpower/architect/swingui/olap/OLAPTree.java Thu Aug 28 11:39:05 2008
@@ -33,6 +33,7 @@
 import ca.sqlpower.architect.olap.OLAPObject;
 import ca.sqlpower.architect.olap.MondrianModel.Cube;
 import ca.sqlpower.architect.olap.MondrianModel.CubeDimension;
+import ca.sqlpower.architect.olap.MondrianModel.CubeUsage;
 import ca.sqlpower.architect.olap.MondrianModel.Hierarchy;
 import ca.sqlpower.architect.olap.MondrianModel.Level;
 import ca.sqlpower.architect.olap.MondrianModel.Measure;
@@ -141,7 +142,8 @@
             OLAPObject obj = (OLAPObject) tp.getLastPathComponent();
if (!(obj instanceof Cube || obj instanceof VirtualCube || obj instanceof Measure || obj instanceof CubeDimension || obj instanceof VirtualCubeMeasure
-                    || obj instanceof Level || obj instanceof Hierarchy)) {
+                    || obj instanceof Level || obj instanceof Hierarchy
+                    || obj instanceof CubeUsage)) {
                 removeSelectionPath(tp);
             }
         }

Modified: trunk/src/ca/sqlpower/architect/swingui/olap/VirtualCubePane.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/VirtualCubePane.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/olap/VirtualCubePane.java Thu Aug 28 11:39:05 2008
@@ -75,7 +75,11 @@

     @Override
     protected List<OLAPObject> getItems() {
-        return model.getChildren();
+        // Return the children and all the cubeUsages.
+        List<OLAPObject> items = new ArrayList<OLAPObject>();
+        items.addAll(model.getCubeUsage().getCubeUsages());
+        items.addAll(model.getChildren());
+        return items;
     }

     public void updateUI() {

Modified: trunk/src/ca/sqlpower/architect/swingui/olap/action/OLAPDeleteSelectedAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/action/OLAPDeleteSelectedAction.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/olap/action/OLAPDeleteSelectedAction.java Thu Aug 28 11:39:05 2008
@@ -34,6 +34,7 @@

 import ca.sqlpower.architect.olap.OLAPObject;
 import ca.sqlpower.architect.olap.MondrianModel.Cube;
+import ca.sqlpower.architect.olap.MondrianModel.CubeUsage;
 import ca.sqlpower.architect.olap.MondrianModel.Dimension;
 import ca.sqlpower.architect.olap.MondrianModel.DimensionUsage;
 import ca.sqlpower.architect.olap.MondrianModel.Hierarchy;
@@ -136,6 +137,10 @@
                 objectsWithSelectedItems.add(item.getParent());
} else if (item instanceof VirtualCubeDimension || item instanceof VirtualCubeMeasure) {
                 objectsWithSelectedItems.add(item.getParent());
+            } else if (item instanceof CubeUsage) {
+ // Parent of CubeUsage is CubeUsages. Parent of CubeUsages is
+                // VirtualCube and we do not want to delete the VirtualCube
+                objectsWithSelectedItems.add(item.getParent().getParent());
             } else if (item instanceof Hierarchy) {
                 if (item.getParent().getParent() instanceof Schema) {
// If the Hierarchy is in a public dimension, then the DimensionPane

Reply via email to