use of org.apache.cayenne.project.Project in project cayenne by apache.
the class NewProjectAction method performAction.
public void performAction(ActionEvent e) {
CayenneModelerController controller = Application.getInstance().getFrameController();
// Save and close (if needed) currently open project.
if (getCurrentProject() != null && !closeProject(true)) {
return;
}
DataChannelDescriptor dataChannelDescriptor = new DataChannelDescriptor();
dataChannelDescriptor.setName(NameBuilder.builder(dataChannelDescriptor).name());
Project project = new Project(new ConfigurationTree<DataChannelDescriptor>(dataChannelDescriptor));
controller.projectOpenedAction(project);
// select default domain
getProjectController().fireDomainDisplayEvent(new DomainDisplayEvent(this, dataChannelDescriptor));
}
use of org.apache.cayenne.project.Project in project cayenne by apache.
the class RevertAction method performAction.
public void performAction(ActionEvent e) {
Project project = getCurrentProject();
if (project == null) {
return;
}
boolean isNew = project.getConfigurationResource() == null;
CayenneModelerController controller = getApplication().getFrameController();
// close ... don't use OpenProjectAction close method as it will ask for save, we
// don't want that here
controller.projectClosedAction();
File fileDirectory = new File(project.getConfigurationResource().getURL().getPath());
// reopen existing
if (!isNew && fileDirectory.isFile()) {
OpenProjectAction openAction = controller.getApplication().getActionManager().getAction(OpenProjectAction.class);
openAction.openProject(fileDirectory);
} else // create new
if (!(project instanceof Project)) {
throw new CayenneRuntimeException("Only ApplicationProjects are supported.");
} else {
controller.getApplication().getActionManager().getAction(NewProjectAction.class).performAction(e);
}
application.getUndoManager().discardAllEdits();
}
use of org.apache.cayenne.project.Project 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.Project 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