简体   繁体   中英

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. But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View?

On base of the result, I need to locate a file in the current active 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.

For the current selection you can use:

IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);

where event is the ExecutionEvent passed to the handler.

To get any resource (such as an IFile ) contained in the selection use:

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

(you may also be able to adapt directly to IFile ).

Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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