svn commit: r17375 - trunk/src/argouml-app/src/org/argouml/ui

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-10-06 15:09:36-0700
New Revision: 17375

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

Log:
Remove creation of GUI dialogs from the save thread (the progress dialog itself is yet to be moved)

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&pathrev=17375&r1=17374&r2=17375
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/ProjectBrowser.java	2009-10-06 15:09:36-0700
@@ -1213,7 +1213,23 @@
      * TODO: Separate this into a Swing specific class - tfm
      */
     public void trySaveWithProgressMonitor(boolean overwrite, File file) {
-        SaveSwingWorker worker = new SaveSwingWorker(overwrite, file);
+        if (!PersistenceManager.getInstance().confirmOverwrite(
+                ArgoFrame.getFrame(), overwrite, file)) {
+            return;
+        }
+        if (this.isFileReadonly(file)) {
+            JOptionPane.showMessageDialog(this, 
+                    Translator.localize(
+                            "optionpane.save-project-read-only"),
+                    Translator.localize(
+                            "optionpane.save-project-read-only-title"),
+                          JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+
+        SaveSwingWorker worker = new SaveSwingWorker(
+                ProjectManager.getManager().getCurrentProject(),
+                file);
         Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         worker.start();
     }
@@ -1236,32 +1252,50 @@
      * @return true if successful
      * 
      * TODO: Separate this into a Swing specific class - tfm
+     * @deprecated in 0.29.1 by Bob Tarling use trySaveWithProgressMonitor
      */
+    @Deprecated
     public boolean trySave(boolean overwrite, 
             File file, 
             ProgressMonitor pmw) {
         LOG.info("Saving the project");
+        
+        if (!PersistenceManager.getInstance().confirmOverwrite(
+                ArgoFrame.getFrame(), overwrite, file)) {
+            return false;
+        }
+        
+        if (this.isFileReadonly(file)) {
+            JOptionPane.showMessageDialog(this, 
+                    Translator.localize(
+                            "optionpane.save-project-read-only"),
+                    Translator.localize(
+                            "optionpane.save-project-read-only-title"),
+                          JOptionPane.INFORMATION_MESSAGE);
+            return false;
+        }
+
         Project project = ProjectManager.getManager().getCurrentProject();
+        return trySave(file, pmw, project);
+    }
+
+    /**
+     * Save the project.
+     * @param file the File to save to
+     * @param pmw       the ProgressMonitor to be updated;  
+     * @return true if successful
+     * 
+     * TODO: Separate this into a Swing specific class - tfm
+     */
+    boolean trySave(
+            final File file, 
+            final ProgressMonitor pmw,
+            final Project project) {
+        LOG.info("Saving the project");
         PersistenceManager pm = PersistenceManager.getInstance();
         ProjectFilePersister persister = null;
 
         try {
-            if (!PersistenceManager.getInstance().confirmOverwrite(
-                    ArgoFrame.getFrame(), overwrite, file)) {
-                return false;
-            }
-
-            if (this.isFileReadonly(file)) {
-                JOptionPane.showMessageDialog(this, 
-                        Translator.localize(
-                                "optionpane.save-project-read-only"),
-                        Translator.localize(
-                                "optionpane.save-project-read-only-title"),
-                              JOptionPane.INFORMATION_MESSAGE);
-                
-                return false;
-            }
-
             String sStatus =
                 MessageFormat.format(Translator.localize(
                     "statusmsg.bar.save-project-status-writing"),

Modified: trunk/src/argouml-app/src/org/argouml/ui/SaveSwingWorker.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/SaveSwingWorker.java?view=diff&pathrev=17375&r1=17374&r2=17375
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/SaveSwingWorker.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/SaveSwingWorker.java	2009-10-06 15:09:36-0700
@@ -29,28 +29,32 @@
 import javax.swing.UIManager;
 
 import org.argouml.i18n.Translator;
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
 import org.argouml.taskmgmt.ProgressMonitor;
 import org.argouml.util.ArgoFrame;
 import org.tigris.gef.undo.UndoManager;
 
 /**
  * The specialized SwingWorker used for saving projects
- * @deprecated in 0.29.1 by Bob Tarling. This will not be deleted but reduce
- * in scope to package to package only. It is currently only used by
+ * @deprecated in 0.29.1 by Bob Tarling. This will not be deleted but reduced
+ * in visibility to package visibility only. It is currently only used by
  * ProjectBrowser and any client calling should use methods there for save.
  */
 class SaveSwingWorker extends SwingWorker {
 @Deprecated
 
-    private boolean overwrite;
-    private File file;
+    private final boolean overwrite;
+    private final File file;
     private boolean result;
+    private Project project;
 
     /**
-     * This is the only constructor for SaveSwingWorker.
+     * Deprecated constructor for SaveSwingWorker.
      *
      * @param aFile        the file that's going to be saved
      * @param aOverwrite   whether to show the UI or not
+     * @deprecated in 0.29.1 Use constructor taking a Project
      */
     public SaveSwingWorker(boolean aOverwrite, File aFile) {
         super("ArgoSaveProjectThread");
@@ -59,6 +63,21 @@
     }
 
     /**
+     * This is the only constructor for SaveSwingWorker.
+     *
+     * @param project   the project to save
+     * @param aFile        the file that's going to be saved
+     */
+    public SaveSwingWorker(
+            final Project project,
+            final File aFile) {
+        super("ArgoSaveProjectThread");
+        overwrite = true;
+        file = aFile;
+        this.project = project;
+    }
+
+    /**
      * Implements org.argouml.swingext.SwingWorker#construct(); this is
      * the main method for this SwingWorker.
      * In this case, it simply loads the project.
@@ -71,15 +90,20 @@
         Thread currentThread = Thread.currentThread();
         currentThread.setPriority(currentThread.getPriority() - 1);
         // saves the project
-        result = ProjectBrowser.getInstance().trySave(overwrite, file, pmw);
+        if (project == null) {
+            // TODO: When the constructor with no Project is removed we can
+            // delete this block and make project final.
+            project = ProjectManager.getManager().getCurrentProject();
+        }
+        result = ProjectBrowser.getInstance().trySave(file, pmw, project);
         return null;
     }
 
     /**
      * Implements org.argouml.swingext.SwingWorker#initProgressMonitorWindow();
-     * it just creates an instance of ProgressMonitorWindow.
+     * it just creates an instance of ProgressMonitor.
      *
-     * @return  an instance of ProgressMonitorWindow
+     * @return  an instance of ProgressMonitor
      */
     public ProgressMonitor initProgressMonitorWindow() {
         Object[] msgArgs = new Object[] {file.getPath()};

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2404293

To unsubscribe from this discussion, e-mail: [[email protected]].
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.