Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » NullPointerException at ITransformableContentPart
NullPointerException at ITransformableContentPart [message #1793763] Wed, 15 August 2018 11:46 Go to next message
Robert Stelzmann is currently offline Robert StelzmannFriend
Messages: 3
Registered: July 2018
Junior Member
Hey guys,

I'm quite new to GEF5 and I'm currently working through the "Getting started with GEF" (at the Itemis website; sorry, I'm not yet allowed to place foreign links in this forum). I've successfully managed to complete the second part of the tutorial and implemented a simple diagram with the capability to translate and resize my nodes. Afterwards I started to migrate this diagram to our Eclipse RCP project (and removed the "resize" capability) and now I'm continuously getting NullPointerExceptions on ITransformableContentPart.

java.lang.NullPointerException
	at org.eclipse.gef.mvc.fx.parts.ITransformableContentPart.setVisualTransform(ITransformableContentPart.java:94)
	at com.durr.ecopro.editor.diagram.parts.OperatorPart.doRefreshVisual(OperatorPart.java:51)


Here you can see the implementation of doRefreshVisual of the problematic GEF-Part.
    @Override
    protected void doRefreshVisual(final OperatorVisual visual) {
        final OperatorRepresentation operator = getContent();
        visual.setName(operator.getOperator().getName());

        visual.setPrefSize(operator.getBounds().getWidth(), operator.getBounds().getHeight());
        visual.getParent().layout();

        setVisualTransform(getContentTransform());
    }


I've also implemented the ITransformableContentPart interface likewise in the aforementioned tutorial.
    @Override
    public Affine getContentTransform() {
        final Rectangle bounds = getContent().getBounds();
        return new Affine(new Translate(bounds.getX(), bounds.getY()));
    }

    @Override
    public void setContentTransform(final Affine totalTransform) {
        // storing the new position
        final Rectangle bounds = getContent().getBounds().getCopy();
        bounds.setX(totalTransform.getTx());
        bounds.setY(totalTransform.getTy());
        getContent().setBounds(bounds);
    }


My module implementation is also more or less a copy of the tutorial temlate.
public class DiagramModule extends MvcFxModule {

    @Override
    protected void configure() {
        super.configure();

        bindIContentPartFactory();

        bindOperatorPartAdapters(AdapterMaps.getAdapterMapBinder(binder(), OperatorPart.class));
    }

    protected void bindOperatorPartAdapters(final MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
        // provides a hover feedback to the shape, used by the HoverBehavior
        AdapterKey<?> role = AdapterKey.role(DefaultHoverFeedbackPartFactory.HOVER_FEEDBACK_GEOMETRY_PROVIDER);
        adapterMapBinder.addBinding(role).to(ShapeOutlineProvider.class);

        // provides a selection feedback to the shape
        role = AdapterKey.role(DefaultSelectionFeedbackPartFactory.SELECTION_FEEDBACK_GEOMETRY_PROVIDER);
        adapterMapBinder.addBinding(role).to(ShapeBoundsProvider.class);

        // support moving nodes via mouse drag
        adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
        adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TranslateSelectedOnDragHandler.class);
    }

    protected void bindIContentPartFactory() {
        binder().bind(IContentPartFactory.class).to(AnalysisDiagramPartFactory.class);
    }

    @Override
    protected void bindAbstractContentPartAdapters(final MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
        super.bindAbstractContentPartAdapters(adapterMapBinder);

        // binding the HoverOnHoverPolicy to every part
        // if a mouse is moving above a part it is set i the HoverModel
        adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(HoverOnHoverHandler.class);

        // add the focus and select policy to every part, listening to clicks
        // and changing the focus and selection model
        adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(FocusAndSelectOnClickHandler.class);
    }

    @Override
    protected void bindIRootPartAdaptersForContentViewer(final MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
        super.bindIRootPartAdaptersForContentViewer(adapterMapBinder);

        // binding a Hover Behavior to the root part. it will react to
        // HoverModel changes and render the hover part
        adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(HoverBehavior.class);
    }

}


Any suggestions?
Re: NullPointerException at ITransformableContentPart [message #1793766 is a reply to message #1793763] Wed, 15 August 2018 12:50 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Robert,

the root of the problem should be that OperatorPart does not have a TRANSFORM_PROVIDER (adapter) when setVisualTransform() is called, i.e. the getAdapter() call inside setVisualTransform() returns null. This should be easy to validate.

Possible causes of the top of my head:
- OperatorPart does not extend AbstractContentPart
- OperatorPart is not constructed using the Injector
- OperatorPart#doRefreshVisual() is called explicitly in a place where setup is not yet complete

Best regards,
Matthias
Re: NullPointerException at ITransformableContentPart [message #1793770 is a reply to message #1793766] Wed, 15 August 2018 13:04 Go to previous message
Robert Stelzmann is currently offline Robert StelzmannFriend
Messages: 3
Registered: July 2018
Junior Member
Hi Matthias,

that was my mistake:
Matthias Wienand wrote on Wed, 15 August 2018 12:50
- OperatorPart is not constructed using the Injector


Thank you so much for the hint! :-)

Best regards,
Robert
Previous Topic:[GEF4] Multiple selection performance problem
Next Topic:GEF/ZEST more complex examples/projects
Goto Forum:
  


Current Time: Fri Apr 19 23:39:33 GMT 2024

Powered by FUDForum. Page generated in 0.02728 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top