Author: thomasobrien95
Date: Tue Apr 7 16:40:12 2009
New Revision: 2980
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
trunk/src/ca/sqlpower/architect/swingui/TablePane.java
Log:
Undid some changes to make moving columns involved with relationships
work again.
Also added the ability to paste in text into the play pen and have
tables be created by the names pasted in. Columns can also be
created by pasting in text.
Modified: trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
(original)
+++ trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java Tue Apr
7 16:40:12 2009
@@ -94,97 +94,69 @@
assertEquals(7, t.getColumns().size());
assertEquals(4, t.getPkSize());
}
-
+
+ /** This tests for a regression we found in March 2006 (bug 1057) */
+ public void testInsertColumnAtStartOfNonPK() throws Exception {
+ SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10, 0);
+ t.addColumn(0, newcol);
+
+ assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+
+ List<SQLObject> movecolList = new ArrayList<SQLObject>();
+ movecolList.add(newcol);
+ tp.insertObjects(movecolList, TablePane.COLUMN_INDEX_START_OF_NON_PK,
true);
+
+ assertEquals(3, t.getColumnIndex(newcol));
+ assertNull("Column should have moved out of primary key",
newcol.getPrimaryKeySeq());
+ }
+
/** This tests for a regression we found in March 2006 (bug 1057) */
- public void testInsertColumnAtStartOfNonPK() throws SQLObjectException
{
- SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10,
0);
- t.addColumn(0, newcol);
-
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
-
- List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
-
- List<SQLObject> movecolList = new ArrayList<SQLObject>();
- movecolList.add(newcol);
- tp.insertObjects(movecolList,
TablePane.COLUMN_INDEX_START_OF_NON_PK, true);
-
- List<SQLColumn> newColumns = new
ArrayList<SQLColumn>(t.getColumns());
- newColumns.removeAll(oldColumns);
-
- assertEquals(1, newColumns.size());
- final SQLColumn copyCol = newColumns.get(0);
- assertEquals(3, t.getColumnIndex(copyCol));
- assertNull("Column should have moved out of primary key",
copyCol.getPrimaryKeySeq());
- }
-
- /** This tests for a regression we found in March 2006 (bug 1057) */
- public void testInsertColumnAboveFirstNonPKColumn() throws
SQLObjectException {
- SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10,
0);
- t.addColumn(0, newcol);
-
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
-
- List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
-
- List<SQLObject> movecolList = new ArrayList<SQLObject>();
- movecolList.add(newcol);
- tp.insertObjects(movecolList, 4, true);
-
- List<SQLColumn> newColumns = new
ArrayList<SQLColumn>(t.getColumns());
- newColumns.removeAll(oldColumns);
-
- assertEquals(1, newColumns.size());
- final SQLColumn copyCol = newColumns.get(0);
- assertEquals(3, t.getColumnIndex(copyCol));
- assertNull("Column should have moved out of primary key",
copyCol.getPrimaryKeySeq());
- }
-
- public void testInsertNewColumnAboveFirstNonPKColumn() throws
SQLObjectException {
- SQLTable t2 = new SQLTable(t.getParentDatabase(), true);
- t2.setName("Another Test Table");
- SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
- t2.addColumn(0, newcol);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
-
- List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
-
- List<SQLObject> movecolList = new ArrayList<SQLObject>();
- movecolList.add(newcol);
- tp.insertObjects(movecolList, 3, true);
-
- List<SQLColumn> newColumns = new
ArrayList<SQLColumn>(t.getColumns());
- newColumns.removeAll(oldColumns);
-
- assertEquals(1, newColumns.size());
- final SQLColumn copyCol = newColumns.get(0);
- assertEquals(3, t.getColumnIndex(copyCol));
- assertNull("Column should not be in primary key",
copyCol.getPrimaryKeySeq());
- }
-
- /** This tests for a real regression (the column was ending up at
index 2 instead of 3) */
- public void testInsertNewColumnAtEndOfPK() throws SQLObjectException {
- SQLTable t2 = new SQLTable(t.getParentDatabase(), true);
- t2.setName("Another Test Table");
- SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
- t2.addColumn(0, newcol);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
-
- List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
-
- List<SQLObject> movecolList = new ArrayList<SQLObject>();
- movecolList.add(newcol);
- tp.insertObjects(movecolList, TablePane.COLUMN_INDEX_END_OF_PK,
true);
-
- List<SQLColumn> newColumns = new
ArrayList<SQLColumn>(t.getColumns());
- newColumns.removeAll(oldColumns);
-
- assertEquals(1, newColumns.size());
- final SQLColumn copyCol = newColumns.get(0);
- assertEquals(3, t.getColumnIndex(copyCol));
- assertNotNull("Column should be in primary key",
copyCol.getPrimaryKeySeq());
- }
+ public void testInsertColumnAboveFirstNonPKColumn() throws Exception {
+ SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10, 0);
+ t.addColumn(0, newcol);
+
+ assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+
+ List<SQLObject> movecolList = new ArrayList<SQLObject>();
+ movecolList.add(newcol);
+ tp.insertObjects(movecolList, 4, true);
+
+ assertEquals(3, t.getColumnIndex(newcol));
+ assertNull("Column should have moved out of primary key",
newcol.getPrimaryKeySeq());
+ }
+
+ public void testInsertNewColumnAboveFirstNonPKColumn() throws Exception
{
+ SQLTable t2 = new SQLTable(t.getParentDatabase(), true);
+ t2.setName("Another Test Table");
+ SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
+ t2.addColumn(0, newcol);
+ newcol.setPrimaryKeySeq(1);
+ assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+
+ List<SQLObject> movecolList = new ArrayList<SQLObject>();
+ movecolList.add(newcol);
+ tp.insertObjects(movecolList, 3, true);
+
+ assertEquals(3, t.getColumnIndex(newcol));
+ assertNull("Column should not be in primary key",
newcol.getPrimaryKeySeq());
+ }
+
+ /** This tests for a real regression (the column was ending up at index 2
instead of 3) */
+ public void testInsertNewColumnAtEndOfPK() throws Exception {
+ SQLTable t2 = new SQLTable(t.getParentDatabase(), true);
+ t2.setName("Another Test Table");
+ SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
+ t2.addColumn(0, newcol);
+ newcol.setPrimaryKeySeq(1);
+ assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+
+ List<SQLObject> movecolList = new ArrayList<SQLObject>();
+ movecolList.add(newcol);
+ tp.insertObjects(movecolList, TablePane.COLUMN_INDEX_END_OF_PK,
true);
+
+ assertEquals(3, t.getColumnIndex(newcol));
+ assertNotNull("Column should be in primary key",
newcol.getPrimaryKeySeq());
+ }
/** This tests for a regression we found in March 2006 (bug 1057) */
public void testInsertColumnAtStartOfNonPKByCopy() throws
SQLObjectException {
Modified:
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
==============================================================================
---
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
(original)
+++
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Tue Apr 7 16:40:12 2009
@@ -177,6 +177,9 @@
// sets the icon so exception dialogs handled by SPSUtils instead
// of ASUtils can still have the correct icon
SPSUtils.setMasterIcon(new ImageIcon(ASUtils.getFrameIconImage()));
+
+ logger.debug("toolkit has system clipboard " +
Toolkit.getDefaultToolkit().getSystemClipboard());
+ clipboard.setContents(dummyTransferable, this);
}
/**
@@ -386,24 +389,30 @@
}
public Transferable getClipboardContents() {
+ logger.debug("local clipboard contents are " +
clipboard.getContents(null));
if (clipboard.getContents(null) != dummyTransferable) {
+ logger.debug("Getting clipboard contents from local
clipboard");
return clipboard.getContents(null);
}
+ logger.debug("Getting clipboard contents from system");
return
Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
}
public void setClipboardContents(Transferable t) {
clipboard.setContents(t, this);
+ logger.debug("Setting local clipboard contents");
if (t instanceof SQLObjectSelection) {
((SQLObjectSelection) t).setLocal(false);
}
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(t,
this);
+ logger.debug("toolkit pasting to system clipboard " +
Toolkit.getDefaultToolkit().getSystemClipboard());
if (t instanceof SQLObjectSelection) {
((SQLObjectSelection) t).setLocal(true);
}
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {
- clipboard.setContents(dummyTransferable, this);
+ this.clipboard.setContents(dummyTransferable, this);
+ logger.debug("Context lost clipboard ownership");
}
}
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 Apr 7
16:40:12 2009
@@ -2206,6 +2206,20 @@
// null: no next task is chained off this
addObjects(sqlObjects, dropPoint, null, transferStyle);
return true;
+ } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+ String[] stringPieces = ((String)
t.getTransferData(DataFlavor.stringFlavor)).split("[\n\r\t]+");
+ List<SQLObject> sqlObjects = new ArrayList<SQLObject>();
+ for (String s : stringPieces) {
+ if (s.length() > 0) {
+ SQLTable newTable = new SQLTable();
+ newTable.setName(s);
+ newTable.initFolders(true);
+ sqlObjects.add(newTable);
+ }
+ }
+
+ addObjects(sqlObjects, dropPoint, null, transferStyle);
+ return true;
} else {
return false;
}
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 Apr 7
16:40:12 2009
@@ -54,6 +54,7 @@
import org.apache.log4j.Logger;
+import ca.sqlpower.architect.InsertionPointWatcher;
import ca.sqlpower.architect.layout.LayoutEdge;
import
ca.sqlpower.architect.swingui.ArchitectSwingSessionImpl.ColumnVisibility;
import ca.sqlpower.architect.swingui.action.EditSpecificIndexAction;
@@ -511,13 +512,48 @@
}
} else if (someData instanceof SQLColumn) {
SQLColumn col = (SQLColumn) someData;
-
- // importing column from a source database
- getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
- if (logger.isDebugEnabled())
logger.debug("Inherited "+col.getName()+" to table with precision " +
col.getPrecision()); //$NON-NLS-1$ //$NON-NLS-2$
- ASUtils.correctSourceColumn(col, duplicateProperties,
getModel().getColumnByName(col.getName()),
getPlayPen().getSession().getSourceDatabases());
if (deleteSource) {
- col.removeReference();
+ if (col.getParentTable() == getModel()) {
+ // moving column inside the same table
+ int oldIndex =
col.getParentTable().getColumns().indexOf(col);
+ if (insertionPoint > oldIndex) {
+ insertionPoint--;
+ }
+ getModel().changeColumnIndex(oldIndex, insertionPoint,
newColumnsInPk);
+ } else if (col.getParentTable().getParentDatabase() ==
getModel().getParentDatabase()) {
+ // moving column within playpen
+
+ InsertionPointWatcher<SQLTable.Folder<SQLColumn>> ipWatcher
=
+ new
InsertionPointWatcher<SQLTable.Folder<SQLColumn>>(getModel().getColumnsFolder(),
insertionPoint);
+ col.getParentTable().removeColumn(col);
+ ipWatcher.dispose();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Moving column '"+col.getName()
//$NON-NLS-1$
+ +"' to table '"+getModel().getName()
//$NON-NLS-1$
+ +"' at
position "+ipWatcher.getInsertionPoint()); //$NON-NLS-1$
+ }
+
getModel().addColumn(ipWatcher.getInsertionPoint(), col);
+ // You need to disable the normalization otherwise it goes
around
+ // the property change events and causes undo to fail when
dragging
+ // into the primary key of a table
+ logger.debug("Column listeners are " +
col.getSQLObjectListeners());
+
+ if (newColumnsInPk) {
+ col.setPrimaryKeySeq(new
Integer(ipWatcher.getInsertionPoint()), false);
+ } else {
+ col.setPrimaryKeySeq(null, false);
+ }
+ } else {
+ // importing column from a source database
+ getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
+ if (logger.isDebugEnabled())
logger.debug("Inherited "+col.getName()+" to table with precision " +
col.getPrecision()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ } else {
+ getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
+ if (logger.isDebugEnabled())
logger.debug("Inherited "+col.getName()+" to table with precision " +
col.getPrecision()); //$NON-NLS-1$ //$NON-NLS-2$
+ ASUtils.correctSourceColumn(col, duplicateProperties,
getModel().getColumnByName(col.getName()),
getPlayPen().getSession().getSourceDatabases());
}
} else {
return false;
@@ -727,7 +763,22 @@
try {
int insertionPoint = pointToItemIndex(loc);
- List<SQLObject> droppedItems = Arrays.asList((SQLObject[])
t.getTransferData(importFlavor));
+ List<SQLObject> droppedItems;
+ if (importFlavor ==
SQLObjectSelection.LOCAL_SQLOBJECT_ARRAY_FLAVOUR) {
+ droppedItems = Arrays.asList((SQLObject[])
t.getTransferData(importFlavor));
+ } else if (importFlavor == DataFlavor.stringFlavor) {
+ String[] stringPieces = ((String)
t.getTransferData(DataFlavor.stringFlavor)).split("[\n\r\t]+");
+ droppedItems = new ArrayList<SQLObject>();
+ for (String s : stringPieces) {
+ if (s.length() > 0) {
+ SQLColumn newCol = new SQLColumn();
+ newCol.setName(s);
+ droppedItems.add(newCol);
+ }
+ }
+ } else {
+ return false;
+ }
logger.debug("Importing items: " + droppedItems); //$NON-NLS-1$
@@ -761,6 +812,9 @@
}
success = insertObjects(droppedItems, insertionPoint,
deleteSource);
} catch (LockedColumnException ex ) {
+ if (logger.isDebugEnabled()) {
+ ex.printStackTrace();
+ }
JOptionPane.showConfirmDialog(pp,
"Could not delete the column " + //$NON-NLS-1$
ex.getCol().getName() +
@@ -843,6 +897,11 @@
if
(flavors[i].equals(SQLObjectSelection.LOCAL_SQLOBJECT_ARRAY_FLAVOUR)) {
logger.debug("YES"); //$NON-NLS-1$
+ return flavors[i];
+ }
+ }
+ for (int i = 0; i < flavors.length; i++) {
+ if (flavors[i].equals(DataFlavor.stringFlavor)) {
return flavors[i];
}
}