blob: 1537a360e23846410fbbb835d1054b7f2390ea2f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.core;
import java.io.File;
import java.util.Locale;
import org.eclipse.core.runtime.PlatformObject;
public class FileAdapter extends PlatformObject {
private File file;
private Object[] children;
private FileAdapter parent;
private String editorId;
private IFileAdapterFactory factory;
/**
* Constructor for FileAdapter.
*/
public FileAdapter(FileAdapter parent, File file, IFileAdapterFactory factory) {
this.file = file;
this.parent = parent;
this.factory = factory;
}
public boolean isManifest() {
String fileName = file.getName();
return (fileName.equals("plugin.xml") || fileName.equals("fragment.xml") || fileName.equalsIgnoreCase("manifest.mf")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public boolean isSchema() {
String fileName = file.getName().toLowerCase(Locale.ENGLISH);
return fileName.endsWith(".mxsd") || fileName.endsWith(".exsd"); //$NON-NLS-1$ //$NON-NLS-2$
}
public FileAdapter getParent() {
return parent;
}
public void setEditorId(String editorId) {
this.editorId = editorId;
}
public String getEditorId() {
return editorId;
}
public File getFile() {
return file;
}
public boolean isDirectory() {
return file.isDirectory();
}
public boolean hasChildren() {
if (file.isDirectory() == false)
return false;
if (children == null)
createChildren();
return children.length > 0;
}
public Object[] getChildren() {
if (file.isDirectory() && children == null)
createChildren();
return children != null ? children : new Object[0];
}
private void createChildren() {
File[] files = file.listFiles();
children = new Object[files.length];
for (int i = 0; i < files.length; i++) {
if (factory==null)
children[i] = new FileAdapter(this, files[i], null);
else
children[i] = factory.createAdapterChild(this, files[i]);
}
}
}
|