1 56 package org.objectstyle.cayenne.modeler.util; 57 58 import java.io.File ; 59 60 import javax.swing.filechooser.FileFilter ; 61 62 import org.objectstyle.cayenne.conf.Configuration; 63 import org.objectstyle.cayenne.project.DataMapFile; 64 65 71 public class FileFilters { 72 73 protected static final FileFilter applicationFilter = new ApplicationFileFilter(); 74 protected static final FileFilter velotemplateFilter = new VelotemplateFileFilter(); 75 protected static final FileFilter eomodelFilter = new EOModelFileFilter(); 76 protected static final FileFilter eomodelSelectFilter = new EOModelSelectFilter(); 77 protected static final FileFilter dataMapFilter = new DataMapFileFilter(); 78 protected static final FileFilter classArchiveFilter = new JavaClassArchiveFilter(); 79 80 83 public static FileFilter getClassArchiveFilter() { 84 return classArchiveFilter; 85 } 86 87 90 public static FileFilter getApplicationFilter() { 91 return applicationFilter; 92 } 93 94 97 public static FileFilter getDataMapFilter() { 98 return dataMapFilter; 99 } 100 101 105 public static FileFilter getVelotemplateFilter() { 106 return velotemplateFilter; 107 } 108 109 113 public static FileFilter getEOModelFilter() { 114 return eomodelFilter; 115 } 116 117 128 public static FileFilter getEOModelSelectFilter() { 129 return eomodelSelectFilter; 130 } 131 132 static final class JavaClassArchiveFilter extends FileFilter { 133 public boolean accept(File f) { 134 if (f.isDirectory()) { 135 return true; 136 } 137 138 String name = f.getName().toLowerCase(); 139 return (name.length() > 4 && (name.endsWith(".jar") || name.endsWith(".zip"))); 140 } 141 142 public String getDescription() { 143 return "Java Class Archive (*.jar,*.zip)"; 144 } 145 } 146 147 static final class VelotemplateFileFilter extends FileFilter { 148 151 public boolean accept(File f) { 152 if (f.isDirectory()) { 153 return true; 154 } 155 156 String name = f.getName(); 157 return (name.endsWith(".vm") && !name.equals(".vm")); 158 } 159 160 public String getDescription() { 161 return "Velocity Templates (*.vm)"; 162 } 163 } 164 165 static final class ApplicationFileFilter extends FileFilter { 166 167 170 public boolean accept(File f) { 171 return f.isDirectory() 172 || Configuration.DEFAULT_DOMAIN_FILE.equals(f.getName()); 173 } 174 175 178 public String getDescription() { 179 return "Cayenne Applications (" + Configuration.DEFAULT_DOMAIN_FILE + ")"; 180 } 181 } 182 183 static final class DataMapFileFilter extends FileFilter { 184 185 188 public boolean accept(File f) { 189 if (f.isDirectory()) { 190 return true; 191 } 192 193 String name = f.getName(); 194 if (name.endsWith(DataMapFile.LOCATION_SUFFIX) 195 && !name.equals(DataMapFile.LOCATION_SUFFIX)) { 196 return true; 197 } 198 199 return false; 200 } 201 202 205 public String getDescription() { 206 return "DataMaps (*" + DataMapFile.LOCATION_SUFFIX + ")"; 207 } 208 } 209 210 static final class EOModelFileFilter extends FileFilter { 211 static final String EOM_SUFFIX = ".eomodeld"; 212 static final String EOM_INDEX = "index" + EOM_SUFFIX; 213 214 217 public boolean accept(File f) { 218 if (f.isDirectory()) { 219 return true; 220 } 221 222 File parent = f.getParentFile(); 223 return parent != null 224 && parent.getName().endsWith(EOM_SUFFIX) 225 && EOM_INDEX.equals(f.getName()); 226 } 227 228 public String getDescription() { 229 return "*" + EOM_SUFFIX; 230 } 231 } 232 233 static final class EOModelSelectFilter extends FileFilter { 234 239 public boolean accept(File f) { 240 if (f.isDirectory()) { 241 if (f.getName().endsWith(EOModelFileFilter.EOM_SUFFIX) 242 && new File (f, EOModelFileFilter.EOM_INDEX).exists()) { 243 244 return true; 245 } 246 } 247 else if (f.isFile()) { 248 File parent = f.getParentFile(); 249 if (parent != null 250 && parent.getName().endsWith(EOModelFileFilter.EOM_SUFFIX) 251 && EOModelFileFilter.EOM_INDEX.equals(f.getName())) { 252 return true; 253 } 254 } 255 256 return false; 257 } 258 259 public String getDescription() { 260 return "*" + EOModelFileFilter.EOM_SUFFIX; 261 } 262 } 263 } 264 | Popular Tags |