Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Empty Selection after opened an editor
Empty Selection after opened an editor [message #1033482] Thu, 04 April 2013 05:19
Tommaso De Sica is currently offline Tommaso De Sica
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

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.
Previous Topic:Errors in Workspace
Next Topic:refresh properties view
Goto Forum:
  


Current Time: Tue Jul 29 02:45:01 EDT 2014

Powered by FUDForum. Page generated in 0.07058 seconds