/**
* Saves project and related files. Saving is done to temporary files, and only on
* successful save, master files are replaced with new versions.
*/
protected boolean saveAll() throws Exception {
Project p = getCurrentProject();
String oldPath = null;
if (p.getConfigurationResource() != null) {
oldPath = p.getConfigurationResource().getURL().getPath();
}
File projectDir = fileChooser.newProjectDir(Application.getFrame(), p);
if (projectDir == null) {
return false;
}
if (projectDir.exists() && !projectDir.canWrite()) {
JOptionPane.showMessageDialog(
Application.getFrame(),
"Can't save project - unable to write to file \""
+ projectDir.getPath()
+ "\"",
"Can't Save Project",
JOptionPane.OK_OPTION);
return false;
}
getProjectController().getProjectWatcher().pauseWatching();
URL url = projectDir.toURL();
URLResource res = new URLResource(url);
ProjectSaver saver = getApplication().getInjector().getInstance(
ProjectSaver.class);
boolean isNewProject = p.getConfigurationResource() == null;
Preferences tempOldPref = null;
if (isNewProject) {
tempOldPref = getApplication().getMainPreferenceForProject();
}
saver.saveAs(p, res);
if (oldPath != null
&& oldPath.length() != 0
&& !oldPath.equals(p.getConfigurationResource().getURL().getPath())) {
String newName = p.getConfigurationResource().getURL().getPath().replace(
".xml",
"");
String oldName = oldPath.replace(".xml", "");
Preferences oldPref = getProjectController().getPreferenceForProject();
String projPath = oldPref.absolutePath().replace(oldName, "");
Preferences newPref = getProjectController().getPreferenceForProject().node(
projPath + newName);
RenamedPreferences.copyPreferences(newPref, getProjectController()
.getPreferenceForProject(), false);
}
else if (isNewProject) {
if (tempOldPref != null) {
String newProjectName = getApplication().getNewProjectTemporaryName();
if (tempOldPref.absolutePath().contains(newProjectName)) {
String projPath = tempOldPref.absolutePath().replace(
"/" + newProjectName,
"");
String newName = p
.getConfigurationResource()
.getURL()
.getPath()
.replace(".xml", "");
Preferences newPref = getApplication()
.getMainPreferenceForProject()
.node(projPath + newName);
RenamedPreferences.copyPreferences(newPref, tempOldPref, false);
tempOldPref.removeNode();
}
}
}
RenamedPreferences.removeNewPreferences();
getApplication().getFrameController().addToLastProjListAction(
p.getConfigurationResource().getURL().getPath());
Application.getFrame().fireRecentFileListChanged();
/**
* Reset the watcher now