svn commit: r19876 - trunk/src/argouml-app/src/org/argouml: i18n persistence ui
[email protected] Wed, 14 Mar 2012 00:14:53 -0700 (PDT)
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mvw
Date: 2012-03-14 00:14:53-0700
New Revision: 19876
Modified:
trunk/src/argouml-app/src/org/argouml/i18n/label.properties
trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties
trunk/src/argouml-app/src/org/argouml/persistence/AbstractFilePersister.java
trunk/src/argouml-app/src/org/argouml/persistence/OldZargoFilePersister.java
trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java
trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java
trunk/src/argouml-app/src/org/argouml/persistence/XmiFilePersister.java
trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java
trunk/src/argouml-app/src/org/argouml/persistence/ZipFilePersister.java
trunk/src/argouml-app/src/org/argouml/ui/SettingsDialog.java
trunk/src/argouml-app/src/org/argouml/ui/SettingsTabPreferences.java
Log:
Fix for issue 6012: saving project to network drive (SharePoint)
Modified: trunk/src/argouml-app/src/org/argouml/i18n/label.properties
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/label.properties?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/i18n/label.properties (original)
+++ trunk/src/argouml-app/src/org/argouml/i18n/label.properties 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
# $Id$
#******************************************************************************
-# Copyright (c) 2009-2011 Contributors - see below
+# Copyright (c) 2009-2012 Contributors - see below
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -474,6 +474,7 @@
label.usage = Usage
# Note: our internal uses are incorrectly spelled. Guillemet is correct.
label.use-guillemots = Use guillemets (\u00ab\u00bb)
+label.use-safe-saves = Use 'safe' saves (switch this off on SharePoint)
label.usecase = Use Case
label.usecase-base = Base Use Case:
label.usecase-diagram = Use Case Diagram
Modified: trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties (original)
+++ trunk/src/argouml-app/src/org/argouml/i18n/optionpane.properties 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
# $Id$
#******************************************************************************
-# Copyright (c) 2009 Contributors - see below
+# Copyright (c) 2009-2012 Contributors - see below
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
#
# Contributors:
# dthompson
+# Michiel van der Wulp
#******************************************************************************
#
# Some portions of this file was previously release using the BSD License:
@@ -79,4 +80,7 @@
optionpane.save-project-io-exception-title = Problem while saving.
optionpane.shortcut-save-conflict = Impossible to save shortcuts: conflicts found.
optionpane.shortcut-save-conflict-title = Problem while saving.
-
+optionpane.save-project-exception-cause1 = Failed to archive the previous file version. \
+ If the save destination is in a folder managed by \
+ SharePoint, then you should disable safe saves
+optionpane.save-project-exception-cause2 = Failed to archive the previous file version
Modified: trunk/src/argouml-app/src/org/argouml/persistence/AbstractFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/AbstractFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/AbstractFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/AbstractFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -50,6 +51,7 @@
import javax.swing.filechooser.FileFilter;
import org.apache.log4j.Logger;
+import org.argouml.configuration.Configuration;
import org.argouml.kernel.ProfileConfiguration;
import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectMember;
@@ -130,6 +132,29 @@
}
/**
+ * Saving in a safe way means: Retain the previous project
+ * file even when the save operation causes an
+ * exception in the middle.
+ * Also create a backup file after saving.
+ *
+ * See issue 6012 - our method of saving in a safe way does not
+ * work on a SharePoint drive.
+ * Hence we can configure ArgoUML to save unsafe, too...
+ *
+ * @return true if we should be careful
+ */
+ protected boolean useSafeSaves() {
+ boolean result = Configuration.getBoolean(
+ PersistenceManager.USE_SAFE_SAVES, true);
+
+ /* make sure this setting exists in the configuration file
+ * to facilitate changing: */
+ Configuration.setBoolean(PersistenceManager.USE_SAFE_SAVES, result);
+
+ return result;
+ }
+
+ /**
* Copies one file src to another, raising file exceptions
* if there are some problems.
*
Modified: trunk/src/argouml-app/src/org/argouml/persistence/OldZargoFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/OldZargoFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/OldZargoFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/OldZargoFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -100,8 +101,7 @@
}
/**
- * It is being considered to save out individual xmi's from individuals
- * diagrams to make it easier to modularize the output of Argo.
+ * Save the project in ".zargo" format.
*
* @param file
* The file to write.
@@ -117,6 +117,10 @@
public void doSave(Project project, File file) throws SaveException,
InterruptedException {
+ /* Retain the previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving. */
+ boolean doSafeSaves = useSafeSaves();
+
ProgressMgr progressMgr = new ProgressMgr();
progressMgr.setNumberOfPhases(4);
progressMgr.nextPhase();
@@ -124,14 +128,16 @@
File lastArchiveFile = new File(file.getAbsolutePath() + "~");
File tempFile = null;
- try {
- tempFile = createTempFile(file);
- } catch (FileNotFoundException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
- } catch (IOException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
+ if (doSafeSaves) {
+ try {
+ tempFile = createTempFile(file);
+ } catch (FileNotFoundException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause1"), e);
+ } catch (IOException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause2"), e);
+ }
}
BufferedWriter writer = null;
@@ -205,20 +211,20 @@
stream.flush();
}
}
-
-
-
- // if save did not raise an exception
- // and name+"#" exists move name+"#" to name+"~"
- // this is the correct backup file
- if (lastArchiveFile.exists()) {
- lastArchiveFile.delete();
- }
- if (tempFile.exists() && !lastArchiveFile.exists()) {
- tempFile.renameTo(lastArchiveFile);
- }
- if (tempFile.exists()) {
- tempFile.delete();
+
+ if (doSafeSaves) {
+ // if save did not raise an exception
+ // and name+"#" exists move name+"#" to name+"~"
+ // this is the correct backup file
+ if (lastArchiveFile.exists()) {
+ lastArchiveFile.delete();
+ }
+ if (tempFile.exists() && !lastArchiveFile.exists()) {
+ tempFile.renameTo(lastArchiveFile);
+ }
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
}
progressMgr.nextPhase();
@@ -231,11 +237,13 @@
// Do nothing.
}
- // frank: in case of exception
- // delete name and mv name+"#" back to name if name+"#" exists
- // this is the "rollback" to old file
- file.delete();
- tempFile.renameTo(file);
+ if (doSafeSaves) {
+ // frank: in case of exception
+ // delete name and mv name+"#" back to name if name+"#" exists
+ // this is the "rollback" to old file
+ file.delete();
+ tempFile.renameTo(file);
+ }
// we have to give a message to user and set the system to unsaved!
throw new SaveException(e);
}
Modified: trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/PersistenceManager.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* bobtarling
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -109,6 +110,16 @@
*/
public static final ConfigurationKey KEY_IMPORT_XMI_PATH =
Configuration.makeKey("xmi", "import", "path");
+
+ /**
+ * The configuration to do safe saves, i.e. retain the
+ * previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving.
+ * This works with a project file ending in "~" for the backup
+ * file, and a file ending in "#" for a temporary file during saving.
+ */
+ public static final ConfigurationKey USE_SAFE_SAVES =
+ Configuration.makeKey("project", "use", "safe-saves");
/**
* Create the default diagram persister.
Modified: trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/UmlFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* Contributors:
* Bob Tarling
* Thomas Neustupny
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -137,8 +138,7 @@
}
/**
- * It is being considered to save out individual xmi's from individuals
- * diagrams to make it easier to modularize the output of Argo.
+ * Save the project in ".uml" format.
*
* @param file The file to write.
* @param project the project to save
@@ -151,6 +151,10 @@
public void doSave(Project project, File file) throws SaveException,
InterruptedException {
+ /* Retain the previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving. */
+ boolean doSafeSaves = useSafeSaves();
+
ProgressMgr progressMgr = new ProgressMgr();
progressMgr.setNumberOfPhases(4);
progressMgr.nextPhase();
@@ -158,14 +162,16 @@
File lastArchiveFile = new File(file.getAbsolutePath() + "~");
File tempFile = null;
- try {
- tempFile = createTempFile(file);
- } catch (FileNotFoundException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
- } catch (IOException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
+ if (doSafeSaves) {
+ try {
+ tempFile = createTempFile(file);
+ } catch (FileNotFoundException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause1"), e);
+ } catch (IOException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause2"), e);
+ }
}
try {
@@ -186,17 +192,19 @@
LOG.info("Dir ==" + path);
}
- // if save did not raise an exception
- // and name+"#" exists move name+"#" to name+"~"
- // this is the correct backup file
- if (lastArchiveFile.exists()) {
- lastArchiveFile.delete();
- }
- if (tempFile.exists() && !lastArchiveFile.exists()) {
- tempFile.renameTo(lastArchiveFile);
- }
- if (tempFile.exists()) {
- tempFile.delete();
+ if (doSafeSaves) {
+ // if save did not raise an exception
+ // and name+"#" exists move name+"#" to name+"~"
+ // this is the correct backup file
+ if (lastArchiveFile.exists()) {
+ lastArchiveFile.delete();
+ }
+ if (tempFile.exists() && !lastArchiveFile.exists()) {
+ tempFile.renameTo(lastArchiveFile);
+ }
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
}
progressMgr.nextPhase();
@@ -204,11 +212,13 @@
} catch (Exception e) {
LOG.error("Exception occured during save attempt", e);
- // frank: in case of exception
- // delete name and mv name+"#" back to name if name+"#" exists
- // this is the "rollback" to old file
- file.delete();
- tempFile.renameTo(file);
+ if (doSafeSaves) {
+ // frank: in case of exception
+ // delete name and mv name+"#" back to name if name+"#" exists
+ // this is the "rollback" to old file
+ file.delete();
+ tempFile.renameTo(file);
+ }
if (e instanceof InterruptedException) {
throw (InterruptedException) e;
} else {
Modified: trunk/src/argouml-app/src/org/argouml/persistence/XmiFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/XmiFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/XmiFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/XmiFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -117,6 +118,10 @@
public void doSave(Project project, File file)
throws SaveException, InterruptedException {
+ /* Retain the previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving. */
+ boolean doSafeSaves = useSafeSaves();
+
ProgressMgr progressMgr = new ProgressMgr();
progressMgr.setNumberOfPhases(4);
progressMgr.nextPhase();
@@ -124,14 +129,16 @@
File lastArchiveFile = new File(file.getAbsolutePath() + "~");
File tempFile = null;
- try {
- tempFile = createTempFile(file);
- } catch (FileNotFoundException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
- } catch (IOException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
+ if (doSafeSaves) {
+ try {
+ tempFile = createTempFile(file);
+ } catch (FileNotFoundException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause1"), e);
+ } catch (IOException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause2"), e);
+ }
}
OutputStream stream = null;
@@ -140,17 +147,19 @@
writeProject(project, stream, progressMgr);
stream.close();
- // if save did not raise an exception
- // and name+"#" exists move name+"#" to name+"~"
- // this is the correct backup file
- if (lastArchiveFile.exists()) {
- lastArchiveFile.delete();
- }
- if (tempFile.exists() && !lastArchiveFile.exists()) {
- tempFile.renameTo(lastArchiveFile);
- }
- if (tempFile.exists()) {
- tempFile.delete();
+ if (doSafeSaves) {
+ // if save did not raise an exception
+ // and name+"#" exists move name+"#" to name+"~"
+ // this is the correct backup file
+ if (lastArchiveFile.exists()) {
+ lastArchiveFile.delete();
+ }
+ if (tempFile.exists() && !lastArchiveFile.exists()) {
+ tempFile.renameTo(lastArchiveFile);
+ }
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
}
} catch (InterruptedException exc) {
try {
@@ -163,11 +172,13 @@
stream.close();
} catch (IOException ex) { }
- // frank: in case of exception
- // delete name and mv name+"#" back to name if name+"#" exists
- // this is the "rollback" to old file
- file.delete();
- tempFile.renameTo(file);
+ if (doSafeSaves) {
+ // frank: in case of exception
+ // delete name and mv name+"#" back to name if name+"#" exists
+ // this is the "rollback" to old file
+ file.delete();
+ tempFile.renameTo(file);
+ }
// we have to give a message to user and set the system to unsaved!
throw new SaveException(e);
}
Modified: trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ZargoFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -128,6 +129,10 @@
InterruptedException {
LOG.info("Saving");
+ /* Retain the previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving. */
+ boolean doSafeSaves = useSafeSaves();
+
ProgressMgr progressMgr = new ProgressMgr();
progressMgr.setNumberOfPhases(4);
progressMgr.nextPhase();
@@ -135,14 +140,16 @@
File lastArchiveFile = new File(file.getAbsolutePath() + "~");
File tempFile = null;
- try {
- tempFile = createTempFile(file);
- } catch (FileNotFoundException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
- } catch (IOException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
+ if (doSafeSaves) {
+ try {
+ tempFile = createTempFile(file);
+ } catch (FileNotFoundException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause1"), e);
+ } catch (IOException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause2"), e);
+ }
}
ZipOutputStream stream = null;
@@ -167,17 +174,20 @@
persister.save(projectMember, stream);
}
}
- // if save did not raise an exception
- // and name+"#" exists move name+"#" to name+"~"
- // this is the correct backup file
- if (lastArchiveFile.exists()) {
- lastArchiveFile.delete();
- }
- if (tempFile.exists() && !lastArchiveFile.exists()) {
- tempFile.renameTo(lastArchiveFile);
- }
- if (tempFile.exists()) {
- tempFile.delete();
+
+ if (doSafeSaves) {
+ // if save did not raise an exception
+ // and name+"#" exists move name+"#" to name+"~"
+ // this is the correct backup file
+ if (lastArchiveFile.exists()) {
+ lastArchiveFile.delete();
+ }
+ if (tempFile.exists() && !lastArchiveFile.exists()) {
+ tempFile.renameTo(lastArchiveFile);
+ }
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
}
progressMgr.nextPhase();
@@ -192,11 +202,13 @@
// Do nothing.
}
- // frank: in case of exception
- // delete name and mv name+"#" back to name if name+"#" exists
- // this is the "rollback" to old file
- file.delete();
- tempFile.renameTo(file);
+ if (doSafeSaves) {
+ // frank: in case of exception
+ // delete name and mv name+"#" back to name if name+"#" exists
+ // this is the "rollback" to old file
+ file.delete();
+ tempFile.renameTo(file);
+ }
// we have to give a message to user and set the system to unsaved!
throw new SaveException(e);
}
Modified: trunk/src/argouml-app/src/org/argouml/persistence/ZipFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/persistence/ZipFilePersister.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/persistence/ZipFilePersister.java (original)
+++ trunk/src/argouml-app/src/org/argouml/persistence/ZipFilePersister.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -100,8 +101,7 @@
}
/**
- * It is being considered to save out individual xmi's from individuals
- * diagrams to make it easier to modularize the output of Argo.
+ * Save the project in ZIP format.
*
* @param file
* The file to write.
@@ -116,18 +116,24 @@
public void doSave(Project project, File file) throws SaveException {
LOG.info("Receiving file '" + file.getName() + "'");
-
+
+ /* Retain the previous project file even when the save operation
+ * crashes in the middle. Also create a backup file after saving. */
+ boolean doSafeSaves = useSafeSaves();
+
File lastArchiveFile = new File(file.getAbsolutePath() + "~");
File tempFile = null;
- try {
- tempFile = createTempFile(file);
- } catch (FileNotFoundException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
- } catch (IOException e) {
- throw new SaveException(
- "Failed to archive the previous file version", e);
+ if (doSafeSaves) {
+ try {
+ tempFile = createTempFile(file);
+ } catch (FileNotFoundException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause1"), e);
+ } catch (IOException e) {
+ throw new SaveException(Translator.localize(
+ "optionpane.save-project-exception-cause2"), e);
+ }
}
OutputStream bufferedStream = null;
@@ -158,17 +164,20 @@
}
}
stream.close();
- // if save did not raise an exception
- // and name+"#" exists move name+"#" to name+"~"
- // this is the correct backup file
- if (lastArchiveFile.exists()) {
- lastArchiveFile.delete();
- }
- if (tempFile.exists() && !lastArchiveFile.exists()) {
- tempFile.renameTo(lastArchiveFile);
- }
- if (tempFile.exists()) {
- tempFile.delete();
+
+ if (doSafeSaves) {
+ // if save did not raise an exception
+ // and name+"#" exists move name+"#" to name+"~"
+ // this is the correct backup file
+ if (lastArchiveFile.exists()) {
+ lastArchiveFile.delete();
+ }
+ if (tempFile.exists() && !lastArchiveFile.exists()) {
+ tempFile.renameTo(lastArchiveFile);
+ }
+ if (tempFile.exists()) {
+ tempFile.delete();
+ }
}
} catch (Exception e) {
LOG.error("Exception occured during save attempt", e);
@@ -178,11 +187,13 @@
// If we get a 2nd error, just ignore it
}
- // frank: in case of exception
- // delete name and mv name+"#" back to name if name+"#" exists
- // this is the "rollback" to old file
- file.delete();
- tempFile.renameTo(file);
+ if (doSafeSaves) {
+ // frank: in case of exception
+ // delete name and mv name+"#" back to name if name+"#" exists
+ // this is the "rollback" to old file
+ file.delete();
+ tempFile.renameTo(file);
+ }
// we have to give a message to user and set the system to unsaved!
throw new SaveException(e);
}
Modified: trunk/src/argouml-app/src/org/argouml/ui/SettingsDialog.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/SettingsDialog.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/SettingsDialog.java (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/SettingsDialog.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -101,7 +102,7 @@
}
// Increase width to accommodate all tabs on one row.
- final int minimumWidth = 500;
+ final int minimumWidth = 600;
tabs.setPreferredSize(new Dimension(Math.max(tabs
.getPreferredSize().width, minimumWidth), tabs
.getPreferredSize().height));
Modified: trunk/src/argouml-app/src/org/argouml/ui/SettingsTabPreferences.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/SettingsTabPreferences.java?view=diff&pathrev=19876&r1=19875&r2=19876
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/SettingsTabPreferences.java (original)
+++ trunk/src/argouml-app/src/org/argouml/ui/SettingsTabPreferences.java 2012-03-14 00:14:53-0700
@@ -1,6 +1,6 @@
/* $Id$
*****************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2012 Contributors - see below
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
*
* Contributors:
* tfmorris
+ * Michiel van der Wulp
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -50,6 +51,7 @@
import org.argouml.application.api.GUISettingsTabInterface;
import org.argouml.configuration.Configuration;
import org.argouml.i18n.Translator;
+import org.argouml.persistence.PersistenceManager;
/**
* Settings tab panel for handling ArgoUML application related settings.
@@ -64,7 +66,8 @@
private JCheckBox chkSplash;
private JCheckBox chkReloadRecent;
private JCheckBox chkStripDiagrams;
-
+ private JCheckBox chkUseSafeSaves;
+
/**
* The constructor.
*
@@ -102,6 +105,12 @@
chkStripDiagrams = j3;
topPanel.add(chkStripDiagrams, checkConstraints);
+ checkConstraints.gridy++;
+ JCheckBox j4 =
+ new JCheckBox(Translator.localize("label.use-safe-saves"));
+ chkUseSafeSaves = j4;
+ topPanel.add(chkUseSafeSaves, checkConstraints);
+
checkConstraints.fill = GridBagConstraints.HORIZONTAL;
add(topPanel, BorderLayout.NORTH);
@@ -118,6 +127,9 @@
chkStripDiagrams.setSelected(
Configuration.getBoolean(Argo.KEY_XMI_STRIP_DIAGRAMS,
false));
+ chkUseSafeSaves.setSelected(
+ Configuration.getBoolean(PersistenceManager.USE_SAFE_SAVES,
+ true));
}
/*
@@ -129,6 +141,8 @@
chkReloadRecent.isSelected());
Configuration.setBoolean(Argo.KEY_XMI_STRIP_DIAGRAMS,
chkStripDiagrams.isSelected());
+ Configuration.setBoolean(PersistenceManager.USE_SAFE_SAVES,
+ chkUseSafeSaves.isSelected());
}
/*
@@ -162,9 +176,5 @@
return "tab.preferences";
}
- /**
- * The UID.
- */
- private static final long serialVersionUID = -340220974967836979L;
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2935370
To unsubscribe from this discussion, e-mail: [[email protected]].