1 11 package org.eclipse.pde.internal.core; 12 13 import java.io.File ; 14 import java.util.Locale ; 15 16 import org.eclipse.core.runtime.PlatformObject; 17 18 public class FileAdapter extends PlatformObject { 19 private File fFile; 20 private Object [] fChildren; 21 private FileAdapter fParent; 22 private String fEditorId; 23 private IFileAdapterFactory fFactory; 24 25 28 public FileAdapter(FileAdapter parent, File file, IFileAdapterFactory factory) { 29 fFile = file; 30 fParent = parent; 31 fFactory = factory; 32 } 33 34 public boolean isManifest() { 35 String fileName = fFile.getName(); 36 return (fileName.equals("plugin.xml") || fileName.equals("fragment.xml") || fileName.equalsIgnoreCase("manifest.mf")); } 38 public boolean isSchema() { 39 String fileName = fFile.getName().toLowerCase(Locale.ENGLISH); 40 return fileName.endsWith(".exsd"); } 42 43 public FileAdapter getParent() { 44 return fParent; 45 } 46 47 public void setEditorId(String editorId) { 48 this.fEditorId = editorId; 49 } 50 51 public String getEditorId() { 52 return fEditorId; 53 } 54 55 public File getFile() { 56 return fFile; 57 } 58 59 public boolean isDirectory() { 60 return fFile.isDirectory(); 61 } 62 63 public boolean hasChildren() { 64 if (fFile.isDirectory() == false) 65 return false; 66 if (fChildren == null) 67 createChildren(); 68 return fChildren.length > 0; 69 } 70 71 public Object [] getChildren() { 72 if (fFile.isDirectory() && fChildren == null) 73 createChildren(); 74 return fChildren != null ? fChildren : new Object [0]; 75 } 76 77 private void createChildren() { 78 File [] files = fFile.listFiles(); 79 fChildren = new Object [files.length]; 80 for (int i = 0; i < files.length; i++) { 81 if (fFactory == null) 82 fChildren[i] = new FileAdapter(this, files[i], null); 83 else 84 fChildren[i] = fFactory.createAdapterChild(this, files[i]); 85 } 86 } 87 } 88 | Popular Tags |