如何以编程方式更改包资源管理器中的选择 [英] How to programmatically change the selection within package explorer

查看:163
本文介绍了如何以编程方式更改包资源管理器中的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个eclipse的插件,用于分析Eclipse Workspace中项目之间的依赖关系和引用,并以类似UML的方式将其显示在自己的View中。



为了增加我的插件的有用性,我希望通过允许用户在软件包资源管理器中打开一个项目,并在编辑器中打开它,在图表上添加交互性。



但是,我的问题是,虽然我知道如何从包资源管理器获取给定的选择,但我无法找到一种方法来更改选择或只是在包中打开一个项目有没有人可以解决这个问题?

解决方案



p>我找到了解决方案。 Eclipse确实提供了直接访问 org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart 中的软件包浏览器,但不鼓励。

  import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; 

...

PackageExplorerPart part = PackageExplorerPart.getFromActivePerspective();
在资源管理器中选择的任何IResource * /;

part.selectAndReveal(resource);

这将突出显示IResource 资源必要时展开树。


I am currently developing a plugin for eclipse that analyzes dependencies and references between projects within the Eclipse Workspace and displays them in its own View in a UML-like diagram.

To increase the usefulness of my plugin, I wish to add interactivity to the diagram by allowing users to open a project in the package explorer and if applicable open it in an editor by clicking on the graph displayed.

However, my problem is that while I know how to obtain a given selection from the package explorer, I have not been able to find a way to change the selection or simply open up a project in the package explorer programmatically.

Does anyone have a solution for this problem?

解决方案

I have found the solution. Eclipse does offer direct access to the package explorer in org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart , but it is discouraged.

import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;

...

PackageExplorerPart part= PackageExplorerPart.getFromActivePerspective();
IResource resource =  /*any IResource to be selected in the explorer*/;

part.selectAndReveal(resource);

This will highlight whatever IResource resource is and expand the tree as necessary.

这篇关于如何以编程方式更改包资源管理器中的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆