svn commit: r15408 - trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-07-30 11:26:40-0700
New Revision: 15408

Modified:
   trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java

Log:
Issue 5245: Simplify control flow for error cases.  Always delete old project instead of trying to preserve it.

Modified: trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java?view=diff&rev=15408&p1=trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java&p2=trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java&r1=15407&r2=15408
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java	2008-07-30 11:26:40-0700
@@ -1573,7 +1573,7 @@
 
         PersistenceManager pm = PersistenceManager.getInstance();
         Project oldProject = ProjectManager.getManager().getCurrentProject();
-        boolean success = true;
+        boolean success = false;
 
         // TODO:
         // This is actually a hack! Some diagram types
@@ -1604,7 +1604,6 @@
                 ProjectFilePersister persister =
                     pm.getPersisterFromFileName(file.getName());
                 if (persister == null) {
-                    success = false;
                     throw new IllegalStateException("Filename "
                             + file.getName()
                             + " is not of a known file type");
@@ -1647,9 +1646,8 @@
                         Translator.localize(
                                 "statusmsg.bar.open-project-status-read",
                                 new Object[] {file.getName(), }));
+                success = true;
             } catch (VersionException ex) {
-                project = oldProject;
-                success = false;
                 reportError(
                         pmw,
                         Translator.localize(
@@ -1657,20 +1655,14 @@
                                 new Object[] {ex.getMessage()}),
                         showUI);
             } catch (OutOfMemoryError ex) {
-                project = oldProject;
-                success = false;
                 LOG.error("Out of memory while loading project", ex);
                 reportError(
                         pmw,
                         Translator.localize("dialog.error.memory.limit"),
                         showUI);
             } catch (java.lang.InterruptedException ex) {
-                project = oldProject;
-                success = false;
                 LOG.error("Project loading interrupted by user");
             } catch (UmlVersionException ex) {
-                project = oldProject;
-                success = false;
                 reportError(
                         pmw,
                         Translator.localize(
@@ -1678,8 +1670,6 @@
                                 new Object[] {ex.getMessage()}),
                         showUI, ex);
             } catch (XmiFormatException ex) {
-                project = oldProject;
-                success = false;
                 reportError(
                         pmw,
                         Translator.localize(
@@ -1687,8 +1677,6 @@
                                 new Object[] {ex.getMessage()}),
                         showUI, ex);
             } catch (IOException ex) {
-                success = false;
-                project = oldProject;
                 LOG.error("Exception while loading project", ex);
                 reportError(
                         pmw,
@@ -1697,8 +1685,6 @@
                                 new Object[] {file.getName()}),
                         showUI, ex);
             } catch (OpenException ex) {
-                success = false;
-                project = oldProject;
                 LOG.error("Exception while loading project", ex);
                 reportError(
                         pmw,
@@ -1707,8 +1693,6 @@
                                 new Object[] {file.getName()}),
                         showUI, ex);
             } catch (RuntimeException ex) {
-                success = false;
-                project = oldProject;
                 LOG.error("Exception while loading project", ex);
                 reportError(
                         pmw,
@@ -1718,47 +1702,34 @@
                         showUI, ex);
             } finally {
 
-        	try {
-                    if (oldProject != null) {
-                        // if p equals oldProject there was an exception and we
-                        // do not have to gc (garbage collect) the old project
-                        if (project != null && !project.equals(oldProject)) {
-                            //prepare the old project for gc
-                            LOG.info("There are "
-                                    + oldProject.getDiagramList().size()
-                                    + " diagrams in the old project");
-                            LOG.info("There are " 
-                                    + project.getDiagramList().size()
-                                    + " diagrams in the new project");
-                            // Set new project before removing old so we always
-                            // have a valid current project
-                            ProjectManager.getManager().setCurrentProject(
-                                    project);
-                            ProjectManager.getManager().removeProject(
-                                    oldProject);
-                            project.getProjectSettings().init();
-                            Command cmd = new NonUndoableCommand() {
-                                public Object execute() {
-                                    // This is temporary. Load project
-                                    // should create a new project
-                                    // with its own UndoManager and so
-                                    // there should be no Command
-                                    return null;
-                                }
-                            };
-                            project.getUndoManager().addCommand(cmd);
-                        }
+                try {
+                    if (!success) {
+                        project = 
+                            ProjectManager.getManager().makeEmptyProject();
                     }
-
-                    if (project == null) {
-                        LOG.info("The current project is null");
-                    } else {
-                        LOG.info("There are " + project.getDiagramList().size()
-                                + " diagrams in the current project");
+                    ProjectManager.getManager().setCurrentProject(project);
+                    if (oldProject != null) {
+                        ProjectManager.getManager().removeProject(oldProject);
                     }
                     
+                    project.getProjectSettings().init();
+                    
+                    Command cmd = new NonUndoableCommand() {
+                        public Object execute() {
+                            // This is temporary. Load project
+                            // should create a new project
+                            // with its own UndoManager and so
+                            // there should be no Command
+                            return null;
+                        }
+                    };
+                    project.getUndoManager().addCommand(cmd);
+
+                    LOG.info("There are " + project.getDiagramList().size()
+                            + " diagrams in the current project");
+
                     Designer.enableCritiquing();
-        	} finally {
+                } finally {
                     // Make sure save action is always reinstated
                     this.saveAction = rememberedSaveAction;
                     ProjectManager.getManager().setSaveAction(
@@ -1766,7 +1737,7 @@
                     if (success) {
                         rememberedSaveAction.setEnabled(false);
                     }
-        	}
+                }
             }
         }
         return success;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.