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.util;
 
 import java.io.File;
 
 
 import  org.apache.cayenne.conf.Configuration;
 import  org.apache.cayenne.project.DataMapFile;

A collection of common file filters used by CayenneModeler JFileChoosers.

Author(s):
Andrei Adamchik
Since:
1.1
 
 public class FileFilters {
 
     protected static final FileFilter applicationFilter = new ApplicationFileFilter();
     protected static final FileFilter velotemplateFilter = new VelotemplateFileFilter();
     protected static final FileFilter eomodelFilter = new EOModelFileFilter();
     protected static final FileFilter eomodelSelectFilter = new EOModelSelectFilter();
     protected static final FileFilter dataMapFilter = new DataMapFileFilter();
     protected static final FileFilter classArchiveFilter = new JavaClassArchiveFilter();

    
Returns a FileFilter for java class archive files, such as JAR and ZIP.
 
     public static FileFilter getClassArchiveFilter() {
         return ;
     }

    
Returns a FileFilter used to select Cayenne Application project files.
 
     public static FileFilter getApplicationFilter() {
         return ;
     }

    
Returns a FileFilter used to select DataMap files.
 
     public static FileFilter getDataMapFilter() {
         return ;
     }

    
Returns a FileFilter used to select Velocity template files. Filters files with ".vm" extension.
 
     public static FileFilter getVelotemplateFilter() {
         return ;
     }

    
Returns a FileFilter used to filter EOModels. This filter will only display directories and index.eomodeld files.
 
     public static FileFilter getEOModelFilter() {
         return ;
     }

    
Returns FileFilter that defines the rules for EOModel selection. This filter will only allow selection of the following files/directories:
  • Directories with name matching *.eomodeld that contain index.eomodeld.
  • index.eomodeld files contained within *.eomodeld directory.
 
     public static FileFilter getEOModelSelectFilter() {
         return ;
     }
 
     static final class JavaClassArchiveFilter extends FileFilter {
         public boolean accept(File f) {
             if (f.isDirectory()) {
                 return true;
            }
            String name = f.getName().toLowerCase();
            return (name.length() > 4 && (name.endsWith(".jar") || name.endsWith(".zip")));
        }
        public String getDescription() {
            return "Java Class Archive (*.jar,*.zip)";
        }
    }
    static final class VelotemplateFileFilter extends FileFilter {
        
Accepts all *.vm files.
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            String name = f.getName();
            return (name.endsWith(".vm") && !name.equals(".vm"));
        }
        public String getDescription() {
            return "Velocity Templates (*.vm)";
        }
    }
    static final class ApplicationFileFilter extends FileFilter {

        
Accepts all directories and all cayenne.xml files.
        public boolean accept(File f) {
            return f.isDirectory()
                || Configuration.DEFAULT_DOMAIN_FILE.equals(f.getName());
        }

        
Returns description of this filter.
        public String getDescription() {
            return "Cayenne Applications (" + Configuration.DEFAULT_DOMAIN_FILE + ")";
        }
    }
    static final class DataMapFileFilter extends FileFilter {

        
Accepts all directories and all *.map.xml files.
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            String name = f.getName();
            if (name.endsWith(DataMapFile.LOCATION_SUFFIX)
                && !name.equals(DataMapFile.LOCATION_SUFFIX)) {
                return true;
            }
            return false;
        }

        
Returns description of this filter.
        public String getDescription() {
            return "DataMaps (*" + DataMapFile.LOCATION_SUFFIX + ")";
        }
    }
    static final class EOModelFileFilter extends FileFilter {
        static final String EOM_SUFFIX = ".eomodeld";
        static final String EOM_INDEX = "index" + ;

        
Accepts all directories and *.eomodeld/index.eomodeld files.
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return true;
            }
            File parent = f.getParentFile();
            return parent != null
                && parent.getName().endsWith()
                && .equals(f.getName());
        }
        public String getDescription() {
            return "*" + ;
        }
    }
    static final class EOModelSelectFilter extends FileFilter {
        
Accepts all directories and *.eomodeld/index.eomodeld files.

See also:
EOModelSelectFilter.accept(File)
        public boolean accept(File f) {
            if (f.isDirectory()) {
                if (f.getName().endsWith(.)
                    && new File(f.).exists()) {
                    return true;
                }
            }
            else if (f.isFile()) {
                File parent = f.getParentFile();
                if (parent != null
                    && parent.getName().endsWith(.)
                    && ..equals(f.getName())) {
                    return true;
                }
            }
            return false;
        }
        public String getDescription() {
            return "*" + .;
        }
    }
New to GrepCode? Check out our FAQ X