Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346566

Summary: NPE in SapphireDiagramEditorContextMenuProvider thus no Context menu shown
Product: z_Archived Reporter: Greg Amerson <gregory.amerson>
Component: SapphireAssignee: Shenxue Zhou <shenxue.zhou>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: konstantin
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Greg Amerson CLA 2011-05-19 20:44:03 EDT
Right-clicking on diagram nodes in my editor will through NPE here:

java.lang.NullPointerException
at org.eclipse.sapphire.ui.swt.graphiti.editor.SapphireDiagramEditorContextMenuProvider.buildContextMenu(SapphireDiagramEditorContextMenuProvider.java:51)
at org.eclipse.gef.ContextMenuProvider.menuAboutToShow(ContextMenuProvider.java:63)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:338)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:469)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:465)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:491)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:241)
Comment 1 Greg Amerson CLA 2011-05-19 20:46:48 EDT
I looked a bit more and noticed that when I click on the different nodes the selectionChanged in the SapphireDiagramEditor it not working as I think it was intended.  

line 178 of SapphireDiagramEditor shows this:
if (activeEditor instanceof MultiPageEditorPart) {
    int activePage = ((MultiPageEditorPart) activeEditor).getActivePage();
    if (activePage != 0) {
        // Editor is active but the diagram sub editor is not
        // its active page
        editorIsActive = false;
    }
}

In my case (diagram editor is the 2nd page, so activePage will always == 1) the editorIsActive is set to false and so the selection is never selectionParts set and will stay null.
Comment 2 Greg Amerson CLA 2011-05-26 16:02:47 EDT
Here is what I have replaced in my workspace and it works as epxected and re-enables the context menu (no NPEs):

if ( activeEditor instanceof FormEditor ) {
					if ( !( this.equals( ( (FormEditor) activeEditor ).getActiveEditor() ) ) ) {
Comment 3 Shenxue Zhou CLA 2011-05-26 16:24:47 EDT
Greg, I've tried out your code snippet and it seemed to work for me (In my editor diagram is the first page).

I've checked your code in. Thanks!
Comment 4 Shenxue Zhou CLA 2011-05-26 16:26:46 EDT
The stack trace is no longer applicable.
I have submitted Greg's code snippet which should work for the case where the diagram editor is not the first page of a multipage editor.
Comment 5 Greg Amerson CLA 2011-05-26 16:45:18 EDT
Verified with latest build.
Comment 6 Konstantin Komissarchik CLA 2011-06-03 13:21:09 EDT
Closing.