Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can retrieve the current workbench selection <strike>using two methods</strike> with the following code:</p> <p><strike></p> <ol> <li>through the Workbench <a href="http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html" rel="nofollow">SelectionService</a></li> <li><code>getViewSite().getSelectionProvider().getSelection()</code></li> </ol> <p></strike></p> <p><code>getViewSite().getWorkbenchWindow().getSelectionService()</code></p> <p>You can find more information in <a href="http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html" rel="nofollow">this article</a>.</p> <p>Using the global workbench selection is the better approach, because it enables your view to get selection from everywhere, which is something the user might expect (I at least do). Also, almost all of the views in Eclipse (and I don't know exceptions to this rule) are using this approach.</p> <p>If you absolutely must to tie your view to another view, then you can get all <code>IWorkbenchPage</code> iterate over them and search for the view by its ID and when you find the view, you call get its <code>SelectionProvider</code> to get the selection.</p> <p>Only by reading this explanation, makes my hair go straight up. Considering that there might be multiple instances of the same view, you can end up with a selection from a random view. I'm not sure whether the user will make sense of how things work, unless you have some clear rules, which exactly view you need. It is up to you.</p> <p>`</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload