Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346566 - NPE in SapphireDiagramEditorContextMenuProvider thus no Context menu shown
Summary: NPE in SapphireDiagramEditorContextMenuProvider thus no Context menu shown
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Sapphire (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Shenxue Zhou CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-19 20:44 EDT by Greg Amerson CLA
Modified: 2021-11-19 09:22 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.