Author: truesweetman
Date: Wed Aug 27 11:38:27 2008
New Revision: 2630

Modified:
   trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
trunk/src/ca/sqlpower/architect/swingui/olap/action/OLAPDeleteSelectedAction.java

Log:
Ahhh!  I committed the wrong to files in the last commit...

In this commit, I will replace the wrong file (OLAPDeleteSelectedAction) I committed (2627) with the previous version and I also will commit the correct file (PlayPen) for the synchro fix.

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 Wed Aug 27 11:38:27 2008
@@ -2741,9 +2741,16 @@
selectMeasure((Measure) obj, ignoredObjs, extraSelections, tree); } else if (obj instanceof VirtualCubeDimension || obj instanceof VirtualCubeMeasure) { selectItemFromVirtualCube(obj, ignoredObjs, extraSelections, tree);
-            } else if (obj instanceof Hierarchy) {
+ } 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
+                // a cube do not show hierarchies on the playPen!
selectHierarchy((Hierarchy) obj, ignoredObjs, extraSelections, tree);
-            } else if (obj instanceof Level) {
+ } else if (obj instanceof Level && obj.getParent() instanceof Hierarchy + && obj.getParent().getParent() instanceof MondrianModel.Dimension + && obj.getParent().getParent().getParent() instanceof Schema) { + // Only select levels from the public dimensions because the ones inside
+                // a cube do not show levels on the playPen!
selectLevel((Level) obj, ignoredObjs, extraSelections, tree);
             }


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 Wed Aug 27 11:38:27 2008
@@ -20,126 +20,48 @@
 package ca.sqlpower.architect.swingui.olap.action;

 import java.awt.event.ActionEvent;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;

 import javax.swing.JOptionPane;
 import javax.swing.tree.TreePath;

-import org.apache.log4j.Logger;
-
 import ca.sqlpower.architect.olap.OLAPObject;
-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.Hierarchy;
-import ca.sqlpower.architect.olap.MondrianModel.Level;
-import ca.sqlpower.architect.olap.MondrianModel.Measure;
-import ca.sqlpower.architect.olap.MondrianModel.VirtualCubeDimension;
-import ca.sqlpower.architect.olap.MondrianModel.VirtualCubeMeasure;
 import ca.sqlpower.architect.swingui.ArchitectSwingSession;
 import ca.sqlpower.architect.swingui.action.AbstractArchitectAction;
 import ca.sqlpower.architect.swingui.olap.OLAPEditSession;
-import ca.sqlpower.architect.swingui.olap.OLAPTree;

 /**
* This action deletes OLAPObjects that are selected on the OLAPTree using removeChild methods.
  */
 public class OLAPDeleteSelectedAction extends AbstractArchitectAction {

- private static final Logger logger = Logger.getLogger(OLAPDeleteSelectedAction.class);
-
     private final OLAPEditSession editSession;

-    private OLAPTree tree;
-
public OLAPDeleteSelectedAction(ArchitectSwingSession session, OLAPEditSession editSession) { super(session, editSession.getOlapPlayPen(), "Delete Selected", "Delete selected item.", (String) null);
         this.editSession = editSession;
-        this.tree = editSession.getOlapTree();
     }

     public void actionPerformed(ActionEvent arg0) {
-        List<OLAPObject> itemsToDelete = getDeletableItems();
-        if (itemsToDelete.size() > 1 ) {
- int decision = JOptionPane.showConfirmDialog(editSession.getDialog(), "Are you sure you want to delete the following " + itemsToDelete.size() + " items?",
+        TreePath[] tps = editSession.getOlapTree().getSelectionPaths();
+        if (tps.length > 1 ) {
+ int decision = JOptionPane.showConfirmDialog(editSession.getDialog(), "Are you sure you want to delete the following " + tps.length + " items?",
                             "Multiple Delete", JOptionPane.YES_NO_OPTION);
             if (decision != JOptionPane.YES_OPTION ) {
                 return;
             }
-        } else if (itemsToDelete.size() < 1) {
+        } else if (tps.length < 1) {
             JOptionPane.showMessageDialog(playpen, "No items to delete!");
             return;
         }
         try {
             playpen.startCompoundEdit("OLAP Delete");
-            for (OLAPObject oo : itemsToDelete) {
-                try {
-                    oo.getParent().removeChild(oo);
-                } catch (NullPointerException ex) {
-                    System.out.println("who dares be null!");
-                    System.out.println(oo);
-                    System.out.println(oo.getParent());
-
-                }
+            for (TreePath tp : tps) {
+                OLAPObject obj = (OLAPObject) tp.getLastPathComponent();
+                obj.getParent().removeChild(obj);
             }
         } finally {
             playpen.endCompoundEdit("OLAP Delete End");
         }

     }
-
-    /**
- * Extracts the list of items we should try to delete from the OLAPTree's
-     * selection list.
-     */
-    private List<OLAPObject> getDeletableItems() {
-        TreePath[] selectionPaths = tree.getSelectionPaths();
-        if (selectionPaths == null) return Collections.emptyList();
- List <OLAPObject> deleteItems = new ArrayList<OLAPObject>(selectionPaths.length);
-        for (int i = 0; i < selectionPaths.length; i++) {
-            if (   selectionPaths[i].getPathCount() > 1 &&
- selectionPaths[i].getPathComponent(0) == editSession.getOlapSession().getSchema()) { - deleteItems.add((OLAPObject) selectionPaths[i].getLastPathComponent());
-            } else {
-                logger.debug("Skipping non-deletable object: " +
-                        selectionPaths[i].getLastPathComponent());
-            }
-        }
-
- Set<OLAPObject> objectsWithSelectedItems = new HashSet<OLAPObject>();
-
- for (ListIterator<OLAPObject> it = deleteItems.listIterator(); it.hasNext(); ) {
-            OLAPObject item = it.next();
-            if (item instanceof Dimension) {
-                if (item.getParent() instanceof Cube) {
-                    objectsWithSelectedItems.add(item.getParent());
-                }
- } else if (item instanceof Measure || item instanceof DimensionUsage) {
-                objectsWithSelectedItems.add(item.getParent());
- } else if (item instanceof VirtualCubeDimension || item instanceof VirtualCubeMeasure) {
-                objectsWithSelectedItems.add(item.getParent());
-            } else if (item instanceof Hierarchy) {
-                objectsWithSelectedItems.add(item.getParent());
-            } else if (item instanceof Level){
-                // Level is inside Hierarchy which is inside Dimension
- // Hierarchy is not selected when Level is, but Dimension is.
-                objectsWithSelectedItems.add(item.getParent().getParent());
-            } else {
-                // for now, allow any other item to be deleted.
-            }
-        }
-
- // When a item is selected in the playpen that is contained in a cubePane, - // virtualCubePane or DimensionPane, then the matching pane is also selected. - // In this case, we want to delete the selected item(s) but NOT the pane!
-        deleteItems.removeAll(objectsWithSelectedItems);
-
-        return deleteItems;
-    }
-
 }

Reply via email to