Bug 290531

Summary: DEFAULT_TARGET_ANCHOR (and DEFAULT_SOURCE_ANCHOR) should be made public
Product: [Tools] GEF Reporter: Jens Von Pilgrim <developer>
Component: GEF-Legacy GEF (MVC)Assignee: gef-inbox <gef-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 3.5   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Jens Von Pilgrim CLA 2009-09-25 08:53:14 EDT
The default anchors used by AbstractConnectionEditPart.getTarget/SourceConnectionAnchor(), i.e.
DEFAULT_TARGET_ANCHOR and DEFAULT_SOURCE_ANCHOR resp., should be made public. As stated in bug #29919  (https://bugs.eclipse.org/29919), these anchors are "only there to let the
developer know that something went wrong". Now, it is impossible to check that if the instance cannot be retrieved. E.g, it is impossible to do something like that in a derived class:

ConnectionAnchor anchor = super.getTargetConnectionAnchor();
if (anchor==DEFAULT_TARGET_ANCHOR) {
    .... // something went wrong
}

Background: I need this for a 3D version of AbstractConnectionEditPart, because in case of 3D (in the GEF3D project) the default anchors must be 3D anchors.  I certainly could copy the original behaviour or getTargetConnectionAnchor() and simply return a DEFAULT_TARGET_ANCHOR_3D instead of a 2D version (which I have to do as a workaround), but I would prefer to copy as little as possible -- and I also think it's a general issue.

Cheers

Jens

BTW: Maybe it would be a good idea to make these default anchors immutable as well, as they could be changed even when they are private. 

Here is an immutable version:

/**
 * ImmutableXYAnchor used for default anchors, all setters are overridden
 * to avoid changing an instance of this class.
 *
 * @author 	Jens von Pilgrim
 * @since 	Sep 25, 2009
 */	
public class ImmutableXYAnchor extends XYAnchor {

	/**
	 * Creates an immutable xy anchor with the given location.
	 * @param i_p
	 */
	public ImmutableXYAnchor(Point i_p) {
		super(i_p);
	}

	/** 
	 * As this class is immutable, this method throws an
	 * {@link UnsupportedOperationException}.
	 * @see org.eclipse.draw2d.XYAnchor#setLocation(org.eclipse.draw2d.geometry.Point)
	 */
	@Override
	public void setLocation(Point i_p) {
		throw new UnsupportedOperationException("Anchor is immutable");
	}

	/** 
	 * As this class is immutable, no events will ever been thrown.
	 * Thus, this method does nothing.
	 * @see org.eclipse.draw2d.ConnectionAnchorBase#addAnchorListener(org.eclipse.draw2d.AnchorListener)
	 */
	@Override
	public void addAnchorListener(AnchorListener i_listener) {
	}
}