01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core;
11:
12: import java.io.File;
13: import java.util.Locale;
14:
15: import org.eclipse.core.runtime.PlatformObject;
16:
17: public class FileAdapter extends PlatformObject {
18: private File fFile;
19: private Object[] fChildren;
20: private FileAdapter fParent;
21: private String fEditorId;
22: private IFileAdapterFactory fFactory;
23:
24: /**
25: * Constructor for FileAdapter.
26: */
27: public FileAdapter(FileAdapter parent, File file,
28: 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")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
37: }
38:
39: public boolean isSchema() {
40: String fileName = fFile.getName().toLowerCase(Locale.ENGLISH);
41: return fileName.endsWith(".exsd"); //$NON-NLS-1$
42: }
43:
44: public FileAdapter getParent() {
45: return fParent;
46: }
47:
48: public void setEditorId(String editorId) {
49: this .fEditorId = editorId;
50: }
51:
52: public String getEditorId() {
53: return fEditorId;
54: }
55:
56: public File getFile() {
57: return fFile;
58: }
59:
60: public boolean isDirectory() {
61: return fFile.isDirectory();
62: }
63:
64: public boolean hasChildren() {
65: if (fFile.isDirectory() == false)
66: return false;
67: if (fChildren == null)
68: createChildren();
69: return fChildren.length > 0;
70: }
71:
72: public Object[] getChildren() {
73: if (fFile.isDirectory() && fChildren == null)
74: createChildren();
75: return fChildren != null ? fChildren : new Object[0];
76: }
77:
78: private void createChildren() {
79: File[] files = fFile.listFiles();
80: fChildren = new Object[files.length];
81: for (int i = 0; i < files.length; i++) {
82: if (fFactory == null)
83: fChildren[i] = new FileAdapter(this, files[i], null);
84: else
85: fChildren[i] = fFactory.createAdapterChild(this,
86: files[i]);
87: }
88: }
89: }
|