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 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.awt.Frame;
 import  org.apache.cayenne.CayenneRuntimeException;
 import  org.apache.cayenne.conf.Configuration;
 import  org.apache.cayenne.project.ApplicationProject;
 import  org.apache.cayenne.project.DataMapProject;
 import  org.apache.cayenne.project.Project;
 import  org.apache.cayenne.project.ProjectFile;
File chooser panel used to select a directory to store project files.
 class ProjectOpener extends JFileChooser {
     private static Log logObj = LogFactory.getLog(ProjectOpener.class);

Selects a directory to store the project.
     File newProjectDir(Frame f, Project p) {
         if (p instanceof ApplicationProject) {
             // configure for application project
             return newProjectDir(f, Configuration.DEFAULT_DOMAIN_FILE, FileFilters
         else if (p instanceof DataMapProject) {
             // configure for DataMap project
             ProjectFile projFileWrapper = p.projectFileForObject(p);
             return newProjectDir(fprojFileWrapper.getLocation(), FileFilters
         else {
             String message = (p == null)
                     ? "Null project."
                     : "Unrecognized project class: " + p.getClass().getName();
             throw new CayenneRuntimeException(message);
     File newProjectDir(Frame fString locationFileFilter filter) {
         // configure dialog
         setDialogTitle("Select Project Directory");
         // preselect current directory
         if (getCurrentDirectory() != null) {
         // configure filters
         // allow users to see directories with cayenne.xml files
         File selectedDir;
         while (true) {
             int status = showDialog(f"Select");
             selectedDir = getSelectedFile();
             if (status != . || selectedDir == null) {
                 .info("Save canceled.");
                 return null;
             // normalize selection
             .info("Selected: " + selectedDir);
             if (!selectedDir.isDirectory()) {
                selectedDir = getSelectedFile().getParentFile();
            // check for overwrite
            File projectFile = new File(selectedDirlocation);
            if (projectFile.exists()) {
                OverwriteDialog dialog = new OverwriteDialog(projectFilef);
                if (dialog.shouldOverwrite()) {
                else if (dialog.shouldSelectAnother()) {
                else {
                    // canceled
                    return null;
            else {
        return selectedDir;

Runs a dialog to open Cayenne project.
    File openProjectFile(Frame f) {
        // configure dialog
        setDialogTitle("Select Project File");
        // configure filters
        // default to App projects
        int status = showOpenDialog(f);
        if (status != .) {
            return null;
        return getSelectedFile();

Returns directory where file search should start. This is either coming from saved preferences, or a current directory is used.
        // find start directory in preferences
        File existingDir = Application
        if (existingDir == null) {
            // go to current dir...
            existingDir = new File(System.getProperty("user.dir"));
        return existingDir;
New to GrepCode? Check out our FAQ X