Search in sources :

Example 11 with Project

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));
}
Also used : Project(org.apache.cayenne.project.Project) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController)

Example 12 with Project

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();
}
Also used : Project(org.apache.cayenne.project.Project) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) File(java.io.File)

Example 13 with Project

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;
}
Also used : Project(org.apache.cayenne.project.Project) ProjectSaver(org.apache.cayenne.project.ProjectSaver) File(java.io.File)

Example 14 with Project

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;
}
Also used : Project(org.apache.cayenne.project.Project) URLResource(org.apache.cayenne.resource.URLResource) ProjectSaver(org.apache.cayenne.project.ProjectSaver) Preferences(java.util.prefs.Preferences) RenamedPreferences(org.apache.cayenne.pref.RenamedPreferences) File(java.io.File)

Aggregations

Project (org.apache.cayenne.project.Project)14 DataMap (org.apache.cayenne.map.DataMap)7 File (java.io.File)4 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 URLResource (org.apache.cayenne.resource.URLResource)3 DataMapBuilder (org.apache.cayenne.dbsync.merge.builders.DataMapBuilder)2 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)2 DbLoader (org.apache.cayenne.dbsync.reverse.dbload.DbLoader)2 DbLoaderConfiguration (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)2 DefaultModelMergeDelegate (org.apache.cayenne.dbsync.reverse.dbload.DefaultModelMergeDelegate)2 DbEntity (org.apache.cayenne.map.DbEntity)2 CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)2 FileProjectSaver (org.apache.cayenne.project.FileProjectSaver)2 ProjectSaver (org.apache.cayenne.project.ProjectSaver)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 Preferences (java.util.prefs.Preferences)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)1