本文介绍了限制ElementTreeSelectionDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现Workspace Browse
.我写下面的代码.
I wanna to implement Workspace Browse
. I write the below code.
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
Display.getDefault().getActiveShell(),
new WorkbenchLabelProvider(),
new BaseWorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.open();
如何将代码更改为仅包含显示的".ecore"文件的根元素(项目或文件夹)?当用户折叠任何根元素时,仅显示.ecore
个文件?
How can I change the code to only root elements (projects or folders) that contains ".ecore" file shown? And when the user collapse any root elements only .ecore
files shown?
推荐答案
您可以在对话框中添加查看器过滤器,以限制显示的内容.
You can add a viewer filter to the dialog to restrict what is shown.
dialog.addFilter(new FileExtensionFilter("ecore"));
添加一个过滤器.
文件扩展名过滤器如下所示:
A file extension filter would look something like:
public class FileExtensionFilter extends ViewerFilter {
private String fTargetExtension;
public FileExtensionFilter(String targetExtension) {
fTargetExtension = targetExtension;
}
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof IFile) {
return ((IFile)element).getName().toLowerCase().endsWith("." + fTargetExtension);
}
if (element instanceof IProject && !((IProject)element).isOpen())
return false;
if (element instanceof IContainer) { // i.e. IProject, IFolder
try {
IResource[] resources = ((IContainer)element).members();
for (IResource resource : resources) {
if (select(viewer, parent, resource))
return true;
}
} catch (CoreException e) {
// Ignore
}
}
return false;
}
}
这是基于org.eclipse.pde.internal.ui.util.FileExtensionFilter
这篇关于限制ElementTreeSelectionDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!