Revision: 3813
Author: [email protected]
Date: Fri Jul 30 07:49:27 2010
Log: Added the snapshots to the dbtree. Now we can see what is happening
with the snapshots.
Now that we can see the snapshots we need to do some clean up.
http://code.google.com/p/power-architect/source/detail?r=3813
Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Mon Jul
26 15:46:35 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Fri Jul
30 07:49:27 2010
@@ -144,7 +144,7 @@
public DBTree(final ArchitectSwingSession session) {
this.session = session;
- treeModel = new DBTreeModel(session.getRootObject(), this);
+ treeModel = new DBTreeModel(session.getRootObject(), this,
session.getWorkspace());
setModel(treeModel);
setUI(new MultiDragTreeUI());
setRootVisible(false);
@@ -954,6 +954,7 @@
//type are selected.
Map<Integer, List<SQLObject>> pathLengthsToSelectedObjectsMap
= new HashMap<Integer, List<SQLObject>>();
for (int i = 0; i < p.length; i++) {
+ if (!(p[i].getLastPathComponent() instanceof SQLObject))
continue;
if
(pathLengthsToSelectedObjectsMap.get(p[i].getPathCount()) == null) {
pathLengthsToSelectedObjectsMap.put(p[i].getPathCount(), new
ArrayList<SQLObject>());
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java
Thu May 27 07:42:00 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java
Fri Jul 30 07:49:27 2010
@@ -21,6 +21,9 @@
import java.awt.Color;
import java.awt.Component;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -31,6 +34,7 @@
import org.apache.log4j.Logger;
+import ca.sqlpower.architect.swingui.SQLTypeTreeCellRenderer;
import ca.sqlpower.sqlobject.SQLCatalog;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLDatabase;
@@ -39,6 +43,7 @@
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.UserDefinedSQLTypeSnapshot;
import ca.sqlpower.sqlobject.SQLIndex.Column;
import ca.sqlpower.sqlobject.SQLRelationship.SQLImportedKey;
import ca.sqlpower.swingui.ComposedIcon;
@@ -70,6 +75,8 @@
public static final ImageIcon UNIQUE_INDEX_ICON = new
ImageIcon(DBTreeCellRenderer.class.getResource("icons/Index_unique16.png"));
public static final ImageIcon COLUMN_ICON = new
ImageIcon(DBTreeCellRenderer.class.getResource("icons/Column16.png"));
public static final ImageIcon ERROR_BADGE = new
ImageIcon(DBTreeCellRenderer.class.getResource("/icons/parts/noAccess.png"));
+ //XXX Wrong icon! for testing currently
+ public static final ImageIcon REFRESH_ICON = new
ImageIcon(DBTreeCellRenderer.class.getResource("/icons/arrow_refresh16.png"));
private final List<IconFilter> iconFilterChain = new
ArrayList<IconFilter>();
@@ -142,6 +149,33 @@
tagColumn((col).getColumn());
}
setIcon(COLUMN_ICON);
+ } else if (value instanceof UserDefinedSQLTypeSnapshot &&
+ !((UserDefinedSQLTypeSnapshot) value).isDomainSnapshot()) {
+ UserDefinedSQLTypeSnapshot snapshot =
(UserDefinedSQLTypeSnapshot) value;
+ setText(snapshot.getSPObject().getName());
+ if (snapshot.isObsolete()) {
+ final BufferedImage bufferedImage =
+ new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
+
+ Graphics2D g = bufferedImage.createGraphics();
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ g.drawImage(REFRESH_ICON.getImage(), 8, 8, 8, 8, new
Color(0xffffffff, true), null);
+ g.dispose();
+
+
setIcon(ComposedIcon.getInstance(SQLTypeTreeCellRenderer.TYPE_ICON,
+ new ImageIcon(bufferedImage)));
+ } else {
+ setIcon(SQLTypeTreeCellRenderer.TYPE_ICON);
+ }
+ } else if (value instanceof UserDefinedSQLTypeSnapshot &&
+ ((UserDefinedSQLTypeSnapshot) value).isDomainSnapshot()) {
+ setText(((UserDefinedSQLTypeSnapshot)
value).getSPObject().getName());
+ setIcon(SQLTypeTreeCellRenderer.DOMAIN_ICON);
+ } else if (tree.getModel() instanceof DBTreeModel &&
+ value == ((DBTreeModel)
tree.getModel()).getSnapshotContainer()) {
+ setText("Types");
+ setIcon(null);
} else {
setIcon(null);
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
Thu Jul 29 07:58:38 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
Fri Jul 30 07:49:27 2010
@@ -45,6 +45,7 @@
import ca.sqlpower.object.SPChildEvent;
import ca.sqlpower.object.SPListener;
import ca.sqlpower.object.SPObject;
+import ca.sqlpower.object.SPObjectSnapshot;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLIndex;
@@ -216,7 +217,7 @@
positions, folderList.toArray());
fireTreeNodesInserted(evt);
} else {
- setupTreeForNode((SQLObject) e.getChild());
+ setupTreeForNode((SPObject) e.getChild());
}
}
@@ -335,7 +336,11 @@
* {...@link SPObject}.
*/
private boolean isSPObjectRelevant(SPObject spObject) {
- if (!SQLPowerUtils.getAncestorList(spObject).contains(root)
&& !spObject.equals(root)) {
+ if (spObject == getSnapshotContainer()) {
+ return true;
+ } else if (spObject instanceof SPObjectSnapshot<?> &&
spObject.getParent() == getSnapshotContainer()) {
+ return true;
+ } if (!SQLPowerUtils.getAncestorList(spObject).contains(root)
&& !spObject.equals(root)) {
return false;
} else if (!showColumns && spObject instanceof SQLColumn) {
return false;
@@ -428,6 +433,12 @@
*/
private final boolean showIndices;
+ /**
+ * Contains all of the snapshots we want to display in the tree. If
this is
+ * null no snapshots will be shown.
+ */
+ private final SPObject snapshotContainer;
+
/**
* Creates a tree model with all of the SQLDatabase objects in the
given
* session's root object in its root list of databases, as well as all
the
@@ -441,6 +452,24 @@
public DBTreeModel(SQLObjectRoot root, JTree tree) {
this(root, tree, true, true, true, true, true);
}
+
+ /**
+ * Creates a new tree model with all the SQLDatabase objects with
exclusion
+ * of specified {...@link SQLObject}s.
+ *
+ * @param root
+ * The {...@link SQLObjectRoot} object that contains all the
+ * databases that should be displayed in the tree.
+ * @param tree
+ * The {...@link JTree} that uses this {...@link DBTreeModel}.
+ * @param snapshotContainer
+ * The object that contains {...@link SPObjectSnapshot}s as
children
+ * that we want to display in the tree. If this is null no
+ * snapshots will be displayed.
+ */
+ public DBTreeModel(SQLObjectRoot root, JTree tree, SPObject
snapshotContainer) {
+ this(root, tree, snapshotContainer, true, true, true, true, true);
+ }
/**
* Creates a new tree model with all the SQLDatabase objects with
exclusion
@@ -463,7 +492,38 @@
* true if the {...@link SQLIndex} folder should be shown.
*/
public DBTreeModel(SQLObjectRoot root, JTree tree, boolean
showPlayPenDatabase, boolean showColumns, boolean showRelationships,
boolean showImportedKeys, boolean showIndices) {
+ this(root, tree, null, showPlayPenDatabase, showColumns,
showRelationships, showImportedKeys, showIndices);
+ }
+
+ /**
+ * Creates a new tree model with all the SQLDatabase objects with
exclusion
+ * of specified {...@link SQLObject}s.
+ *
+ * @param root
+ * The {...@link SQLObjectRoot} object that contains all the
+ * databases that should be displayed in the tree.
+ * @param tree
+ * The {...@link JTree} that uses this {...@link DBTreeModel}.
+ * @param snapshotContainer
+ * The object that contains {...@link SPObjectSnapshot}s as
children
+ * that we want to display in the tree. If this is null no
+ * snapshots will be displayed.
+ * @param showPlayPenDatabase
+ * true if the playpen database should be shown.
+ * @param showColumns
+ * true if the {...@link SQLColumn} folder should be shown.
+ * @param showRelationships
+ * true if the {...@link SQLRelationship} folder should be
shown.
+ * @param showImportedKeys
+ * true if the {...@link SQLImportedKey} folder should be
shown.
+ * @param showIndices
+ * true if the {...@link SQLIndex} folder should be shown.
+ */
+ public DBTreeModel(SQLObjectRoot root, JTree tree, SPObject
snapshotContainer,
+ boolean showPlayPenDatabase, boolean showColumns, boolean
showRelationships,
+ boolean showImportedKeys, boolean showIndices) {
this.root = root;
+ this.snapshotContainer = snapshotContainer;
this.showPlayPenDatabase = showPlayPenDatabase;
this.showColumns = showColumns;
this.showRelationships = showRelationships;
@@ -474,8 +534,16 @@
SQLPowerUtils.listenToHierarchy(root, treeListener);
for (SPObject ancestor : SQLPowerUtils.getAncestorList(root)) {
+ if (ancestor == snapshotContainer) continue;
ancestor.addSPListener(treeListener);
}
+
+ if (snapshotContainer != null) {
+ snapshotContainer.addSPListener(treeListener);
+ for (SPObjectSnapshot<?> snapshot :
snapshotContainer.getChildren(SPObjectSnapshot.class)) {
+ SQLPowerUtils.listenToHierarchy(snapshot, treeListener);
+ }
+ }
setupTreeForNode(root);
}
@@ -484,12 +552,18 @@
* Recursively walks the tree doing any necessary setup for each node.
* At current this just adds folders for {...@link SQLTable} objects.
*/
- private void setupTreeForNode(SQLObject node) {
+ private void setupTreeForNode(SPObject node) {
if (node instanceof SQLTable) {
createFolders((SQLTable) node);
}
- for (SQLObject child : node.getChildrenWithoutPopulating()) {
- setupTreeForNode(child);
+ if (node instanceof SQLObject) {
+ for (SQLObject child : ((SQLObject)
node).getChildrenWithoutPopulating()) {
+ setupTreeForNode(child);
+ }
+ } else {
+ for (SPObject child : node.getChildren()) {
+ setupTreeForNode(child);
+ }
}
}
@@ -513,7 +587,8 @@
if (!showPlayPenDatabase && parent instanceof SQLObjectRoot) {
SQLObjectRoot root = (SQLObjectRoot) parent;
List<? extends SQLObject> children = root.getChildren();
- for (int childIndex = 0, treeIndex = 0; childIndex <
children.size(); childIndex++) {
+ int treeIndex = 0;
+ for (int childIndex = 0; childIndex < children.size(); childIndex++)
{
SQLObject child = children.get(childIndex);
if (!(child instanceof SQLDatabase &&
@@ -524,6 +599,15 @@
treeIndex++;
}
}
+ if (index == treeIndex && getSnapshotContainer() != null) {
+ return getSnapshotContainer();
+ }
+ } else if (parent instanceof SQLObjectRoot &&
+ index == ((SQLObjectRoot) parent).getChildren().size())
{
+ return getSnapshotContainer();
+ } else if (parent == getSnapshotContainer()) {
+ SPObjectSnapshot<?> snapshot =
getSnapshotContainer().getChildren(SPObjectSnapshot.class).get(index);
+ return snapshot;
}
SQLObject sqlParent = (SQLObject) parent;
@@ -552,10 +636,23 @@
size--;
}
}
+ if (getSnapshotContainer() != null) {
+ size++;
+ }
+ return size;
+ } else if (parent instanceof SQLObjectRoot) {
+ SQLObjectRoot root = (SQLObjectRoot) parent;
+ int size = root.getChildren().size();
+ if (getSnapshotContainer() != null) {
+ size++;
+ }
+ return size;
+ } else if (parent == getSnapshotContainer()) {
+ int size = ((SPObject)
parent).getChildren(SPObjectSnapshot.class).size();
return size;
}
- SQLObject sqlParent = (SQLObject) parent;
+ SPObject sqlParent = (SPObject) parent;
try {
if (logger.isDebugEnabled())
logger.debug("returning "+sqlParent.getChildren().size()); //$NON-NLS-1$
return sqlParent.getChildren().size();
@@ -571,7 +668,7 @@
} else if (parent instanceof SQLColumn) {
return true;
}
- return !((SQLObject) parent).allowsChildren();
+ return !((SPObject) parent).allowsChildren();
}
public boolean isColumnsFolder(Object parent) {
@@ -593,7 +690,7 @@
return foldersInTables.get((SQLTable) parent).indexOf(child);
}
- int index = ((SQLObject)
parent).getChildren(spChild.getClass()).indexOf(child);
+ int index = ((SPObject)
parent).getChildren(spChild.getClass()).indexOf(child);
if (!showPlayPenDatabase && parent instanceof SQLObjectRoot) {
if (child instanceof SQLDatabase && ((SQLDatabase)
child).isPlayPenDatabase()) {
@@ -612,6 +709,9 @@
}
index -= playPenDatabaseCount;
}
+ if (child == getSnapshotContainer()) {
+ index++;
+ }
}
return index;
@@ -714,7 +814,7 @@
*
* @throws IllegalArgumentException if <code>node</code> is of class
SQLRelationship.
*/
- public SQLObject[] getPathToNode(SPObject node) {
+ public SPObject[] getPathToNode(SPObject node) {
List<SPObject> path = new LinkedList<SPObject>();
while (node != null && node != root) {
if (path.size() > 0 && node instanceof SQLTable) {
@@ -726,10 +826,14 @@
}
}
path.add(0, node);
- node = node.getParent();
+ if (node == getSnapshotContainer()) {
+ break;
+ } else {
+ node = node.getParent();
+ }
}
path.add(0, root);
- return (SQLObject[]) path.toArray(new SQLObject[path.size()]);
+ return (SPObject[]) path.toArray(new SPObject[path.size()]);
}
/**
@@ -740,8 +844,8 @@
* one path to the object. Otherwise the list will contain the path
* to the primary key then the path to the foreign key.
*/
- public List<SQLObject[]> getPathsToNode(SQLObject node) {
- List<SQLObject[]> nodePaths = new ArrayList<SQLObject[]>();
+ public List<SPObject[]> getPathsToNode(SQLObject node) {
+ List<SPObject[]> nodePaths = new ArrayList<SPObject[]>();
nodePaths.add(getPathToNode(node));
return nodePaths;
}
@@ -800,4 +904,8 @@
}
}
}
-}
+
+ public SPObject getSnapshotContainer() {
+ return snapshotContainer;
+ }
+}