Revision: 4038
Author: [email protected]
Date: Mon Dec 13 08:44:10 2010
Log: Trying to open an enterprise architect file with a non-enterprise
version of Architect now notifies the user that they cannot open it, and
closes the blank project that was created during the loading process.
http://code.google.com/p/power-architect/source/detail?r=4038
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Mon Nov
8 11:05:46 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Mon Dec
13 08:44:10 2010
@@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InterruptedIOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.sql.SQLException;
@@ -169,6 +170,11 @@
protected int progress = 0;
protected ArchitectSession session;
+
+ /**
+ * The session that will display any required popups.
+ */
+ protected ArchitectSession siblingSession;
/**
* This stores the version of the file that this project loader would
@@ -186,6 +192,10 @@
// ------------- READING THE PROJECT FILE ---------------
+ public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources) throws IOException, SQLObjectException {
+ load(in, dataSources, null);
+ }
+
/**
* Loads the project data from the given input stream.
* <p>
@@ -196,8 +206,10 @@
* @param dataSources
* Collection of the data sources used in the project
*/
- public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources) throws IOException, SQLObjectException {
+ public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources,
+ ArchitectSession messageDelegate) throws IOException,
SQLObjectException {
UnclosableInputStream uin = new UnclosableInputStream(in);
+ siblingSession = messageDelegate;
try {
dbcsLoadIdMap = new HashMap<String, JDBCDataSource>();
sqlObjectLoadIdMap = new HashMap<String, SQLObject>();
@@ -212,7 +224,7 @@
//The digester likes to wrap the cancelled exception in a
SAXException.
if (ex.getException() instanceof
DigesterCancelledException) {
//Digeseter was cancelled by the user. Do not load
anything.
- return;
+ throw new RuntimeException(new
InterruptedIOException("progress"));
}
logger.error("SAX Exception in project file parse!", ex);
String message;
@@ -327,9 +339,30 @@
protected Digester setupDigester() throws
ParserConfigurationException, SAXException {
Digester d = new Digester(new UnescapingSaxParser());
+ final ArchitectSession messageOwner = (siblingSession == null ?
session : siblingSession);
d.setValidating(false);
d.push(session);
+ d.addRule("architect-enterprise-project", new Rule() {
+ @Override
+ public void begin(String namespace, String name, Attributes
attributes) throws Exception {
+ UserPrompter loadingWarningPrompt =
messageOwner.createUserPrompter(
+ "This file contains an Enterprise project and can
only\n" +
+ "be opened in the Architect Enterprise Edition.",
+ UserPromptType.BOOLEAN,
UserPromptOptions.OK_CANCEL,
+ UserPromptResponse.CANCEL,
UserPromptResponse.CANCEL, "Get Enterprise", "Cancel");
+ UserPromptResponse upr = loadingWarningPrompt.promptUser();
+ if (upr == UserPromptResponse.OK) {
+ try {
+
BrowserUtil.launch("http://www.sqlpower.ca/page/architect-e");
+ } catch (IOException e) {
+ throw new DigesterCancelledException();
+ }
+ }
+ throw new DigesterCancelledException();
+ }
+ });
+
//app version number
d.addRule("architect-project", new Rule() {
@Override
@@ -350,7 +383,7 @@
} catch (Exception e) {
loadingMessage = "The version of the file cannot be
understood.";
}
- UserPrompter loadingWarningPrompt =
session.createUserPrompter(
+ UserPrompter loadingWarningPrompt =
messageOwner.createUserPrompter(
loadingMessage + "\nDo you wish to try and open
the file?",
UserPromptType.BOOLEAN,
UserPromptOptions.OK_NOTOK_CANCEL,
UserPromptResponse.OK, UserPromptResponse.OK, "Try
loading",
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
Wed Dec 1 09:20:26 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
Mon Dec 13 08:44:10 2010
@@ -46,6 +46,7 @@
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
+import ca.sqlpower.architect.ArchitectSession;
import ca.sqlpower.architect.ArchitectVersion;
import ca.sqlpower.architect.ProjectLoader;
import ca.sqlpower.architect.UnclosableInputStream;
@@ -178,10 +179,15 @@
}
return olapModified || super.isModified();
}
+
+ public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources) throws IOException, SQLObjectException {
+ load(in, dataSources, null);
+ }
// ------------- READING THE PROJECT FILE ---------------
- public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources) throws IOException, SQLObjectException {
+ public void load(InputStream in, DataSourceCollection<? extends
SPDataSource> dataSources,
+ ArchitectSession messageDelegate) throws IOException,
SQLObjectException {
olapPaneLoadIdMap = new HashMap<String, OLAPPane<?, ?>>();
UnclosableInputStream uin = new UnclosableInputStream(in);
@@ -213,7 +219,7 @@
in.reset();
- super.load(in, dataSources);
+ super.load(in, dataSources, messageDelegate);
} finally {
getSession().getUndoManager().setLoading(false);
uin.forceClose();
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java
Fri Aug 20 15:11:42 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/OpenProjectAction.java
Mon Dec 13 08:44:10 2010
@@ -215,7 +215,7 @@
@Override
public void doStuff() throws Exception {
- session.getProjectLoader().load(in, session.getDataSources());
+ session.getProjectLoader().load(in, session.getDataSources(),
openingSession);
session.getProjectLoader().setFile(file);
}
@@ -226,8 +226,11 @@
// This if clause is to prevent an error from being thrown
if
// the user cancelled the file load,
// in which ProgressMonitorInputStream throws an
- // InterruptedIOException with message "progress"
- if (!(cause instanceof InterruptedIOException) |
| !(cause.getMessage().equals("progress"))) { //$NON-NLS-1$
+ // InterruptedIOException with message "progress",
+ // or if the user cancelled because of a warning when
+ // they tried to open an incompatible file
+ if (!(getDoStuffException() instanceof
InterruptedIOException) &&
+ (!(cause instanceof InterruptedIOException) |
| !(cause.getMessage().equals("progress")))) { //$NON-NLS-1$
// We have to use the non-session exception dialogue
here,
// because there is no session available (we just
failed to
// create one!)