import org.eclipse.swt.widgets.TreeItem; //导入方法依赖的package包/类
/**
* Get the basic class path and replace the first class path entry
* with it.
*/
protected void getCurrentClassPath() {
// Get the current class path.
if (this.directoryTree.getSelection().length > 0) {
String newEntry = "";
TreeItem item = this.directoryTree.getSelection()[0];
Object data = item.getData();
if (data instanceof JarFileEntry) {
// just add the jar file as the class path entry
JarFileEntry jfe = (JarFileEntry) data;
JarFile jf = jfe.getJarFile();
newEntry = jf.getName();
this.currentClassPackage = jfe.getFileName().replace("/", ".").replace("\\", ".");
} else if (data instanceof File && ((File) data).isFile()) {
// It is just a single file, so add the path to it.
newEntry = ((File) data).getPath();
this.currentClassPackage = "";
} else {
// Try to find out if we are somewhere in a structure with a root dir "bin". Otherwise just add the current dir.
String fullPath = "";
boolean resetClassPackage = true;
while (item != null) {
fullPath = item.getText() + "/" + fullPath;
if (item.getText().toLowerCase().equals("bin")) {
fullPath = fullPath.replace("/", ".").replace("\\", ".");
if (fullPath.contains(".")) {
fullPath = fullPath.substring(fullPath.indexOf(".") + 1);
}
this.currentClassPackage = fullPath;
resetClassPackage = false;
fullPath = "/bin"; // Forget where this leads to.
}
item = item.getParentItem();
}
if (resetClassPackage) {
this.currentClassPackage = "";
}
fullPath = fullPath.replace("\\/", "/");
fullPath = fullPath.replace("\\", "/");
fullPath = fullPath.replace("//", "/");
newEntry = fullPath;
if (!newEntry.substring(newEntry.length() - 1).equals("/")) newEntry += "/";
}
// Set the entry.
if (Options.getInst().classPathEntries.size() == 0) {
Options.getInst().classPathEntries.add(newEntry);
} else {
Options.getInst().classPathEntries.set(0, newEntry);
}
// Update the classLoader.
this.classLoader.updateClassPath(StaticGuiSupport.arrayList2StringArray(Options.getInst().classPathEntries), !Options.getInst().doNotClearClassLoaderCache);
}
}