KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > FileAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.io.File JavaDoc;
14 import java.util.Locale JavaDoc;
15
16 import org.eclipse.core.runtime.PlatformObject;
17
18 public class FileAdapter extends PlatformObject {
19     private File JavaDoc fFile;
20     private Object JavaDoc[] fChildren;
21     private FileAdapter fParent;
22     private String JavaDoc fEditorId;
23     private IFileAdapterFactory fFactory;
24
25     /**
26      * Constructor for FileAdapter.
27      */

28     public FileAdapter(FileAdapter parent, File JavaDoc file, IFileAdapterFactory factory) {
29         fFile = file;
30         fParent = parent;
31         fFactory = factory;
32     }
33
34     public boolean isManifest() {
35         String JavaDoc fileName = fFile.getName();
36         return (fileName.equals("plugin.xml") || fileName.equals("fragment.xml") || fileName.equalsIgnoreCase("manifest.mf")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
37
}
38     public boolean isSchema() {
39         String JavaDoc fileName = fFile.getName().toLowerCase(Locale.ENGLISH);
40         return fileName.endsWith(".exsd"); //$NON-NLS-1$
41
}
42             
43     public FileAdapter getParent() {
44         return fParent;
45     }
46
47     public void setEditorId(String JavaDoc editorId) {
48         this.fEditorId = editorId;
49     }
50
51     public String JavaDoc getEditorId() {
52         return fEditorId;
53     }
54
55     public File JavaDoc 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 JavaDoc[] getChildren() {
72         if (fFile.isDirectory() && fChildren == null)
73             createChildren();
74         return fChildren != null ? fChildren : new Object JavaDoc[0];
75     }
76
77     private void createChildren() {
78         File JavaDoc[] files = fFile.listFiles();
79         fChildren = new Object JavaDoc[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