Package org.apache.cayenne.project

Examples of org.apache.cayenne.project.Project


    /**
     * 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();

        // obtain preference object before save, when the project path may change.....
        Domain preference = getProjectController().getPreferenceDomainForProject();

        if (!chooseDestination(p)) {
            return false;
        }
       
        if (p.getMainFile().exists() && !p.getMainFile().canWrite()) {
            JOptionPane.showMessageDialog(Application.getFrame(),
                    "Can't save project - unable to write to file \"" + p.getMainFile().getPath() + "\"",
                    "Can't Save Project", JOptionPane.OK_OPTION);
            return false;
        }
       
        getProjectController().getProjectWatcher().pauseWatching();
       
        p.save();

        // update preferences domain key
        preference.rename(p.getMainFile().getAbsolutePath());

        getApplication().getFrameController().addToLastProjListAction(
                p.getMainFile().getAbsolutePath());
        Application.getFrame().fireRecentFileListChanged();

        /**
         * Reset the watcher now
         */
 
View Full Code Here


    public boolean enableForPath(ProjectPath path) {
        if (path == null) {
            return false;
        }

        Project project = path.firstInstanceOf(Project.class);
        return project != null && project.isModified();
    }
View Full Code Here

           
            getApplication().getFrameController().addToLastProjListAction(
                    file.getAbsolutePath());

            Configuration config = buildProjectConfiguration(file);
            Project project = new ApplicationProject(file, config);
            getProjectController().setProject(project);

            // if upgrade was canceled
            int upgradeStatus = project.getUpgradeStatus();
            if (upgradeStatus > 0) {
                JOptionPane
                        .showMessageDialog(
                                Application.getFrame(),
                                "Can't open project - it was created using a newer version of the Modeler",
View Full Code Here

                }
            }

            if (modelChanged) {
                // mark the model as unsaved
                Project project = getApplication().getProject();
                project.setModified(true);

                ProjectController projectController = getApplication()
                        .getFrameController()
                        .getProjectController();
                projectController.setDirty(true);
View Full Code Here

        super(getActionName(), application);
    }

    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()) {
View Full Code Here

        // non-derived DbEntities...

        // TODO: this is inefficient.. we need targeted validation
        // instead of doing it on the whole project

        Project project = getApplication().getProject();

        ProjectValidator projectValidator = getApplication().getInjector().getInstance(
                ProjectValidator.class);
        ValidationResult validationResult = projectValidator.validate(project
                .getRootNode());

        if (validationResult.getFailures().size() > 0) {

            for (ValidationFailure nextProblem : validationResult.getFailures()) {
View Full Code Here

        String name = NamedObjectFactory.createName(DataChannelDescriptor.class, domain);

        domain.setName(name);

        Project project = new Project(
                new ConfigurationTree<DataChannelDescriptor>(domain));

        controller.projectOpenedAction(project);

        // select default domain
View Full Code Here

    /**
     * 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
View Full Code Here

    public boolean enableForPath(ConfigurationNode object) {
        if (object == null) {
            return false;
        }

        Project project = getApplication().getProject();
        return project != null && project.isModified();
    }
View Full Code Here

                if (processUpgrades(md)) {
                    // perform upgrade
                    logObj.info("Will upgrade project " + url.getPath());
                    Resource upgraded = handler.performUpgrade();
                    if (upgraded != null) {
                        Project project = openProjectResourse(upgraded, controller);

                        getProjectController().getProjectWatcher().pauseWatching();
                        getProjectController().getProjectWatcher().reconfigure();

                        // if project file name changed
                        // need upgrade all
                        if (!file.getAbsolutePath().equals(
                                project.getConfigurationResource().getURL().getPath())) {
                            controller.changePathInLastProjListAction(file
                                    .getAbsolutePath(), project
                                    .getConfigurationResource()
                                    .getURL()
                                    .getPath());
                        }
                    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.project.Project

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.