Revision: 3788
Author: [email protected]
Date: Mon Jul 26 15:46:35 2010
Log: Added to the DBTreeModel so that it can be made optional to display
the playpen database, columns, relationships, imported keys, and indices.
This new functionality of the DBTreeModel is used in the newly added source
column chooser in ColumnEditPanel.
Refactored the SQLTypeTreePopupAction into the library as PopupJTreeAction
so that the ColumnEditPanel can use it for both the source column chooser
and the data type chooser.
The data type chooser now updates the data type button text properly if a
non-UserDefinedSQLType is selected in the JTree.
Fixed several NPE's with the column's auto increment being null.
Also, fixed some Eclipse warnings in the DBTree class.
http://code.google.com/p/power-architect/source/detail?r=3788
Deleted:
/trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreePopupAction.java
Modified:
/trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreePopupAction.java
Fri Jun 11 14:23:35 2010
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2010, SQL Power Group Inc.
- *
- * This file is part of Power*Architect.
- *
- * Power*Architect is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Power*Architect is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package ca.sqlpower.architect.swingui;
-
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.FocusAdapter;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JButton;
-import javax.swing.JPanel;
-import javax.swing.JTree;
-import javax.swing.Popup;
-import javax.swing.SwingUtilities;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.TreePath;
-
-import ca.sqlpower.sqlobject.UserDefinedSQLType;
-import ca.sqlpower.swingui.PopupListenerHandler;
-import ca.sqlpower.swingui.SPSUtils;
-
-/**
- * This {...@link Action} creates a {...@link Popup} for choosing domains and
data
- * types in the {...@link ColumnEditPanel}.
- */
-public class SQLTypeTreePopupAction extends AbstractAction {
-
- private final JPanel panel;
- private final JTree colType;
- private final JButton typeChooserButton;
- private PopupListenerHandler popupListenerHandler;
-
- private final TreeSelectionListener treeListener = new
TreeSelectionListener() {
- public void valueChanged(TreeSelectionEvent e) {
- TreePath path = e.getNewLeadSelectionPath();
- if (path != null) {
- Object node = path.getLastPathComponent();
- if (node instanceof UserDefinedSQLType) {
- popupCleanup();
- }
- }
- }
- };
-
- private final FocusListener focusListener = new FocusAdapter() {
- @Override
- public void focusLost(FocusEvent e) {
- popupCleanup();
- }
- };
-
- /**
- * Creates a new {...@link SQLTypeTreePopupAction} given the {...@link
JPanel} the
- * created {...@link Popup} should appear on, the {...@link JTree} the
- * {...@link Popup} should embed, and the {...@link JButton} that performs
this
- * action.
- *
- * @param panel
- * The {...@link JPanel} this {...@link Popup} should appear on.
- * @param colType
- * The {...@link JTree} the {...@link Popup} should embed.
- * @param typeChooserButton
- * The {...@link JButton} that should perform this action.
- */
- public SQLTypeTreePopupAction(JPanel panel, JTree colType, JButton
typeChooserButton) {
- super();
-
- this.panel = panel;
- this.colType = colType;
- this.typeChooserButton = typeChooserButton;
- }
-
- /**
- * Creates a {...@link Popup} if it is not visible, and connects the
- * appropriate listeners to check for when to hide the {...@link Popup}.
- * Otherwise, it hides the {...@link Popup} and disconnects the listeners.
- */
- public void actionPerformed(ActionEvent e) {
- if (popupListenerHandler != null &&
popupListenerHandler.isPopupVisible()) {
- popupCleanup();
- } else {
- Point windowLocation = new Point(0, 0);
- SwingUtilities.convertPointToScreen(windowLocation,
typeChooserButton);
- windowLocation.y += typeChooserButton.getHeight();
-
- // Popup the type choosing tree and attach the
- // popup listener handler to the tree
- popupListenerHandler =
- SPSUtils.popupComponent(panel, colType, windowLocation);
- popupConnect();
- }
- }
-
- private void popupConnect() {
- if (popupListenerHandler != null) {
- popupListenerHandler.connect();
- }
- if (colType != null) {
- colType.addTreeSelectionListener(treeListener);
- colType.addFocusListener(focusListener);
- }
- }
-
- private void popupCleanup() {
- if (popupListenerHandler != null &&
popupListenerHandler.isPopupVisible()) {
- popupListenerHandler.cleanup();
- }
- if (colType != null) {
- colType.removeTreeSelectionListener(treeListener);
- colType.removeFocusListener(focusListener);
- }
- }
-
-}
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Fri Jul 23 13:50:23 2010
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Mon Jul 26 15:46:35 2010
@@ -91,7 +91,7 @@
assertEquals(col3.isAutoIncrement(), ((YesNoEnum)
panel.getColAutoInc().getSelectedItem()).getValue());
assertEquals(col3.isPrimaryKey(),
panel.getColInPK().getModel().isSelected());
assertEquals(col3.getNullable() == DatabaseMetaData.columnNullable,
((YesNoEnum) panel.getColNullable().getSelectedItem()).getValue());
- assertEquals("None Specified",panel.getSourceLabel().getText());
+ assertEquals("None
Specified",panel.getSourceColumnButton().getText());
col2.getUserDefinedSQLType().setUpstreamType(session.getSQLTypes().get(1));
panel = new ColumnEditPanel(col2, session);
@@ -103,7 +103,7 @@
assertEquals(col2.isAutoIncrement(), ((YesNoEnum)
panel.getColAutoInc().getSelectedItem()).getValue());
assertEquals(col2.isPrimaryKey(),
panel.getColInPK().getModel().isSelected());
assertEquals(col2.getNullable() ==
DatabaseMetaData.columnNullable, ((YesNoEnum)
panel.getColNullable().getSelectedItem()).getValue());
- assertEquals("None Specified",panel.getSourceLabel().getText());
+ assertEquals("None
Specified",panel.getSourceColumnButton().getText());
}
public void testApplyChanges() {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Fri Jul 23 15:32:49 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Mon Jul 26 15:46:35 2010
@@ -69,6 +69,8 @@
import ca.sqlpower.architect.ddl.DDLUtils;
import ca.sqlpower.architect.enterprise.DomainCategory;
import ca.sqlpower.architect.enterprise.DomainCategorySnapshot;
+import ca.sqlpower.architect.swingui.dbtree.DBTreeCellRenderer;
+import ca.sqlpower.architect.swingui.dbtree.DBTreeModel;
import ca.sqlpower.object.AbstractPoolingSPListener;
import ca.sqlpower.object.ObjectDependentException;
import ca.sqlpower.object.SPChildEvent;
@@ -78,11 +80,12 @@
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectUtils;
import ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider;
+import
ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
import ca.sqlpower.sqlobject.UserDefinedSQLType;
import ca.sqlpower.sqlobject.UserDefinedSQLTypeSnapshot;
-import
ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
import ca.sqlpower.swingui.ChangeListeningDataEntryPanel;
import ca.sqlpower.swingui.DataEntryPanelChangeUtil;
+import ca.sqlpower.swingui.PopupJTreeAction;
import ca.sqlpower.swingui.SPSUtils;
import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.TransactionEvent;
@@ -165,7 +168,9 @@
* Label that shows where the column was reverse engineered from, or
* where its data comes from when building an ETL mapping.
*/
- private final JLabel sourceLabel;
+ private final JButton colSourceButton;
+
+ private final JTree colSourceTree;
private final JTextField colLogicalName;
@@ -254,8 +259,27 @@
layout.appendRow(RowSpec.decode("p"));
panel.add(makeTitle(Messages.getString("ColumnEditPanel.source")),
cc.xyw(2, row++, width)); //$NON-NLS-1$
layout.appendRow(RowSpec.decode("p"));
- panel.add(sourceLabel = new JLabel(), cc.xyw(2, row++, width));
-
+
+ cb = new JCheckBox();
+ if (cols.size() > 1) {
+ panel.add(cb, cc.xy(1, row));
+ }
+
+ colSourceTree = new JTree();
+ DBTreeModel sourceTreeModel = new
DBTreeModel(session.getRootObject(), colSourceTree, false, true, false,
false, false);
+ colSourceTree.setModel(sourceTreeModel);
+ colSourceTree.setRootVisible(false);
+ colSourceTree.setShowsRootHandles(true);
+ colSourceTree.setCellRenderer(new DBTreeCellRenderer());
+ colSourceTree.getSelectionModel().setSelectionMode(
+ TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+ colSourceButton = new JButton();
+ colSourceButton.setAction(new PopupJTreeAction(panel,
colSourceTree, colSourceButton, SQLColumn.class));
+
+ panel.add(colSourceButton, cc.xyw(2, row++, 2));
+ componentEnabledMap.put(colSourceTree, cb);
+
layout.appendRow(RowSpec.decode("5dlu"));
row++;
@@ -350,10 +374,12 @@
colType.expandRow(i);
}
colType.setRootVisible(true);
+ colType.setShowsRootHandles(true);
colType.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
- typeChooserButton.addActionListener(new
SQLTypeTreePopupAction(panel, colType, typeChooserButton));
+ typeChooserButton.setAction(
+ new PopupJTreeAction(panel, colType, typeChooserButton,
UserDefinedSQLType.class));
componentEnabledMap.put(colType, cb);
panel.add(typeChooserButton, cc.xyw(2, row++, 2));
@@ -609,13 +635,38 @@
SQLPowerUtils.listenToHierarchy(session.getRootObject(), this);
panel.addAncestorListener(cleanupListener);
+ colSourceTree.addTreeSelectionListener(new TreeSelectionListener()
{
+ @Override
+ public void valueChanged(TreeSelectionEvent e) {
+ TreePath path = e.getNewLeadSelectionPath();
+ if (path != null) {
+ Object selection = path.getLastPathComponent();
+ if (selection instanceof SQLColumn) {
+ SQLColumn sourceColumn = (SQLColumn) selection;
+ colSourceButton.setText(DDLUtils.toQualifiedName(
+ sourceColumn.getParent()) + "." +
sourceColumn.getName());
+ } else {
+
colSourceButton.setText(Messages.getString("ColumnEditPanel.noneSpecified"));
+ }
+ } else {
+
colSourceButton.setText(Messages.getString("ColumnEditPanel.noneSpecified"));
+ }
+ }
+ });
+
colType.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getNewLeadSelectionPath();
- Object selection = path.getLastPathComponent();
- if (selection instanceof UserDefinedSQLType) {
- typeChooserButton.setText(((UserDefinedSQLType)
selection).getName());
- updateSQLTypeComponents((UserDefinedSQLType)
selection, false);
+ if (path != null) {
+ Object selection = path.getLastPathComponent();
+ if (selection instanceof UserDefinedSQLType) {
+ typeChooserButton.setText(((UserDefinedSQLType)
selection).getName());
+ updateSQLTypeComponents((UserDefinedSQLType)
selection, false);
+ } else {
+
typeChooserButton.setText(Messages.getString("ColumnEditPanel.chooseType"));
+ }
+ } else {
+
typeChooserButton.setText(Messages.getString("ColumnEditPanel.chooseType"));
}
}
});
@@ -654,17 +705,27 @@
private void updateComponents(SQLColumn col) throws SQLObjectException
{
SQLColumn sourceColumn = col.getSourceColumn();
if (sourceColumn == null) {
-
sourceLabel.setText(Messages.getString("ColumnEditPanel.noneSpecified"));
//$NON-NLS-1$
+
colSourceButton.setText(Messages.getString("ColumnEditPanel.noneSpecified"));
//$NON-NLS-1$
} else {
-
- sourceLabel.setText(
+ updateComponent(colSourceTree, sourceColumn);
+
+ DBTreeModel model = (DBTreeModel) colSourceTree.getModel();
+ colSourceTree.setSelectionPath(new
TreePath(model.getPathToNode(sourceColumn)));
+ colSourceButton.setText(
DDLUtils.toQualifiedName(
sourceColumn.getParent()) + "." +
sourceColumn.getName());
}
updateComponent(colLogicalName, col.getName());
updateComponent(colPhysicalName, col.getPhysicalName());
+
updateComponent(colType,
col.getUserDefinedSQLType().getUpstreamType());
+ if (!colType.isSelectionEmpty()) {
+ typeChooserButton.setText(
+ ((UserDefinedSQLType)
col.getUserDefinedSQLType().getUpstreamType()).getName());
+ } else {
+
colSourceButton.setText(Messages.getString("ColumnEditPanel.noneSpecified"));
+ }
updateSQLTypeComponents(col.getUserDefinedSQLType(), true);
@@ -696,10 +757,9 @@
if (componentEnabledMap.get(comp).isSelected() &&
(comp.isSelectionEmpty() ||
comp.getLastSelectedPathComponent() == expectedValue)) {
for (int i = 0; i < comp.getRowCount(); i++) {
- if (comp.getPathForRow(i).getLastPathComponent() ==
expectedValue) {
+ Object lastPathComponent =
comp.getPathForRow(i).getLastPathComponent();
+ if (lastPathComponent == expectedValue) {
comp.setSelectionRow(i);
- typeChooserButton.setText(
- ((UserDefinedSQLType)
expectedValue).getName());
}
}
} else {
@@ -801,7 +861,8 @@
colNullable.setEnabled(false);
}
- if (((YesNoEnum) colAutoInc.getSelectedItem()).getValue() ||
+ if (colAutoInc.getSelectedIndex() == -1 ||
+ ((YesNoEnum) colAutoInc.getSelectedItem()).getValue() ||
!typeOverrideMap.get(colDefaultValue).isSelected()) {
colDefaultValue.setText(""); //$NON-NLS-1$
colDefaultValue.setEnabled(false);
@@ -809,7 +870,11 @@
colDefaultValue.setEnabled(true);
}
- colAutoIncSequenceName.setEnabled(((YesNoEnum)
colAutoInc.getSelectedItem()).getValue());
+ if (colAutoInc.getSelectedIndex() != -1) {
+ colAutoIncSequenceName.setEnabled(((YesNoEnum)
colAutoInc.getSelectedItem()).getValue());
+ } else {
+ colAutoIncSequenceName.setEnabled(false);
+ }
}
/**
@@ -822,7 +887,7 @@
logger.debug("Updating model"); //$NON-NLS-1$
List<String> errors = new ArrayList<String>();
if (componentEnabledMap.get(colType).isSelected() &&
- colType.getLastSelectedPathComponent() == null) {
+ !(colType.getLastSelectedPathComponent() instanceof
UserDefinedSQLType)) {
errors.add(Messages.getString("ColumnEditPanel.missingType"));
return errors;
}
@@ -832,6 +897,15 @@
compoundEditRoot.begin(Messages.getString("ColumnEditPanel.compoundEditName"));
//$NON-NLS-1$
for (SQLColumn column : columns) {
+ if (componentEnabledMap.get(colSourceTree).isSelected()) {
+ Object selection =
colSourceTree.getLastSelectedPathComponent();
+ if (selection instanceof SQLColumn) {
+ column.setSourceColumn((SQLColumn) selection);
+ } else {
+ column.setSourceColumn(null);
+ }
+ }
+
if (componentEnabledMap.get(colPhysicalName).isSelected())
{
column.setPhysicalName(colPhysicalName.getText());
}
@@ -851,7 +925,7 @@
(upstreamType.getParent() instanceof
DomainCategory &&
upstreamType.getParent().getParent().equals(session.getWorkspace())))) //
not an already existing domain snapshot
{
- int systemRevision =
session.getEnterpriseSession().getSystemSession().getCurrentRevisionNumber();;
+ int systemRevision =
session.getEnterpriseSession().getSystemSession().getCurrentRevisionNumber();
boolean isDomainSnapshot =
upstreamType.getParent() instanceof DomainCategory;
UserDefinedSQLTypeSnapshot snapshot;
if (upstreamType.getUpstreamType() != null) {
@@ -1040,8 +1114,8 @@
}
/** Only for testing. Normal client code should not need to call this.
*/
- public JLabel getSourceLabel() {
- return sourceLabel;
+ public JButton getSourceColumnButton() {
+ return colSourceButton;
}
public boolean hasUnsavedChanges() {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Tue Jul
13 10:58:50 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Mon Jul
26 15:46:35 2010
@@ -34,7 +34,6 @@
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -166,7 +165,7 @@
getTreeCellRenderer().addIconFilter(new ProfiledTableIconFilter());
setCellRenderer(getTreeCellRenderer());
selectAllChildTablesAction = new SelectAllChildTablesAction();
- addMouseListener(new MouseListener() {
+ addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (getPathForLocation(e.getX(), e.getY()) != null) {
Object node = getPathForLocation(e.getX(),
e.getY()).getLastPathComponent();
@@ -179,18 +178,6 @@
}
}
}
- public void mousePressed(MouseEvent e) {
- //no-op
- }
- public void mouseExited(MouseEvent e) {
- //no-op
- }
- public void mouseEntered(MouseEvent e) {
- //no-op
- }
- public void mouseClicked(MouseEvent e) {
- //no-op
- }
});
getActionMap().put("copy", new AbstractAction() {
@@ -211,12 +198,12 @@
/**
* Returns a list of all the databases in this DBTree's model.
*/
- public List getDatabaseList() {
- ArrayList databases = new ArrayList();
+ public List<SQLDatabase> getDatabaseList() {
+ List<SQLDatabase> databases = new ArrayList<SQLDatabase>();
TreeModel m = getModel();
int dbCount = m.getChildCount(m.getRoot());
for (int i = 0; i < dbCount; i++) {
- databases.add(m.getChild(m.getRoot(), i));
+ databases.add((SQLDatabase) m.getChild(m.getRoot(), i));
}
return databases;
}
@@ -266,12 +253,12 @@
* User Settings. If we find one, return a handle to it. If we don't
find
* one, return null.
*/
- public SPDataSource getDuplicateDbcs(SPDataSource spec) {
- SPDataSource dup = null;
+ public JDBCDataSource getDuplicateDbcs(SPDataSource spec) {
+ JDBCDataSource dup = null;
boolean found = false;
- Iterator it = session.getContext().getConnections().iterator();
+ Iterator<JDBCDataSource> it =
session.getContext().getConnections().iterator();
while (it.hasNext() && found == false) {
- SPDataSource dbcs = (SPDataSource) it.next();
+ JDBCDataSource dbcs = (JDBCDataSource) it.next();
if (spec.equals(dbcs)) {
dup = dbcs;
found = true;
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
Thu Jul 22 09:38:47 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java
Mon Jul 26 15:46:35 2010
@@ -46,13 +46,14 @@
import ca.sqlpower.object.SPListener;
import ca.sqlpower.object.SPObject;
import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLIndex;
import ca.sqlpower.sqlobject.SQLObject;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
import ca.sqlpower.sqlobject.SQLRelationship;
-import ca.sqlpower.sqlobject.SQLTable;
import ca.sqlpower.sqlobject.SQLRelationship.SQLImportedKey;
+import ca.sqlpower.sqlobject.SQLTable;
import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.TransactionEvent;
@@ -184,6 +185,11 @@
public void childAdded(SPChildEvent e) {
if
(!SQLPowerUtils.getAncestorList(e.getSource()).contains(root)
&& !e.getSource().equals(root)) return;
+ if (!showColumns && e.getChild() instanceof SQLColumn) return;
+ if (!showRelationships && e.getChild() instanceof
SQLRelationship) return;
+ if (!showImportedKeys && e.getChild() instanceof
SQLImportedKey) return;
+ if (!showIndices && e.getChild() instanceof SQLIndex) return;
+ if (!showPlayPenDatabase &&
SQLPowerUtils.getAncestor(e.getSource(),
SQLDatabase.class).isPlayPenDatabase()) return;
if (!root.getRunnableDispatcher().isForegroundThread())
throw new IllegalStateException("Adding a child " +
e.getChild() + " to " + e.getSource() +
@@ -221,6 +227,11 @@
public void childRemoved(SPChildEvent e) {
if
(!SQLPowerUtils.getAncestorList(e.getSource()).contains(root)
&& !e.getSource().equals(root)) return;
+ if (!showColumns && e.getChild() instanceof SQLColumn) return;
+ if (!showRelationships && e.getChild() instanceof
SQLRelationship) return;
+ if (!showImportedKeys && e.getChild() instanceof
SQLImportedKey) return;
+ if (!showIndices && e.getChild() instanceof SQLIndex) return;
+ if (!showPlayPenDatabase &&
SQLPowerUtils.getAncestor(e.getSource(),
SQLDatabase.class).isPlayPenDatabase()) return;
if (!root.getRunnableDispatcher().isForegroundThread())
throw new IllegalStateException("Removing a child " +
e.getChild() + " to " + e.getSource() +
@@ -262,7 +273,11 @@
public void propertyChanged(PropertyChangeEvent e) {
if (!SQLPowerUtils.getAncestorList(((SPObject)
e.getSource())).contains(root) && !e.getSource().equals(root)) return;
-
+ if (!showColumns && e.getSource() instanceof SQLColumn) return;
+ if (!showRelationships && e.getSource() instanceof
SQLRelationship) return;
+ if (!showImportedKeys && e.getSource() instanceof
SQLImportedKey) return;
+ if (!showIndices && e.getSource() instanceof SQLIndex) return;
+ if (!showPlayPenDatabase && e.getSource() instanceof
SQLDatabase && ((SQLDatabase) e.getSource()).isPlayPenDatabase()) return;
if (!root.getRunnableDispatcher().isForegroundThread())
throw new IllegalStateException("Changing the property" +
e.getPropertyName() + " on " + e.getSource() +
@@ -359,27 +374,82 @@
}
}
};
-
- /**
- * Creates a tree model with all of the SQLDatabase objects in the
- * given session's root object in its root list of databases.
- *
- * @param root A SQLObject that contains all the databases you
- * want in the tree. This does not necessarily have to be the
- * root object associated with the given session, but it normally
- * will be.
- */
+
+ /**
+ * Determinant of whether the playpen database should be shown.
+ */
+ private final boolean showPlayPenDatabase;
+
+ /**
+ * Determinant of whether the column folder should be shown.
+ */
+ private final boolean showColumns;
+
+ /**
+ * Determinant of whether the relationship folder should be shown.
+ */
+ private final boolean showRelationships;
+
+ /**
+ * Determinant of whether the imported keys folder should be shown.
+ */
+ private final boolean showImportedKeys;
+
+ /**
+ * Determinant of whether the indices folder should be shown.
+ */
+ private final boolean showIndices;
+
+ /**
+ * 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
+ * column, relationship, imported keys, and indices folders.
+ *
+ * @param root
+ * A SQLObject that contains all the databases you want in
the
+ * tree. This does not necessarily have to be the root
object
+ * associated with the given session, but it normally will
be.
+ */
public DBTreeModel(SQLObjectRoot root, JTree tree) {
- this.root = root;
- this.treeModelListeners = new LinkedList<TreeModelListener>();
- tree.addTreeWillExpandListener(treeWillExpandListener);
- SQLPowerUtils.listenToHierarchy(root, treeListener);
-
- for (SPObject ancestor : SQLPowerUtils.getAncestorList(root)) {
- ancestor.addSPListener(treeListener);
- }
-
- setupTreeForNode(root);
+ 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 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, boolean
showPlayPenDatabase, boolean showColumns, boolean showRelationships,
boolean showImportedKeys, boolean showIndices) {
+ this.root = root;
+ this.showPlayPenDatabase = showPlayPenDatabase;
+ this.showColumns = showColumns;
+ this.showRelationships = showRelationships;
+ this.showImportedKeys = showImportedKeys;
+ this.showIndices = showIndices;
+ this.treeModelListeners = new LinkedList<TreeModelListener>();
+ tree.addTreeWillExpandListener(treeWillExpandListener);
+ SQLPowerUtils.listenToHierarchy(root, treeListener);
+
+ for (SPObject ancestor : SQLPowerUtils.getAncestorList(root)) {
+ ancestor.addSPListener(treeListener);
+ }
+
+ setupTreeForNode(root);
}
/**
@@ -408,6 +478,25 @@
} else if (parent instanceof SQLTable) {
return foldersInTables.get((SQLTable) parent).get(index);
}
+
+ // If the playpen database is hidden, adjust the index
accordingly.
+ // The index passed into this method is in terms of a
non-PP-database
+ // tree.
+ 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++) {
+ SQLObject child = children.get(childIndex);
+
+ if (!(child instanceof SQLDatabase &&
+ ((SQLDatabase) child).isPlayPenDatabase())) {
+ if (treeIndex == index) {
+ return child;
+ }
+ treeIndex++;
+ }
+ }
+ }
SQLObject sqlParent = (SQLObject) parent;
try {
@@ -427,6 +516,15 @@
return foldersInTables.get((SQLTable) parent).size();
} else if (parent instanceof SQLColumn) {
return 0;
+ } else if (!showPlayPenDatabase && parent instanceof
SQLObjectRoot) {
+ SQLObjectRoot root = (SQLObjectRoot) parent;
+ int size = root.getChildren().size();
+ for (SQLDatabase db : ((SQLObjectRoot)
parent).getChildren(SQLDatabase.class)) {
+ if (db.isPlayPenDatabase()) {
+ size--;
+ }
+ }
+ return size;
}
SQLObject sqlParent = (SQLObject) parent;
@@ -467,7 +565,28 @@
return foldersInTables.get((SQLTable) parent).indexOf(child);
}
- return ((SQLObject)
parent).getChildren(spChild.getClass()).indexOf(child);
+ int index = ((SQLObject)
parent).getChildren(spChild.getClass()).indexOf(child);
+
+ if (!showPlayPenDatabase && parent instanceof SQLObjectRoot) {
+ if (child instanceof SQLDatabase && ((SQLDatabase)
child).isPlayPenDatabase()) {
+ index = -1;
+ } else {
+ SQLObjectRoot root = (SQLObjectRoot) parent;
+ List<? extends SQLObject> children = root.getChildren();
+ int playPenDatabaseCount = 0;
+ for (int i = 0; i < index; i++) {
+ SQLObject childOfRoot = children.get(i);
+
+ if (childOfRoot instanceof SQLDatabase &&
+ ((SQLDatabase)
childOfRoot).isPlayPenDatabase()) {
+ playPenDatabaseCount++;
+ }
+ }
+ index -= playPenDatabaseCount;
+ }
+ }
+
+ return index;
}
// -------------- treeModel event source support -----------------
@@ -619,30 +738,38 @@
if (foldersInTables.get(table) == null) {
List<FolderNode> folderList = new ArrayList<FolderNode>();
foldersInTables.put(table, folderList);
- FolderNode SQLColumnFolder = new FolderNode(table,
SQLColumn.class, new Callable<Boolean>() {
- public Boolean call() throws Exception {
- return table.isColumnsPopulated();
- }
- });
- folderList.add(SQLColumnFolder);
- FolderNode SQLRelationshipFolder = new FolderNode(table,
SQLRelationship.class, new Callable<Boolean>() {
- public Boolean call() throws Exception {
- return table.isExportedKeysPopulated();
- }
- });
- folderList.add(SQLRelationshipFolder);
- FolderNode SQLImportedKeys = new FolderNode(table,
SQLImportedKey.class, new Callable<Boolean>() {
- public Boolean call() throws Exception {
- return table.isImportedKeysPopulated();
- }
- });
- folderList.add(SQLImportedKeys);
- FolderNode SQLIndexFolder = new FolderNode(table,
SQLIndex.class, new Callable<Boolean>() {
- public Boolean call() throws Exception {
- return table.isIndicesPopulated();
- }
- });
- folderList.add(SQLIndexFolder);
+ if (showColumns) {
+ FolderNode SQLColumnFolder = new FolderNode(table,
SQLColumn.class, new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return table.isColumnsPopulated();
+ }
+ });
+ folderList.add(SQLColumnFolder);
+ }
+ if (showRelationships) {
+ FolderNode SQLRelationshipFolder = new FolderNode(table,
SQLRelationship.class, new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return table.isExportedKeysPopulated();
+ }
+ });
+ folderList.add(SQLRelationshipFolder);
+ }
+ if (showImportedKeys) {
+ FolderNode SQLImportedKeys = new FolderNode(table,
SQLImportedKey.class, new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return table.isImportedKeysPopulated();
+ }
+ });
+ folderList.add(SQLImportedKeys);
+ }
+ if (showIndices) {
+ FolderNode SQLIndexFolder = new FolderNode(table,
SQLIndex.class, new Callable<Boolean>() {
+ public Boolean call() throws Exception {
+ return table.isIndicesPopulated();
+ }
+ });
+ folderList.add(SQLIndexFolder);
+ }
}
}
}