1 11 package org.eclipse.ui.wizards.datatransfer; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.FileNotFoundException ; 16 import java.io.InputStream ; 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 21 22 26 public class FileSystemStructureProvider implements IImportStructureProvider { 27 28 31 public final static FileSystemStructureProvider INSTANCE = new FileSystemStructureProvider(); 32 33 36 private FileSystemStructureProvider() { 37 super(); 38 } 39 40 43 public List getChildren(Object element) { 44 File folder = (File ) element; 45 String [] children = folder.list(); 46 int childrenLength = children == null ? 0 : children.length; 47 List result = new ArrayList (childrenLength); 48 49 for (int i = 0; i < childrenLength; i++) { 50 result.add(new File (folder, children[i])); 51 } 52 53 return result; 54 } 55 56 59 public InputStream getContents(Object element) { 60 try { 61 return new FileInputStream ((File ) element); 62 } catch (FileNotFoundException e) { 63 IDEWorkbenchPlugin.log(e.getLocalizedMessage(), e); 64 return null; 65 } 66 } 67 68 71 public String getFullPath(Object element) { 72 return ((File ) element).getPath(); 73 } 74 75 78 public String getLabel(Object element) { 79 80 File file = (File ) element; 82 String name = file.getName(); 83 if (name.length() == 0) { 84 return file.getPath(); 85 } 86 return name; 87 } 88 89 92 public boolean isFolder(Object element) { 93 return ((File ) element).isDirectory(); 94 } 95 } 96 | Popular Tags |