Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.modeler.action;
 
 import java.io.File;
 
 

Author(s):
Andrei Adamchik
 
 public class OpenProjectAction extends ProjectAction {
 
     private static Logger logObj = Logger.getLogger(OpenProjectAction.class);
 
     protected ProjectOpener fileChooser;
 
     public static String getActionName() {
         return "Open Project";
     }

    
Constructor for OpenProjectAction.
 
     public OpenProjectAction(Application application) {
         super(getActionName(), application);
         this. = new ProjectOpener();
     }
 
     public String getIconName() {
         return "icon-open.gif";
     }
 
     public KeyStroke getAcceleratorKey() {
         return KeyStroke.getKeyStroke(., Toolkit
                 .getDefaultToolkit()
                 .getMenuShortcutKeyMask());
     }
 
     public void performAction(ActionEvent e) {
 
         // Save and close (if needed) currently open project.
         if (getProjectController() != null && !checkSaveOnClose()) {
             return;
         }
 
         File f = null;
         if (e.getSource() instanceof FileMenuItem) {
             FileMenuItem menu = (FileMenuIteme.getSource();
             f = menu.getFile();
         }
 
         if (f == null) {
             try {
                 // Get the project file name (always cayenne.xml)
                 f = .openProjectFile(Application.getFrame());
             }
             catch (Exception ex) {
                 .warn("Error loading project file."ex);
             }
         }
 
         if (f != null) {
             // by now if the project is unsaved, this has been a user choice...
             if (getProjectController() != null && !closeProject(false)) {
                 return;
             }
 
             openProject(f);
        }
    }

    
Opens specified project file. File must already exist.
    public void openProject(File file) {
        try {
                    file.getAbsolutePath());
            Configuration config = buildProjectConfiguration(file);
            Project project = new ApplicationProject(fileconfig);
            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",
                                "Can't Open Project",
                                .);
                closeProject(false);
            }
            else if (upgradeStatus < 0) {
                if (processUpgrades(project)) {
                    getApplication().getFrameController().projectOpenedAction(project);
                }
                else {
                    closeProject(false);
                }
            }
            else {
                getApplication().getFrameController().projectOpenedAction(project);
            }
        }
        catch (Exception ex) {
            .warn("Error loading project file."ex);
            ErrorDebugDialog.guiWarning(ex"Error loading project");
        }
    }
    protected boolean processUpgrades(Project projectthrows ProjectException {
        // must really concat all messages, this is a temp hack...
        String msg = (Stringproject.getUpgradeMessages().get(0);
        // need an upgrade
        int returnCode = JOptionPane.showConfirmDialog(
                Application.getFrame(),
                "Project needs an upgrade to a newer version. " + msg + ". Upgrade?",
                "Upgrade Needed",
                .);
        if (returnCode == .) {
            return false;
        }
        // perform upgrade
        .info("Will upgrade project " + project.getMainFile());
        project.upgrade();
        return true;
    }
New to GrepCode? Check out our FAQ X