Eclipse RCP - 选择项目(包资源管理器)

发布于 2024-12-12 06:50:01 字数 121 浏览 3 评论 0原文

如何检索所选项目的名称和路径? (包资源管理器)

示例: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑看君怀她人 2024-12-19 06:50:02

Eclipse 定义扩展点
"org.eclipse.ui.navigator.linkHelper"

如果您向这些 EP 贡献一个类,则必须实现 ILinkHelper

当在资源管理器中选择某些内容时,ILInkHelper 界面会通知您

  • public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection)

您可以检查选择的类型

 if (aSelection.getFirstElement() instanceof IFile) {
    // Do something
 }

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

  • public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection)

You can check the type of the selection

 if (aSelection.getFirstElement() instanceof IFile) {
    // Do something
 }
表情可笑 2024-12-19 06:50:02

旧的记忆,但也许对你有用。我猜包资源管理器提供了它的选择,因此您可以通过调用以下方式获取代码中的当前选择:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文