Author: [EMAIL PROTECTED]
Date: Tue Oct 14 14:20:06 2008
New Revision: 2777
Modified:
trunk/src/ca/sqlpower/architect/swingui/DBTree.java
trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
Log:
Created a new data flavor for the DBTree node. this data flavor is list of
selected node names. Created an overloading constructor for the
DnDTreePathTransferable class to accept the selected tree path. THe DBTree
class now uses the overloading constructor, so the other classes can access
the selected nodes names.
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 14 14:20:06
2008
@@ -922,7 +922,6 @@
DBTree t = (DBTree) dge.getComponent();
TreePath[] p = t.getSelectionPaths();
-
if (p == null || p.length == 0) {
// nothing to export
return;
@@ -947,7 +946,7 @@
dge.getDragSource().startDrag
(dge,
null, //DragSource.DefaultCopyNoDrop,
- new DnDTreePathTransferable(paths,
userVisibleName.toString()),
+ new DnDTreePathTransferable(paths, userVisibleName.toString(),
t.getSelectionPaths()),
t);
}
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/DnDTreePathTransferable.java
Tue Oct 14 14:20:06 2008
@@ -26,6 +26,8 @@
import java.util.Arrays;
import java.util.List;
+import javax.swing.tree.TreePath;
+
import org.apache.log4j.Logger;
import ca.sqlpower.architect.ArchitectException;
@@ -38,31 +40,46 @@
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");
protected ArrayList<int[]> data;
-
+
+ protected String[] objectNames;
+
private final String userVisibleName;
- public DnDTreePathTransferable(ArrayList<int[]> data, String
userVisibleName) {
+ public DnDTreePathTransferable(ArrayList<int[]> data, String
userVisibleName) {
this.data = data;
this.userVisibleName = userVisibleName;
}
+ public DnDTreePathTransferable(ArrayList<int[]> data, String
userVisibleName, TreePath[] selectedObjects) {
+ this(data,userVisibleName);
+ objectNames = getObjectNames(selectedObjects);
+ }
+
+
public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] { TREEPATH_ARRAYLIST_FLAVOR };
+ return new DataFlavor[] { TREEPATH_ARRAYLIST_FLAVOR,
TREE_OBJECT_NAMES };
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
- return (flavor.equals(TREEPATH_ARRAYLIST_FLAVOR));
+ return (flavor.equals(TREEPATH_ARRAYLIST_FLAVOR) ||
flavor.equals(TREE_OBJECT_NAMES));
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
- if (flavor != TREEPATH_ARRAYLIST_FLAVOR) {
- throw new IllegalArgumentException("Unsupported flavor
"+flavor);
+
+ if (flavor == TREEPATH_ARRAYLIST_FLAVOR) {
+ return data;
+ }
+ else if(flavor == TREE_OBJECT_NAMES){
+ return objectNames;
+ }
+ else{
+ throw new IllegalArgumentException("Unsupported flavor
"+flavor);
}
- return data;
}
/**
@@ -100,6 +117,7 @@
}
logger.debug("Created path: " + Arrays.toString(retval));
+
return retval;
} catch (ArchitectException e) {
@@ -115,6 +133,18 @@
}
return current;
}
+
+ /**
+ * Takes the tree paths to store the names of the SQLObjects into an
ArrayList which will be used as a flavor.
+ */
+ private String[] getObjectNames(TreePath[] treePaths){
+ String[] nodeNames = new String[treePaths.length];
+ for(int i = 0; i < treePaths.length; i++){
+ nodeNames[i]=
((SQLObject)treePaths[i].getLastPathComponent()).getName();
+ }
+ return nodeNames;
+ }
+
@Override
public String toString() {