Eclipse RCP - 选择项目(包资源管理器)
如何检索所选项目的名称和路径? (包资源管理器)
示例:c:\project\test\projectName
有人有一些代码解释了如何完成我获取工作区中特定项目的项目名称或完整路径?
How do I retrieve the name and path of the project selected? (Package Explorer)
example: c:\project\test\projectName
someone has some code that explains how to complete I get the project name or full path of a particular project in my workspace?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Eclipse 定义扩展点
"org.eclipse.ui.navigator.linkHelper"
如果您向这些 EP 贡献一个类,则必须实现 ILinkHelper
当在资源管理器中选择某些内容时,ILInkHelper 界面会通知您
您可以检查选择的类型
Eclipse defines an extension point
"org.eclipse.ui.navigator.linkHelper"
If you contribute a class to these EP you have to implement ILinkHelper
The ILInkHelper interface notifies you, when something was selected in the explorer
You can check the type of the selection
旧的记忆,但也许对你有用。我猜包资源管理器提供了它的选择,因此您可以通过调用以下方式获取代码中的当前选择:
ISelectionService service = getSite().getWorkbenchWindow().getSelectionService()
比您可以通过其 id 获取包资源管理器视图(plugin.xml有关更多详细信息):
IStructuredSelection choice = (IStructuredSelection) service.getSelection("org.eclipse.jdt.ui.PackageExplorer");
请注意,据我所知,您始终可以安全地将 ISelection 转换为 IStructuredSelection。然后调用 Structured.getFirstElement() ,我认为第一个元素将是一个 IFile 对象。我希望我的“伪代码”对你来说足够了。 IFile 有很多有用的方法,方便您使用
Old memories but maybe useful for you. I guess package explorer provides its selection, so you can get the current selection in your code by calling:
ISelectionService service = getSite().getWorkbenchWindow().getSelectionService()
than you can get the package explorer view by its id (plugin.xml for more details):
IStructuredSelection selection = (IStructuredSelection) service.getSelection("org.eclipse.jdt.ui.PackageExplorer");
Please note AFAIK you can always safely cast ISelection to IStructuredSelection. Then call structured.getFirstElement() and I think the first element will be an IFile object. I hope my "pseudo code" whould be enough for you. And IFile has lots of usefule methods for your convenience