Revision: 4059
Author:   [email protected]
Date:     Wed May 22 07:34:00 2013
Log: Fixed bug:2932. Not able copy/paste table into the same playpen. Got the exception because user trying to paste table while copied table still selected. Now user can paste table while copied table still selected.
http://code.google.com/p/power-architect/source/detail?r=4059

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Fri Aug 19 08:36:52 2011 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Wed May 22 07:34:00 2013
@@ -2308,7 +2308,8 @@
* The transferable to get objects from to add to the playpen
      */
        public void pasteData(Transferable t) {
-        if (!getSelectedContainers().isEmpty()) {
+ // check if user trying to paste table while copied table is still selected
+        if (!getSelectedContainers().isEmpty()  &&  !isCopyingTable(t)) {
             for (ContainerPane<?, ?> cp : getSelectedContainers()) {
                 cp.pasteData(t);
             }
@@ -2333,7 +2334,42 @@
         }
        }

-       public class TablePaneDragGestureListener implements 
DragGestureListener {
+       /**
+ * This method checks if user try to paste table while copied table is still selected instead of playpen
+        * @param t
+        * @return true if trying to paste table
+        */
+       private boolean isCopyingTable(Transferable t) {
+
+           boolean copyingTable = false;
+
+           List<? extends SQLObject> copyingItems;
+
+           for (ContainerPane<?, ?> cp : getSelectedContainers()) {
+ DataFlavor flavor = cp.bestImportFlavor(this, t.getTransferDataFlavors());
+
+               try {
+ if (flavor == SQLObjectSelection.LOCAL_SQLOBJECT_ARRAY_FLAVOUR) { + copyingItems = Arrays.asList((SQLObject[]) t.getTransferData(flavor));
+                       for(SQLObject o:copyingItems ) {
+                           if (o instanceof SQLTable) {
+                               copyingTable = true;
+                               break;
+                           }
+                       }
+                       if(copyingTable) break;
+                   }
+               } catch (UnsupportedFlavorException e) {
+ throw new RuntimeException("Cannot add items to a table of type " + flavor, e);
+               } catch (IOException e) {
+ throw new RuntimeException("Transfer type changed while adding it to the table", e);
+               }
+           }
+
+           return copyingTable;
+       }
+
+ public class TablePaneDragGestureListener implements DragGestureListener {
                public void dragGestureRecognized(DragGestureEvent dge) {

             // ignore drag events that aren't from the left mouse button

--

--- You received this message because you are subscribed to the Google Groups "Architect Commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to