Find Project locations in Project Explorer (Eclipse)(在 Project Explorer (Eclipse) 中查找项目位置)
问题描述
我在上下文菜单中添加了一个按钮,仅当您在项目资源管理器窗口中单击鼠标右键时才会执行.我希望能够在 Project Explorer 窗口中抓取每个项目并抓取 ProjectName 和 ProjectLocation 并将其单独放入一个对象中并返回新的对象数组.
I've added a button in the context menu to execute only when you right click in the Project Explorer window. I want to be able to grab each project in the Project Explorer window and grab the ProjectName and ProjectLocation and put that into an object by itself and return the new array of objects.
我找不到访问所需信息的方法.
I can't find a way to access the information that I need.
插件.xml
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
<command commandId="helloworld.sample"
label="Hello World" style="push">
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command defaultHandler="helloworld.handler.samplehandler"
id="helloworld.sample" name="Sample">
</command>
</extension>
samplehandler.java
samplehandler.java
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart viewpart = page.findView("org.eclipse.ui.navigator.ProjectExplorer");
Tree tree = (Tree) ((TreeViewer) viewpart.getSite().getSelectionProvider()).getControl();
TreeItem[] selTree = tree.getSelection();
我觉得好像 tree 或 selTree 会有我想要的信息,但我找不到.有什么帮助吗?
I feel as though tree or selTree would have the information I want but I can't find it. Any help?
推荐答案
使用来自选择提供者的选择数据:
Use the selection data from the selection provider:
IStructuredSelection sel =
(IStructuredSelection)viewpart.getSite().getSelectionProvider().getSelection();
Object selObj = sel.getFirstElement();
IProject project =
(IProject)Platform.getAdapterManager().getAdapter(selObj, IProject.class);
... might return null if selection is not the project
String name = project.getName();
IPath location = project.getLocation();
要让所有项目使用:
IWorkspace workspace = ResourcesPlugin.getPlugin().getWorkspace();
IProject [] projects = workspace.getRoot().getProjects();
这篇关于在 Project Explorer (Eclipse) 中查找项目位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Project Explorer (Eclipse) 中查找项目位置
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01