Revision: 3281
Author: ferguson.sebastian
Date: Wed Feb 10 11:19:11 2010
Log: Improved client side session and project management panel
http://code.google.com/p/power-architect/source/detail?r=3281
Modified:
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
/trunk/src/ca/sqlpower/architect/enterprise/ProjectLocation.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
/trunk/src/ca/sqlpower/architect/swingui/enterprise/ServerProjectsManagerPanel.java
=======================================
---
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Mon Feb 8 14:05:30 2010
+++
/trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Wed Feb 10 11:19:11 2010
@@ -89,6 +89,8 @@
// -
+ int currentRevision = 0;
+
public ArchitectClientSideSession(ArchitectSessionContext context,
String name, ProjectLocation projectLocation) throws SQLObjectException
{
super(context, name);
@@ -174,6 +176,7 @@
return new
SpecificDataSourceCollection<JDBCDataSource>(plIni, JDBCDataSource.class);
}
};
+
try {
dataSourceCollection =
executeServerRequest(outboundHttpClient,
projectLocation.getServiceInfo(), "/data-sources/", plIniHandler);
} catch (Exception ex) {
@@ -189,10 +192,10 @@
updater.start();
final SPPersisterListener listener = new SPPersisterListener(
- new
SPPersisterHelperFactoryImpl(sessionPersister,
- new SessionPersisterSuperConverter(dataSourceCollection,
getWorkspace())));
-
- SQLPowerUtils.listenToHierarchy(getWorkspace(), listener);
+ new SPPersisterHelperFactoryImpl(jsonPersister,
+ new SessionPersisterSuperConverter(dataSourceCollection,
getWorkspace().getRootObject())));
+
+ SQLPowerUtils.listenToHierarchy(getWorkspace().getRootObject(),
listener);
addSessionLifecycleListener(new
SessionLifecycleListener<ArchitectSession>() {
public void
sessionClosing(SessionLifecycleEvent<ArchitectSession> e) {
@@ -364,6 +367,9 @@
public void flush() throws SPPersistenceException {
try {
+
+ currentRevision++;
+
URI serverURI = getServerURI();
HttpPost postRequest = new HttpPost(serverURI);
postRequest.setEntity(new
StringEntity(message.toString()));
@@ -374,7 +380,10 @@
throws
ClientProtocolException, IOException {
StatusLine statusLine =
response.getStatusLine();
if (statusLine.getStatusCode()
>= 400) {
- throw new
ClientProtocolException(
+
+ currentRevision--;
+
+ throw new
ClientProtocolException(
"HTTP Post
request returned an error: " +
"Code = " +
statusLine.getStatusCode() + ", " +
"Reason =
" + statusLine.getReasonPhrase());
@@ -383,10 +392,13 @@
}
});
} catch (ClientProtocolException e) {
+ currentRevision--;
throw new SPPersistenceException(null, e);
} catch (IOException e) {
+ currentRevision--;
throw new SPPersistenceException(null, e);
} catch (URISyntaxException e) {
+ currentRevision--;
throw new SPPersistenceException(null, e);
} finally {
clear();
@@ -450,23 +462,28 @@
logger.info("Updater thread starting");
// the path to contact on the server for update events
- int currentRevision = 0;
- final String contextRelativePath = "/project/" +
getWorkspace().getUUID() +
-
"?oldRevisionNo=" + currentRevision;
+ final String contextRelativePath = "/project/" +
projectLocation.getUUID();
try {
while (!this.isInterrupted() && !cancelled) {
try {
-
- final String jsonArray =
executeServerRequest(
-
inboundHttpClient, projectLocation.getServiceInfo(),
-
contextRelativePath, new BasicResponseHandler());
-
- System.out.println(jsonArray);
- runInForeground(new Runnable() {
+
+ URI uri = new URI("http", null,
projectLocation.getServiceInfo().getServerAddress(),
projectLocation.getServiceInfo().getPort(),
+ projectLocation.getServiceInfo().getPath() +
contextRelativePath, "oldRevisionNo=" + currentRevision, null);
+ HttpUriRequest request = new
HttpGet(uri);
+
+ String message = inboundHttpClient.execute(request, new
BasicResponseHandler());
+ JSONObject json = new
JSONObject(message);
+ final String jsonArray =
json.getString("data");
+
+ currentRevision =
json.getInt("currentRevision");
+
+ runInForeground(new Runnable() {
public void run() {
try {
+
jsonDecoder.decode(jsonArray);
+
} catch
(SPPersistenceException e) {
logger.error("Update from server failed!", e);
createUserPrompter(
@@ -479,7 +496,7 @@
}
}
});
- } catch (Exception ex) {
+ } catch (Exception ex) {
logger.error("Failed to contact server. Will retry in " + retryDelay
+ " ms.", ex);
Thread.sleep(retryDelay);
}
=======================================
--- /trunk/src/ca/sqlpower/architect/enterprise/ProjectLocation.java Mon
Feb 8 14:05:30 2010
+++ /trunk/src/ca/sqlpower/architect/enterprise/ProjectLocation.java Wed
Feb 10 11:19:11 2010
@@ -36,6 +36,6 @@
@Override
public String toString() {
- return serviceInfo + ", uuid=" + uuid;
+ return name + " (" +uuid +")";
}
}
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java Tue Feb 9
12:57:13 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java Wed Feb 10
11:19:11 2010
@@ -254,7 +254,6 @@
};
ServerProjectsManagerPanel spm = new
ServerProjectsManagerPanel(session.getContext(),
- session.getContext().getServerManager(),
ArchitectFrame.this, closeAction);
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.setContentPane(spm.getPanel());
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Tue Feb 9 12:57:13 2010
+++
/trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java
Wed Feb 10 11:19:11 2010
@@ -295,9 +295,8 @@
public ArchitectSwingSession createServerSession(ProjectLocation
projectLocation, String name, boolean initGUI) throws SQLObjectException {
ArchitectClientSideSession clientSession = new
ArchitectClientSideSession(this, name, projectLocation);
- clientSession.startUpdaterThread();
-
ArchitectSwingSession swingSession = new
ArchitectSwingSessionImpl(this, clientSession);
+ clientSession.startUpdaterThread();
if (initGUI) {
swingSession.initGUI();
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/enterprise/ServerProjectsManagerPanel.java
Tue Feb 9 12:57:13 2010
+++
/trunk/src/ca/sqlpower/architect/swingui/enterprise/ServerProjectsManagerPanel.java
Wed Feb 10 11:19:11 2010
@@ -41,7 +41,6 @@
import ca.sqlpower.architect.enterprise.ProjectLocation;
import ca.sqlpower.architect.swingui.ArchitectSwingSessionContextImpl;
import ca.sqlpower.enterprise.client.SPServerInfo;
-import ca.sqlpower.enterprise.client.SPServerInfoManager;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.CellConstraints;
@@ -50,9 +49,10 @@
public class ServerProjectsManagerPanel {
private final Component dialogOwner;
- private final JPanel panel;
- private final SPServerInfoManager serverInfoManager;
private final ArchitectSessionContext context;
+
+ private final JPanel panel;
+ private final Action closeAction;
private JList projects;
private JList servers;
@@ -106,8 +106,8 @@
}
}
}
-
- refreshInfoList();
+
+ closeAction.actionPerformed(e);
}
}
}
@@ -157,10 +157,11 @@
}
};
- public ServerProjectsManagerPanel(ArchitectSessionContext context,
SPServerInfoManager serverInfoManager, Component dialogOwner, Action
closeAction) {
+ public ServerProjectsManagerPanel(ArchitectSessionContext context,
+ Component dialogOwner, Action closeAction) {
this.dialogOwner = dialogOwner;
- this.serverInfoManager = serverInfoManager;
this.context = context;
+ this.closeAction = closeAction;
DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(
"pref:grow, 5dlu, pref:grow, 5dlu, pref",
@@ -178,8 +179,8 @@
DefaultListModel serversModel = (DefaultListModel)
servers.getModel();
serversModel.removeAllElements();
- if (serverInfoManager.getServers(false).size() > 0) {
- for (SPServerInfo serverInfo :
serverInfoManager.getServers(false)) {
+ if (context.getServerManager().getServers(false).size() > 0) {
+ for (SPServerInfo serverInfo :
context.getServerManager().getServers(false)) {
serversModel.addElement(serverInfo);
}
} else {
@@ -191,7 +192,7 @@
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 &&
SwingUtilities.isLeftMouseButton(e)) {
- openSelectedProject();
+ openAction.actionPerformed(null);
}
}
});
@@ -238,6 +239,7 @@
} catch (Exception ex) {
model.removeAllElements();
model.addElement("There has been a problem retrieving
projects from the selected server");
+ throw new RuntimeException("There has been a problem
retrieving projects from the selected server", ex);
}
} else {
model.addElement("No Server Selected");
@@ -258,8 +260,4 @@
return null;
}
-
- private void openSelectedProject() {
-
- }
-}
+}