Author: thomasobrien95
Date: Tue Oct 21 07:16:44 2008
New Revision: 2796

Added:
trunk/src/ca/sqlpower/architect/swingui/dbtree/DnDTreePathTransferable.java (contents, props changed) - copied, changed from r2795, /trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
Removed:
   trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
Modified:
   trunk/src/ca/sqlpower/architect/swingui/DBTree.java
   trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
   trunk/src/ca/sqlpower/architect/swingui/TablePane.java
   trunk/src/ca/sqlpower/architect/swingui/olap/DnDOLAPTransferable.java
   trunk/src/ca/sqlpower/architect/swingui/query/QueryDropListener.java

Log:
Moved the DnDTreePathTransferable class to the dbtree package for use in the dbtree library. This was moved as it is currently the best implementation for dragging and dropping with a tree of SQLObjects and is needed in Wabit.

Doc comments also added.

Modified: trunk/src/ca/sqlpower/architect/swingui/DBTree.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/DBTree.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/DBTree.java Tue Oct 21 07:16:44 2008
@@ -70,6 +70,7 @@
 import ca.sqlpower.architect.swingui.action.RemoveSourceDBAction;
 import ca.sqlpower.architect.swingui.dbtree.DBTreeCellRenderer;
 import ca.sqlpower.architect.swingui.dbtree.DBTreeModel;
+import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;
 import ca.sqlpower.sql.SPDataSource;
 import ca.sqlpower.swingui.JTreeCollapseAllAction;
 import ca.sqlpower.swingui.JTreeExpandAllAction;

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 Tue Oct 21 07:16:44 2008
@@ -117,6 +117,7 @@
 import ca.sqlpower.architect.olap.MondrianModel.VirtualCubeDimension;
 import ca.sqlpower.architect.olap.MondrianModel.VirtualCubeMeasure;
 import ca.sqlpower.architect.swingui.action.CancelAction;
+import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;
 import ca.sqlpower.architect.swingui.event.PlayPenLifecycleEvent;
 import ca.sqlpower.architect.swingui.event.PlayPenLifecycleListener;
 import ca.sqlpower.architect.swingui.event.SelectionEvent;

Modified: trunk/src/ca/sqlpower/architect/swingui/TablePane.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/TablePane.java      (original)
+++ trunk/src/ca/sqlpower/architect/swingui/TablePane.java Tue Oct 21 07:16:44 2008
@@ -65,6 +65,7 @@
 import ca.sqlpower.architect.SQLTable;
 import ca.sqlpower.architect.layout.LayoutEdge;
 import ca.sqlpower.architect.swingui.action.EditSpecificIndexAction;
+import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;
 import ca.sqlpower.swingui.ColorIcon;
 import ca.sqlpower.swingui.SPSUtils;


Copied: trunk/src/ca/sqlpower/architect/swingui/dbtree/DnDTreePathTransferable.java (from r2795, /trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java)
==============================================================================
--- /trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/dbtree/DnDTreePathTransferable.java Tue Oct 21 07:16:44 2008
@@ -16,11 +16,12 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-package ca.sqlpower.architect.swingui;
+package ca.sqlpower.architect.swingui.dbtree;

 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DropTargetDropEvent;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -34,6 +35,21 @@
 import ca.sqlpower.architect.ArchitectRuntimeException;
 import ca.sqlpower.architect.SQLObject;

+/**
+ * This class transfers an object dragged from a DBTree. The object dragged is + * stored by an array list of its path in the tree and as the string names of
+ * the nodes selected from the tree.
+ * <p>
+ * The object dragged can be found by the tree path stored as an integer array + * in this class. The object dragged is not stored in this transferable directly + * as SQLObject is not serializable and only serializable objects or tree paths
+ * of serializable objects can be dropped through a transferable. The
+ * implemented solution is to track the path of the node in the tree by an
+ * integer array and use that to get the object back after the drop. The problem
+ * with this approach is dragging from one session to another will possibly
+ * cause different objects to be dragged as the trees can be different and the
+ * array list only points to positions in the tree.
+ */
public class DnDTreePathTransferable implements Transferable, java.io.Serializable {

private static final Logger logger = Logger.getLogger(DnDTreePathTransferable.class);
@@ -41,10 +57,17 @@
public static final DataFlavor TREEPATH_ARRAYLIST_FLAVOR = new DataFlavor
                (ArrayList.class, "List of selected tree paths");

- public static final DataFlavor TREE_OBJECT_NAMES = new DataFlavor(String[].class, "List of selected object names");
-       
+ public static final DataFlavor TREE_OBJECT_NAMES = new DataFlavor(String[].class, "List of selected object names");
+
+    /**
+ * The collection of the integer arrays that point to all of the selected
+     * SQLObjects in the tree.
+     */
        protected ArrayList<int[]> data;
        
+       /**
+ * A string array that contains the names of the selected nodes in the tree.
+        */
        protected String[] objectNames;
        
     private final String userVisibleName;
@@ -125,6 +148,23 @@
            }
     }

+       /**
+        * Gets a SQLObject from the tree by following the path of integers
+        * through the tree. Each integer represents the child number of the
+        * node retrieved from the number before it.
+        * <p>
+        * NOTE: This path will only make sense if the tree that the object
+        * was dragged from has the same structure as the tree that contains
+        * the given root object. If the tree from the dragged object and
+        * the tree connected by the given root object are different then
+        * either the wrong node will be selected or the path will try to
+        * select a node out of bounds. This problem often comes up when
+        * dragging from one architect tree to another.
+        * <p>
+        * A partial solution is to check if the drop is local by using the
+        * isLocalTransfer() method on a [EMAIL PROTECTED] 
DropTargetDropEvent}. This
+        * will check if the drag came from the same JVM.
+        */
public static SQLObject getNodeForDnDPath(SQLObject root, int[] path) throws ArchitectException {
            logger.debug("Resolving path " + root + ": " + 
Arrays.toString(path));
            SQLObject current = root;

Modified: trunk/src/ca/sqlpower/architect/swingui/olap/DnDOLAPTransferable.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/olap/DnDOLAPTransferable.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/olap/DnDOLAPTransferable.java Tue Oct 21 07:16:44 2008
@@ -29,11 +29,11 @@

 import ca.sqlpower.architect.olap.OLAPObject;
 import ca.sqlpower.architect.olap.OLAPUtil;
-import ca.sqlpower.architect.swingui.DnDTreePathTransferable;
 import ca.sqlpower.architect.swingui.PlayPen;
 import ca.sqlpower.architect.swingui.PlayPenComponent;
 import ca.sqlpower.architect.swingui.PlayPenContentPane;
 import ca.sqlpower.architect.swingui.PlayPenCoordinate;
+import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;

public class DnDOLAPTransferable implements Transferable, java.io.Serializable {


Modified: trunk/src/ca/sqlpower/architect/swingui/query/QueryDropListener.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/query/QueryDropListener.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/query/QueryDropListener.java Tue Oct 21 07:16:44 2008
@@ -37,7 +37,7 @@
 import ca.sqlpower.architect.SQLObject;
 import ca.sqlpower.architect.SQLTable;
 import ca.sqlpower.architect.swingui.DBTree;
-import ca.sqlpower.architect.swingui.DnDTreePathTransferable;
+import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;
 import ca.sqlpower.swingui.query.SQLQueryUIComponents;

 /**

Reply via email to