如何将文件与 Eclipse 插件中的透视图关联起来
我已经为 eclipse 创建了一个与文件扩展名 .eap 关联的编辑器插件,
我还创建了一个包含此数据视图的透视图。
我想添加以下行为:当我双击 .eap 文件时,我希望打开 EAP 透视图。
就像您第一次单击 Java 文件时所发生的情况一样。
任何帮助表示赞赏!
将要
try {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.showPerspective(EapPerspective.ID,
workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
I have created an editor plug-in for eclipse that is associated with the file extension .eap
I have also created a perspective that contains views for this data.
I would like to add the following behaviour: When I double click on the .eap file I'd like the EAP Perspective to be opened.
Just like what happens when you click on a Java file for the first time.
Any help appreciated!
Will
try {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.showPerspective(EapPerspective.ID,
workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,第一次点击或打开Java文件并不会打开Java透视图。然而,也许您在想,使用“新建 Java 类向导”后,如何提示您更改为 Java 透视图。
无论如何,您可以执行以下操作:
假设您已子类化
AbstractTextEditor
,则重写 setFocus() 方法并添加一些逻辑以更改为适当的视角,如下所示(但要小心添加特定的 null 检查):getEditorSite().getWorkbenchWindow().getWorkbench().showPerspective(desc.getId(),
getWindow(), pageInput);
推荐第一个解决方案,尽管它不会涵盖您要求的所有情况,而第二个解决方案有点顽皮,因为它违反了 Eclipse 约定。
As far as I know, clicking on or opening a Java file for the first time will not open the Java perspective. However, perhaps you are thinking about how after using the New Java Class Wizard, you are prompted to change to the Java perspective.
Regardless, there are several things that you can do:
Assuming that you have sub-classed
AbstractTextEditor
, then override thesetFocus()
method and add some logic to change to the appropriate perspective, something like this (but be careful to add specific null checks):getEditorSite().getWorkbenchWindow().getWorkbench().showPerspective(desc.getId(),
getWindow(), pageInput);
The first solution is recommended, although it will not cover all the cases that you are asking for, and the second is a bit naughty as it goes against Eclipse conventions.