0
我是eclipse插件开发新手。我写了一个代码,它获取了选定项目名称&的路径。但是,如果选择多个项目,则会列出第一个项目。检查是否选择多个项目
这里是我的代码
IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement != null) {
if (firstElement instanceof IAdaptable) {
IProject project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject.class);
IPath path = project.getFullPath();
IPath location = project.getLocation();
}
}
如何检查多个项目是否被选中呢?
它导致无限循环 – 2014-11-24 07:17:38
您可以查看迭代器(it)的大小并结束它。希望您使用“instanceOf IAdaptable”来查看是否选择了多个项目。 – hemanth 2014-11-24 07:56:30
您必须在循环中调用“it.next()”才能移动到每个新项目。 – 2014-11-24 08:14:12