Revision: 3807
Author: [email protected]
Date: Thu Jul 29 11:37:29 2010
Log: To listen to the upstream SQLTypes in the session a listener is being
attached to the target database and its children for upstream type changes.
When an upstream type of a column's proxy is detected the new hierarchy
listener will attach a listener to the system type that updates the
snapshot.
There is more to complete such as cleaning up the listener on the system
type.
http://code.google.com/p/power-architect/source/detail?r=3807
Added:
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java
Thu Jul 29 11:37:29 2010
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Library.
+ *
+ * SQL Power Library 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.
+ *
+ * SQL Power Library 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;
+
+import java.beans.PropertyChangeEvent;
+
+import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
+import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.object.AbstractSPListener;
+import ca.sqlpower.object.SPChildEvent;
+import ca.sqlpower.object.SPObjectSnapshot;
+import ca.sqlpower.sqlobject.SPObjectSnapshotUpdateListener;
+import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
+
+/**
+ * Add this listener to a SQLDatabase to have its columns have correct
snapshot listeners
+ * attached to system types.
+ */
+public class SPObjectSnapshotHierarchyListener extends AbstractSPListener {
+
+ /**
+ * This project holds all of the snapshots of the {...@link
UserDefinedSQLType}
+ * objects.
+ */
+ private final ArchitectClientSideSession session;
+
+ public SPObjectSnapshotHierarchyListener(ArchitectClientSideSession
session) {
+ this.session = session;
+ }
+
+ @Override
+ public void childAdded(SPChildEvent e) {
+ if (e.getChild() instanceof SQLTable) {
+ e.getChild().addSPListener(this);
+ } else if (e.getChild() instanceof SQLColumn) {
+ SQLColumn sqlColumn = (SQLColumn) e.getChild();
+ sqlColumn.getUserDefinedSQLType().addSPListener(this);
+ if (sqlColumn.getUserDefinedSQLType() != null) {
+ addUpdateListener(sqlColumn.getUserDefinedSQLType());
+ }
+ }
+ }
+
+ @Override
+ public void childRemoved(SPChildEvent e) {
+ if (e.getChild() instanceof SQLTable) {
+ e.getChild().removeSPListener(this);
+ for (SQLColumn col :
e.getChild().getChildren(SQLColumn.class)) {
+
col.getUserDefinedSQLType().removeSPListener(this);
+ }
+ } else if (e.getChild() instanceof SQLColumn) {
+ ((SQLColumn)
e.getChild()).getUserDefinedSQLType().removeSPListener(this);
+ }
+ }
+
+ @Override
+ public void propertyChanged(PropertyChangeEvent e) {
+ if (e.getSource() instanceof UserDefinedSQLType
+ && e.getPropertyName().equals("upstreamType")) {
+ //XXX Need to remove the old listener
+ UserDefinedSQLType columnProxyType =
(UserDefinedSQLType) e.getSource();
+ addUpdateListener(columnProxyType);
+ }
+ }
+
+ private void addUpdateListener(UserDefinedSQLType columnProxyType) {
+ UserDefinedSQLType upstreamSnapshotType =
columnProxyType.getUpstreamType();
+ for (SPObjectSnapshot<?> snapshot :
session.getWorkspace().getSqlTypeSnapshots()) {
+ if (snapshot.getSPObject() == upstreamSnapshotType) {
+ for (UserDefinedSQLType systemType :
session.getSystemWorkspace().getSqlTypes()) {
+ if
(systemType.getUUID().equals(snapshot.getOriginalUUID())) {
+ systemType.addSPListener(new
SPObjectSnapshotUpdateListener(snapshot));
+ break;
+ }
+ }
+ for (DomainCategory category :
session.getSystemWorkspace().getDomainCategories()) {
+ boolean typeFound = false;
+ for (UserDefinedSQLType systemType :
category.getChildren(UserDefinedSQLType.class)) {
+ if
(systemType.getUUID().equals(upstreamSnapshotType.getUUID())) {
+ systemType.addSPListener(new
SPObjectSnapshotUpdateListener(snapshot));
+ typeFound = true;
+ break;
+ }
+ }
+ if (typeFound) break;
+ }
+ break;
+ }
+ }
+ }
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Wed Jul 28 09:52:56 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Thu Jul 29 11:37:29 2010
@@ -54,6 +54,7 @@
import ca.sqlpower.architect.ArchitectSession;
import ca.sqlpower.architect.ArchitectSessionContext;
import ca.sqlpower.architect.ArchitectSessionImpl;
+import ca.sqlpower.architect.SPObjectSnapshotHierarchyListener;
import ca.sqlpower.architect.ddl.DDLGenerator;
import ca.sqlpower.architect.swingui.ArchitectSwingProject;
import ca.sqlpower.architect.swingui.ArchitectSwingSessionContext;
@@ -150,6 +151,8 @@
String name, ProjectLocation projectLocation) throws SQLObjectException
{
super(context, name, new ArchitectSwingProject());
+ getTargetDatabase().addSPListener(new
SPObjectSnapshotHierarchyListener(this));
+
this.projectLocation = projectLocation;
this.isEnterpriseSession = true;
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Thu Jul 29 08:30:29 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Thu Jul 29 11:37:29 2010
@@ -77,15 +77,14 @@
import ca.sqlpower.object.ObjectDependentException;
import ca.sqlpower.object.SPChildEvent;
import ca.sqlpower.object.SPListener;
-import ca.sqlpower.sqlobject.SPObjectSnapshotUpdateListener;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLObject;
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;
@@ -998,6 +997,7 @@
boolean isDomainSnapshot =
upstreamType.getParent() instanceof DomainCategory;
UserDefinedSQLTypeSnapshot snapshot;
if (upstreamType.getUpstreamType() != null) {
+ //For domains
UserDefinedSQLType upUpStreamType =
upstreamType.getUpstreamType();
UserDefinedSQLTypeSnapshot upstreamSnapshot =
new UserDefinedSQLTypeSnapshot(upUpStreamType, systemRevision,
isDomainSnapshot);
session.getWorkspace().addChild(upstreamSnapshot, 0);
@@ -1006,8 +1006,6 @@
} else {
snapshot = new
UserDefinedSQLTypeSnapshot(upstreamType, systemRevision, isDomainSnapshot);
}
- SPObjectSnapshotUpdateListener updateListener =
new SPObjectSnapshotUpdateListener(snapshot);
- upstreamType.addSPListener(updateListener);
session.getWorkspace().addChild(snapshot, 0);
column.getUserDefinedSQLType().setUpstreamType(snapshot.getSPObject());
if ((upstreamType.getParent() instanceof
DomainCategory)) {