NullPointerException at ITransformableContentPart [message #1793763] |
Wed, 15 August 2018 07:46  |
Eclipse User |
|
|
|
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05717 seconds