1 19 20 package org.netbeans.modules.j2ee.persistence.wizard.fromdb; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.Comparator ; 26 import java.util.Enumeration ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.SourceGroup; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.util.NbBundle; 35 36 40 public class DBSchemaFileList { 41 42 private final Map <FileObject,String > dbschema2DisplayName = new HashMap <FileObject,String >(); 43 private final List dbschemaList; 44 45 public DBSchemaFileList(Project project, FileObject configFilesFolder) { 46 SourceGroup[] sourceGroups = SourceGroupSupport.getJavaSourceGroups(project); 47 48 for (int i = 0; i < sourceGroups.length; i++) { 50 searchRoot(sourceGroups[i].getRootFolder(), sourceGroups[i].getDisplayName()); 51 } 52 53 if (configFilesFolder != null) { 54 String configFilesDisplayName = NbBundle.getMessage(DBSchemaFileList.class, "LBL_Node_DocBase"); 55 searchRoot(configFilesFolder, configFilesDisplayName); 56 } 57 58 List tempDBSchemaList = new ArrayList (dbschema2DisplayName.keySet()); 59 Collections.sort(tempDBSchemaList, new DBSchemaComparator()); 60 61 dbschemaList = Collections.unmodifiableList(tempDBSchemaList); 62 } 63 64 private void searchRoot(FileObject root, String rootDisplayName) { 65 Enumeration ch = root.getChildren(true); 66 while (ch.hasMoreElements()) { 67 FileObject f = (FileObject) ch.nextElement(); 68 if (f.getExt().equals(DBSchemaManager.DBSCHEMA_EXT) && !f.isFolder()) { 69 if (!dbschema2DisplayName.containsKey(f)) { 70 String relativeParent = FileUtil.getRelativePath(root, f.getParent()) + File.separator; 71 if (relativeParent.startsWith("/")) { relativeParent = relativeParent.substring(1); 73 } 74 String relative = relativeParent + f.getName(); 75 String displayName = NbBundle.getMessage(DBSchemaFileList.class, 76 "LBL_SchemaLocation", rootDisplayName, relative); 77 dbschema2DisplayName.put(f, displayName); 78 } 79 } 80 } 81 } 82 83 public List <FileObject> getFileList() { 84 return dbschemaList; 85 } 86 87 public String getDisplayName(FileObject dbschemaFile) { 88 return dbschema2DisplayName.get(dbschemaFile); 89 } 90 91 private final class DBSchemaComparator implements Comparator { 92 93 public int compare(Object o1, Object o2) { 94 FileObject f1 = (FileObject)o1; 95 FileObject f2 = (FileObject)o2; 96 97 String displayName1 = dbschema2DisplayName.get(f1); 98 String displayName2 = dbschema2DisplayName.get(f2); 99 100 return displayName1.compareTo(displayName2); 101 } 102 } 103 } 104 | Popular Tags |