简体   繁体   English

Eclipse插件:如何查找用户从哪个View打开了对话框?

[英]Eclipse plugin: How to find from which View the user opened a Dialog?

I know how to find out whether a View like the "Project Explorer" is open in Eclipse. 我知道如何确定像“ Project Explorer”这样的View是否在Eclipse中打开。 But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View? 但是,如何确定用户是从“ z / OS Projects”视图还是从“ Project Explorer”视图打开对话框?

On base of the result, I need to locate a file in the current active View. 根据结果​​,我需要在当前活动的View中找到一个文件。 This part I got covered already. 我已经覆盖了这一部分。

In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event. 在扩展AbstractHandler的处理程序类中,可以使用HandlerUtil方法从执行事件中获取各种信息。

For the current selection you can use: 对于当前选择,您可以使用:

IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);

where event is the ExecutionEvent passed to the handler. 其中event是传递给处理程序的ExecutionEvent

To get any resource (such as an IFile ) contained in the selection use: 要获取选择中包含的任何资源(例如IFile ),请使用:

IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);

(you may also be able to adapt directly to IFile ). (您也可以直接适应IFile )。

Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. 注意: getCurrentStructuredSelectionAdapters仅在相当新的Eclipse版本中。 For older versions the code is a little more complex. 对于较旧的版本,代码要复杂一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM