I'm migrating Eclipse views to using the e4 framework, currently we use Ecipse 4.4.1 in compability mode.
In most views I'm setting the selection provider of the site:
site.setSelectionProvider(treeViewer);
In different handlers I then use code like this to get the selection:
IWorkbenchSite site = HandlerUtil.getActiveSite(event);
ISelectionProvider selectionProvider = site.getSelectionProvider();
ISelection selection = selectionProvider.getSelection();
Some handler even use the selection provider and if it is Viewer work with it eg refersh, expand...
ISelectionProvider selectionProvider = activeSite.getSelectionProvider();
if (selectionProvider instanceof StructuredViewer) {
...
}
The wiki describes how to handle selections new in e4. https://wiki.eclipse.org/E4/EAS/Selection
What I can't find is a way to migrate using the actual selection provider?
In an e4 handler you use something like:
@Execute
void execute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection
{
...
}
to get the active selection.
If you want to look at the active part you can use:
@Execute
void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart)
{
Object object = activePart.getObject();
// 'object' is the class you defined for the part in the Application.e4xmi
}
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.