Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef-dev] RoutingConstraint initialisation order problem gives null bendpoints for EDiagram example

Hi Pratik

Selecting a Link in EDiagram frequently results in a NPE becuase there is an initialisation order problem in
EDiagramEditor.initializeGraphicalViewer().

The viewer.setContents(diagram) line provokes a refresh that causes

void refreshVisuals() {
	getConnectionFigure().setRoutingConstraint(getLink().getBendpoints());
}

in LinkEditPart to set the routing constraint on the NullRouter since it is not till a few lines later
that EDiagramEditor.initializeGraphicalViewer() invokes connLayer.setConnectionRouter(router);

Therefore when a Link is selected and nothing has triggered another refreshVisuals()
BendpointEditPolicy barfs on a null bendpoints.

Adding a forced refresh at the end of initializeGraphicalViewer() doesn't work because
the smarts suppress the 'redundant' refresh propagation.

The following addition to LinkEditPart solves the problem by making LinkEditPart
listen for the PROPERTY_CONNECTION_ROUTER change.

protected PropertyChangeListener propertyChangeListener = null;

protected void setFigure(IFigure figure) {
	if (this.figure != figure) {
		if ((this.figure != null) && (propertyChangeListener != null))
			figure.removePropertyChangeListener(propertyChangeListener);
		super.setFigure(figure);
		if (this.figure != null) {
			if (propertyChangeListener == null)
				propertyChangeListener = new PropertyChangeListener() {					
					public void propertyChange(PropertyChangeEvent evt) {
						if (evt.getPropertyName() == Connection.PROPERTY_CONNECTION_ROUTER)
							refreshVisuals();
					}};
			figure.addPropertyChangeListener(propertyChangeListener);
		}
	}
}

I doubt this is the most appropriate solution, and it may have leakage issues, but at least
it enables me to proceed, and perhaps enables you to do it better.

    Regards

        Ed Willink 



Back to the top