Revision: 3248
Author: silva.josemanuel1
Date: Tue Jan 26 10:49:55 2010
Log: Implemented property change support and life cycle listening in the
ArchitectSession.
NEW - bug 2445: Create a server side session
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2445
http://code.google.com/p/power-architect/source/detail?r=3248
Modified:
/trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
/trunk/src/ca/sqlpower/architect/ArchitectSession.java
/trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
/trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
/trunk/src/ca/sqlpower/architect/swingui/olap/OLAPEditSession.java
=======================================
--- /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Mon
Jan 18 09:19:18 2010
+++ /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Tue
Jan 26 10:49:55 2010
@@ -32,6 +32,7 @@
package ca.sqlpower.architect;
+import java.beans.PropertyChangeListener;
import java.util.List;
import ca.sqlpower.architect.ddl.DDLGenerator;
@@ -43,6 +44,7 @@
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
+import ca.sqlpower.swingui.event.SessionLifecycleListener;
import ca.sqlpower.util.DefaultUserPrompterFactory;
import ca.sqlpower.util.UserPrompter;
import ca.sqlpower.util.UserPrompter.UserPromptOptions;
@@ -162,5 +164,30 @@
// TODO Auto-generated method stub
}
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession> l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean close() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
l) {
+ // TODO Auto-generated method stub
+
+ }
}
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon Jan 18 09:19:18 2010
+++
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Tue Jan 26 10:49:55 2010
@@ -20,6 +20,7 @@
import java.awt.Color;
import java.awt.Window;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collections;
@@ -161,7 +162,8 @@
userSettings = argUserSettings;
}
- public void close() {
+ public boolean close() {
+ return true;
}
public CompareDMSettings getCompareDMSettings() {
@@ -340,11 +342,11 @@
return null;
}
- public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener) {
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
listener) {
// do-nothing stub
}
- public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener) {
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
listener) {
// do-nothing stub
}
@@ -414,4 +416,14 @@
// TODO Auto-generated method stub
}
-}
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ // TODO Auto-generated method stub
+
+ }
+}
=======================================
--- /trunk/src/ca/sqlpower/architect/ArchitectSession.java Mon Jan 18
09:19:18 2010
+++ /trunk/src/ca/sqlpower/architect/ArchitectSession.java Tue Jan 26
10:49:55 2010
@@ -18,6 +18,7 @@
*/
package ca.sqlpower.architect;
+import java.beans.PropertyChangeListener;
import java.util.List;
import ca.sqlpower.architect.ddl.DDLGenerator;
@@ -26,6 +27,7 @@
import ca.sqlpower.sqlobject.SQLDatabaseMapping;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
+import ca.sqlpower.swingui.event.SessionLifecycleListener;
import ca.sqlpower.util.SPSession;
import ca.sqlpower.util.UserPrompterFactory;
@@ -105,4 +107,24 @@
*/
public SQLObjectRoot getRootObject();
-}
+ void addPropertyChangeListener(PropertyChangeListener l);
+
+ void removePropertyChangeListener(PropertyChangeListener l);
+
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession> l);
+
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
l);
+
+ /**
+ * Ends this session, disposing its frame and releasing any system
+ * resources that were obtained explicitly by this session. Also
+ * fires a sessionClosing lifecycle event, so any resources used up
+ * by subsystems dependent on this session can be freed by the
appropriate
+ * parties.
+ *
+ * @return True if the session was successfully closed. False if the
+ * session did not close due to an error or user intervention.
+ */
+ public boolean close();
+
+}
=======================================
--- /trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java Mon Jan 18
09:19:18 2010
+++ /trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java Tue Jan 26
10:49:55 2010
@@ -19,17 +19,24 @@
package ca.sqlpower.architect;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
import java.util.List;
import ca.sqlpower.architect.ddl.DDLGenerator;
import ca.sqlpower.architect.profile.ProfileManagerImpl;
+import ca.sqlpower.object.CleanupExceptions;
import ca.sqlpower.sql.DataSourceCollection;
import ca.sqlpower.sql.JDBCDataSource;
import ca.sqlpower.sql.SPDataSource;
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
+import ca.sqlpower.swingui.event.SessionLifecycleEvent;
+import ca.sqlpower.swingui.event.SessionLifecycleListener;
import ca.sqlpower.util.DefaultUserPrompterFactory;
+import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.UserPrompter;
import ca.sqlpower.util.UserPrompterFactory;
import ca.sqlpower.util.UserPrompter.UserPromptOptions;
@@ -50,6 +57,11 @@
private final ArchitectProject project;
private String name;
+ private final PropertyChangeSupport pcs = new
PropertyChangeSupport(this);
+
+ private final List<SessionLifecycleListener<ArchitectSession>>
lifecycleListeners =
+ new ArrayList<SessionLifecycleListener<ArchitectSession>>();
+
/**
* The factory that creates user prompters for this session. Defaults
to a
* factory that makes an "always OK" user prompter for
headless/embedded use.
@@ -183,6 +195,35 @@
public void runInForeground(Runnable runner) {
runner.run();
}
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ pcs.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ pcs.addPropertyChangeListener(l);
+ }
+
+ public boolean close() {
+ CleanupExceptions cleanupObject =
SQLPowerUtils.cleanupSPObject(project);
+ SQLPowerUtils.displayCleanupErrors(cleanupObject,
userPrompterFactory);
+
+ SessionLifecycleEvent<ArchitectSession> lifecycleEvent =
+ new SessionLifecycleEvent<ArchitectSession>(this);
+ for (int i = lifecycleListeners.size() - 1; i >= 0; i--) {
+ lifecycleListeners.get(i).sessionClosing(lifecycleEvent);
+ }
+
+ return true;
+ }
+
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession> l) {
+ lifecycleListeners.add(l);
+ }
+
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
l) {
+ lifecycleListeners.remove(l);
+ }
}
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Fri
Jan 15 15:02:04 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Tue
Jan 26 10:49:55 2010
@@ -94,13 +94,6 @@
*/
public JDialog getProfileDialog();
- /**
- * This is a common handler for all actions that must
- * occur when switching projects, e.g., dispose dialogs,
- * shut down running threads, etc.
- */
- public void close();
-
/**
* See {...@link #userSettings}.
*
@@ -299,14 +292,14 @@
* notified when this session is about to close. Being a lifecycle
listener
* is an excellent way to make a session shutdown hook for your
subsystem.
*/
- public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener);
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
listener);
/**
* Removes the given listener from the lifecycle event list. Once
removed,
* the listener will not receive a sessionClosing notification when
this
* session closes.
*/
- public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener);
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
listener);
/**
* Creates a new JMenu containing one item per data source in this
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Fri Jan 15 15:02:04 2010
+++
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Tue Jan 26 10:49:55 2010
@@ -302,9 +302,9 @@
* Removes the closed session from the list, and terminates the VM
* if there are no more sessions.
*/
- private SessionLifecycleListener<ArchitectSwingSession>
sessionLifecycleListener =
- new SessionLifecycleListener<ArchitectSwingSession>() {
- public void
sessionClosing(SessionLifecycleEvent<ArchitectSwingSession> e) {
+ private SessionLifecycleListener<ArchitectSession>
sessionLifecycleListener =
+ new SessionLifecycleListener<ArchitectSession>() {
+ public void sessionClosing(SessionLifecycleEvent<ArchitectSession>
e) {
getSessions().remove(e.getSource());
if (getSessions().isEmpty() && exitAfterAllSessionsClosed) {
System.exit(0);
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Mon Jan 25 09:01:33 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Tue Jan 26 10:49:55 2010
@@ -144,7 +144,7 @@
private KettleJob kettleJob;
// END STUFF BROUGHT IN FROM SwingUIProject
- private final List<SessionLifecycleListener<ArchitectSwingSession>>
lifecycleListeners;
+ private final List<SessionLifecycleListener<ArchitectSession>>
lifecycleListeners;
private Set<SPSwingWorker> swingWorkers;
@@ -270,7 +270,7 @@
playPen.getPlayPenContentPane().addPropertyChangeListener("dashed",
undoManager.getEventAdapter()); //$NON-NLS-1$
playPen.getPlayPenContentPane().addPropertyChangeListener("rounded",
undoManager.getEventAdapter()); //$NON-NLS-1$
- lifecycleListeners = new
ArrayList<SessionLifecycleListener<ArchitectSwingSession>>();
+ lifecycleListeners = new
ArrayList<SessionLifecycleListener<ArchitectSession>>();
swingWorkers = new HashSet<SPSwingWorker>();
@@ -531,7 +531,7 @@
* projects, e.g., prompting to save any unsaved changes, disposing
dialogs,
* shutting down running threads, and so on.
*/
- public void close() {
+ public boolean close() {
// IMPORTANT NOTE: If the GUI hasn't been initialized, frame will
be null.
@@ -540,11 +540,15 @@
JOptionPane.showMessageDialog(frame,
Messages.getString("ArchitectSwingSessionImpl.cannotExitWhileSaving"),
//$NON-NLS-1$
Messages.getString("ArchitectSwingSessionImpl.cannotExitWhileSavingDialogTitle"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return;
+ return false;
}
if (!promptForUnsavedModifications()) {
- return;
+ return false;
+ }
+
+ if (!delegateSession.close()) {
+ return false;
}
// If we still have ArchitectSwingWorker threads running,
@@ -564,7 +568,7 @@
null, options, options[0]);
if (n == 0) {
- return;
+ return false;
} else {
for (SPSwingWorker currentWorker : swingWorkers) {
currentWorker.kill();
@@ -606,6 +610,8 @@
delegateSession.getProfileManager().clear();
fireSessionClosing();
+
+ return true;
}
/**
@@ -783,17 +789,17 @@
}
// END STUFF BROUGHT IN FROM SwingUIProject
- public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener) {
- lifecycleListeners.add(listener);
- }
-
- public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener) {
- lifecycleListeners.remove(listener);
+ public void
addSessionLifecycleListener(SessionLifecycleListener<ArchitectSession> l) {
+ lifecycleListeners.add(l);
+ }
+
+ public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSession>
l) {
+ lifecycleListeners.remove(l);
}
public void fireSessionClosing() {
- SessionLifecycleEvent<ArchitectSwingSession> evt = new
SessionLifecycleEvent<ArchitectSwingSession>(this);
- for (SessionLifecycleListener<ArchitectSwingSession> listener:
lifecycleListeners) {
+ SessionLifecycleEvent<ArchitectSession> evt = new
SessionLifecycleEvent<ArchitectSession>(this);
+ for (SessionLifecycleListener<ArchitectSession> listener:
lifecycleListeners) {
listener.sessionClosing(evt);
}
}
@@ -1045,4 +1051,12 @@
SwingUtilities.invokeLater(runner);
}
}
-}
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ delegateSession.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ delegateSession.removePropertyChangeListener(l);
+ }
+}
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
Tue Apr 7 14:43:36 2009
+++
/trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
Tue Jan 26 10:49:55 2010
@@ -33,6 +33,7 @@
import org.apache.log4j.Logger;
+import ca.sqlpower.architect.ArchitectSession;
import ca.sqlpower.architect.swingui.ArchitectSwingSession;
import ca.sqlpower.architect.swingui.PlayPen;
import ca.sqlpower.swingui.event.SessionLifecycleEvent;
@@ -57,9 +58,9 @@
};
session.getPlayPen().addFocusListener(focusListener);
- final SessionLifecycleListener<ArchitectSwingSession>
lifecycleListener = new SessionLifecycleListener<ArchitectSwingSession>() {
-
- public void
sessionClosing(SessionLifecycleEvent<ArchitectSwingSession> e) {
+ final SessionLifecycleListener<ArchitectSession> lifecycleListener
= new SessionLifecycleListener<ArchitectSession>() {
+
+ public void
sessionClosing(SessionLifecycleEvent<ArchitectSession> e) {
session.getPlayPen().removeFocusListener(focusListener);
}
};
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/olap/OLAPEditSession.java Mon
Jul 6 13:15:24 2009
+++ /trunk/src/ca/sqlpower/architect/swingui/olap/OLAPEditSession.java Tue
Jan 26 10:49:55 2010
@@ -35,6 +35,7 @@
import org.apache.log4j.Logger;
+import ca.sqlpower.architect.ArchitectSession;
import ca.sqlpower.architect.layout.FruchtermanReingoldForceLayout;
import ca.sqlpower.architect.olap.OLAPChildEvent;
import ca.sqlpower.architect.olap.OLAPChildListener;
@@ -162,8 +163,8 @@
pp = OLAPPlayPenFactory.createPlayPen(swingSession, this,
undoManager);
- swingSession.addSessionLifecycleListener(new
SessionLifecycleListener<ArchitectSwingSession>() {
- public void
sessionClosing(SessionLifecycleEvent<ArchitectSwingSession> e) {
+ swingSession.addSessionLifecycleListener(new
SessionLifecycleListener<ArchitectSession>() {
+ public void
sessionClosing(SessionLifecycleEvent<ArchitectSession> e) {
close();
}
});