我有一个Java项目,我需要创建一个窗口(可能使用SWT),提示用户选择当前工作区中已存在的文件。之后,它应该为用户创建一个所述文件(IFile)的实例来对其执行操作,即提取关于文件内容的信息。我有点无知在这一点上...为Eclipse工作区中存在的文件创建一个IFile
感谢您的帮助!
我有一个Java项目,我需要创建一个窗口(可能使用SWT),提示用户选择当前工作区中已存在的文件。之后,它应该为用户创建一个所述文件(IFile)的实例来对其执行操作,即提取关于文件内容的信息。我有点无知在这一点上...为Eclipse工作区中存在的文件创建一个IFile
感谢您的帮助!
这就是ElementTreeSelectionDialog
用于制造。 您可以使用它,例如像这样:
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
shell, new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setTitle("File selection");
dialog.setMessage("Choose a file");
dialog.setAllowMultiple(false);
// ...
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return true; // adapt to your need
}
});
dialog.open();
IFile selectedFile = (IFile) dialog.getFirstResult();
你永远不会实例化一个IFile
实例,你请求一个从IWorkspaceRoot
或另一个的路径。
http://help.eclipse.org/neon/topic/org.eclipse.platform.doc.isv/guide/resInt.htm?cp=2_0_10
我明白了,现在。谢谢你的帮助! –
这正是我需要的!万分感谢! –