Goodmorning everyone,
I've got a perspective with 2 views and I use SelectionService to get the selected object from one of these (doubleclick event).
If I use this selection to open an editor on selected object I've got this problem: once the editor is open the selection is empty and if I try to double-click on other objects I'll receive NullPointerException.
If I try to debug, selection is never empty and all goes fine (could be a synchronization problem?)
Here are some hot code parts:
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final E objectToBeEditedEObject = getObjectToBeEdited();
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
final IEditorInput editorInput = retrieveEditorInput(page, objectToBeEditedEObject);
page.openEditor(editorInput, getEditorId());
} catch (final PartInitException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
protected MyType getObjectToBeEdited() {
return (MyType) getCurrentSelection();
}
protected Object getCurrentSelection() {
final StructuredSelection selection=(StructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
Object toReturn = selection.getFirstElement();
return toReturn;
}
Thanks for you help.