Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » NPE when initialising GraphicalEditor
NPE when initialising GraphicalEditor [message #668200] Wed, 04 May 2011 09:33 Go to next message
Pewterfish  is currently offline Pewterfish
Messages: 2
Registered: May 2011
Junior Member
Hi folk,

I'm attempting to build a GEF-based model editor in an RCP application, and hitting a little trouble. I'm following the guide located at http://www.ibm.com/developerworks/library/os-eclipse-gef11/ (this is my first GEF project), and it's mostly been pretty straightforward. However, now I've finished defining editparts and writing figure drawing code, and it's time to pull it all together... and it doesn't work.

I've subclassed GraphicalEditor to create an editor (at the moment I'm just giving it an EditPartFactory and a Model, as recommended in the IBM tutorial), and am displaying it on a View. However, when I try to instantiate this editor, I get a null-pointer exception in GraphicallEditor.hookGraphicalViewer(), which appears to be coming from a getSite() call that returns null. The entire stack trace is posted below.

I'm using Eclipse Helios and GEF 3.7.0 (upgraded from 3.6.2 in the hopes of a bugfix that didn't materialise).

Can anyone shed any light on what's going wrong here? I'm a fairly experienced Java programmer but am comparatively new to Eclipse RCP/GEF, so I suspect I'm making a simple but non-obvious mistake Confused

Quote:
java.lang.NullPointerException
at org.eclipse.gef.ui.parts.GraphicalEditor.hookGraphicalViewer (GraphicalEditor.java:332)
at org.eclipse.gef.ui.parts.GraphicalEditor.createGraphicalView er(GraphicalEditor.java:157)
at org.eclipse.gef.ui.parts.GraphicalEditorWithPalette.createPa rtControl(GraphicalEditorWithPalette.java:63)
at gefexperiment.ReqAnalyserView.createPartControl(ReqAnalyserV iew.java:36)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewR eference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReferen ce.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(Workb enchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:31 3)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:52 9)
at org.eclipse.ui.internal.presentations.PresentablePart.setVis ible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFo lder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrd er.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresen tation.selectPart(TabbedStackPresentation.java:473)
(...and so on back to org.eclipse.equinox.launcher.Main)
Re: NPE when initialising GraphicalEditor [message #668251 is a reply to message #668200] Wed, 04 May 2011 12:41 Go to previous messageGo to next message
Eclipse User
Originally posted by: tmicko.gmail.com

If it's your first touch with GEF, consider moving to GMF, framework
built on top of GEF. GEF is no longer evolving, but GMF is still
evolving quite fast and it provides many better features than GEF.

Tomas
Re: NPE when initialising GraphicalEditor [message #668280 is a reply to message #668200] Wed, 04 May 2011 15:41 Go to previous messageGo to next message
Eclipse User
Originally posted by: tmicko.gmail.com

Regarding your NPE, try to post the code of the first two method where
it is throwed (hookGraphicalViewer() and createGraphicalViewer()),
because it's hard to tell what could be wrong.

Tomas
Re: NPE when initialising GraphicalEditor [message #668376 is a reply to message #668200] Thu, 05 May 2011 09:27 Go to previous messageGo to next message
Pewterfish  is currently offline Pewterfish
Messages: 2
Registered: May 2011
Junior Member
The first two methods in which the exception is thrown are both methods of GraphicalEditor, a GEF-provided class that I'm extending to create my own editor, as recommended in the documentation. I suspect there's something else going on, but the relevant code is quoted below:

	/**
	 * Hooks the GraphicalViewer to the rest of the Editor. By default, the
	 * viewer is added to the SelectionSynchronizer, which can be used to keep 2
	 * or more EditPartViewers in sync. The viewer is also registered as the
	 * ISelectionProvider for the Editor's PartSite.
	 */
	protected void hookGraphicalViewer() {
		getSelectionSynchronizer().addViewer(getGraphicalViewer());
		getSite().setSelectionProvider(getGraphicalViewer());
	}


	/**
	 * Creates the GraphicalViewer on the specified <code>Composite</code>.
	 * 
	 * @param parent
	 *            the parent composite
	 */
	protected void createGraphicalViewer(Composite parent) {
		GraphicalViewer viewer = new ScrollingGraphicalViewer();
		viewer.createControl(parent);
		setGraphicalViewer(viewer);
		configureGraphicalViewer();
		hookGraphicalViewer();
		initializeGraphicalViewer();
	}


Also, I'll have a look at GMF, but all the examples I've seen to date appear at best overcomplicated for my needs. I'm open to being wrong, of course, maybe I've not yet found the right example.
Re: NPE when initialising GraphicalEditor [message #671587 is a reply to message #668376] Wed, 18 May 2011 08:21 Go to previous message
Girish Kumar is currently offline Girish Kumar
Messages: 22
Registered: May 2011
Junior Member
Hi Saurabh ,

Google with the key word "GEF tutorial pdf"

click on the first result itself (something like this is will be [PDF]
GEF c'est le futur)

Read this document it is very simple than other document ,which you are reading currently
Previous Topic:One-click drag of the endpoint of a connector
Next Topic:z-order of children edit parts
Goto Forum:
  


Current Time: Tue Jul 22 19:46:38 EDT 2014

Powered by FUDForum. Page generated in 0.02075 seconds