use of org.apache.cayenne.project.ProjectSaver in project cayenne by apache.
the class SaveAction method saveAll.
@Override
protected boolean saveAll() throws Exception {
Project p = getCurrentProject();
if (p == null || p.getConfigurationResource() == null) {
return super.saveAll();
}
String oldPath = p.getConfigurationResource().getURL().getPath();
File oldProjectFile = new File(p.getConfigurationResource().getURL().toURI());
getProjectController().getFileChangeTracker().pauseWatching();
ProjectSaver saver = getApplication().getInjector().getInstance(ProjectSaver.class);
saver.save(p);
RenamedPreferences.removeOldPreferences();
// if change DataChanelDescriptor name - as result change name of xml file
// we will need change preferences path
String[] path = oldPath.split("/");
String[] newPath = p.getConfigurationResource().getURL().getPath().split("/");
if (!path[path.length - 1].equals(newPath[newPath.length - 1])) {
String newName = newPath[newPath.length - 1].replace(".xml", "");
RenamedPreferences.copyPreferences(newName, getProjectController().getPreferenceForProject());
RenamedPreferences.removeOldPreferences();
}
File newProjectFile = new File(p.getConfigurationResource().getURL().toURI());
getApplication().getFrameController().changePathInLastProjListAction(oldProjectFile, newProjectFile);
Application.getFrame().fireRecentFileListChanged();
// Reset the watcher now
getProjectController().getFileChangeTracker().reconfigure();
return true;
}
use of org.apache.cayenne.project.ProjectSaver in project cayenne by apache.
the class SaveAsAction method saveAll.
/**
* 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().getFileChangeTracker().pauseWatching();
URLResource res = new URLResource(projectDir.toURI().toURL());
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();
File file = new File(p.getConfigurationResource().getURL().toURI());
getApplication().getFrameController().addToLastProjListAction(file);
Application.getFrame().fireRecentFileListChanged();
// Reset the watcher now
getProjectController().getFileChangeTracker().reconfigure();
return true;
}
Aggregations