Revision: 3712
Author: [email protected]
Date: Mon Jul 12 09:30:04 2010
Log: Added drag and drop support to the muti-tabbed tree.
http://code.google.com/p/power-architect/source/detail?r=3712
Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Mon Jul 12 08:21:11 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Mon Jul 12 09:30:04 2010
@@ -25,6 +25,13 @@
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
@@ -144,6 +151,7 @@
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.sqlobject.SQLTable.TransferStyles;
import ca.sqlpower.swingui.DataEntryPanelBuilder;
import ca.sqlpower.swingui.RecentMenu;
import ca.sqlpower.swingui.SPSUtils;
@@ -175,9 +183,9 @@
private JToolBar projectBar = null;
private JToolBar ppBar = null;
private JMenuBar menuBar = null;
- JSplitPane splitPane = null;
- StackedTabComponent stackedTabPane = new StackedTabComponent();
- BiMap<ArchitectSwingSession, StackedTab> sessionTabs =
HashBiMap.create();
+ private JSplitPane splitPane = null;
+ private StackedTabComponent stackedTabPane = new StackedTabComponent();
+ private BiMap<ArchitectSwingSession, StackedTab> sessionTabs =
HashBiMap.create();
private Navigator navigatorDialog;
private CompareDMDialog compareDMDialog = null;
@@ -188,6 +196,8 @@
private int prefHeight;
private final UserPrompterFactory nonModalUserPrompterFactory;
+
+ private final DropTargetListener tabDropTargetListener = new
TabDropTargetListener();
private JMenu connectionsMenu;
private ArchitectLayout autoLayout;
@@ -482,7 +492,8 @@
// close is handled by a window listener
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- stackedTabPane.addChangeListener(tabChangeListener );
+ stackedTabPane.addChangeListener(tabChangeListener);
+ stackedTabPane.setDropTarget(new DropTarget(stackedTabPane,
tabDropTargetListener));
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(stackedTabPane);
@@ -1499,5 +1510,53 @@
public ArchitectSwingSession getCurrentSession() {
return currentSession;
}
+
+ private class TabDropTargetListener implements DropTargetListener {
+ public void dragEnter(DropTargetDragEvent dtde) {
+ // don't care
+ }
+
+ public void dragExit(DropTargetEvent dte) {
+ // don't care
+ }
+
+ public void dragOver(DropTargetDragEvent dtde) {
+ Point mouseLocation = dtde.getLocation();
+ int index = stackedTabPane.indexAtLocation(mouseLocation.x,
mouseLocation.y);
+ if (index != -1) {
+ dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE &
dtde.getDropAction());
+ } else {
+ dtde.rejectDrag();
+ }
+ }
+
+ public void drop(DropTargetDropEvent dtde) {
+ Point mouseLocation = dtde.getLocation();
+ int index = stackedTabPane.indexAtLocation(mouseLocation.x,
mouseLocation.y);
+ StackedTab tab = stackedTabPane.getTabs().get(index);
+ PlayPen playPen = sessionTabs.inverse().get(tab).getPlayPen();
+ try {
+ if (playPen.addTransferable(dtde.getTransferable(), new
Point(playPen.getLocation().x + 100, playPen.getLocation().y + 100),
TransferStyles.COPY)) {
+ dtde.acceptDrop(DnDConstants.ACTION_COPY);
+ dtde.dropComplete(true);
+ }
+ } catch (SQLObjectException e) {
+ logger.error(e);
+ dtde.rejectDrop();
+ } catch (UnsupportedFlavorException e) {
+ logger.error(e);
+ dtde.rejectDrop();
+ } catch (IOException e) {
+ logger.error(e);
+ dtde.rejectDrop();
+ }
+ }
+
+ public void dropActionChanged(DropTargetDragEvent dtde) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon Jul
12 08:21:11 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon Jul
12 09:30:04 2010
@@ -994,17 +994,6 @@
public void setMouseZoomOutAction(Action zoomOutAction){
this.zoomOutAction = zoomOutAction;
}
-
- /**
- * Returns the scrollPane used in this PlayPen. If none has been set,
it
- * returns the default scrollPane from the ArchitectFrame
- */
- public Component getScrollPane(){
- if (ppScrollPane == null) {
- return
session.getArchitectFrame().splitPane.getRightComponent();
- }
- return ppScrollPane;
- }
/**
* Modifies the given point p in model space to apparent position in
screen
@@ -2216,6 +2205,7 @@
* in the transferable to the play pen. If there is no transferable
object
* then if there is a string or list of strings in the transferable
this
* method will try to create SQLObjects for the transferred values.
+ * This is package protected for the ArchitectFrame's benefit.
*
* @param t
* The transferable to get objects from to add to the
playpen
@@ -2227,7 +2217,7 @@
* @throws UnsupportedFlavorException
* @throws SQLObjectException
*/
- private boolean addTransferable(Transferable t, Point dropPoint,
TransferStyles transferStyle)
+ boolean addTransferable(Transferable t, Point dropPoint, TransferStyles
transferStyle)
throws UnsupportedFlavorException, IOException, SQLObjectException {
if
(t.isDataFlavorSupported(SQLObjectSelection.LOCAL_SQLOBJECT_ARRAY_FLAVOUR)