我有一个Java项目,我需要创建一个窗口(可能使用SWT),提示用户选择当前工作区中已存在的文件。之后,它应该为用户创建所述文件(IFile)的实例以对其执行操作,即提取关于文件内容的信息。在这一点上,我有点无能为力......
感谢您的帮助!
答案 0 :(得分:0)
您永远不会实例化IFile
个实例,而是从IWorkspaceRoot
或另一个IContainer
申请一个路径。
http://help.eclipse.org/neon/topic/org.eclipse.platform.doc.isv/guide/resInt.htm?cp=2_0_10
答案 1 :(得分:0)
这就是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();