Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Bendpoint creation is hit or miss
Bendpoint creation is hit or miss [message #777113] Mon, 09 January 2012 17:41 Go to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
I implemented bendpoints in conjunction with ShortestPathConnectionRouter. They work, however snapping bendpoint off connection is hit or miss - when I mouse over bendpoint handle and try to drag it, first time nothing happens and second or third time snap works. It's takes 2-3 tried (sometimes more) in order to snap, in logic example this works flawlessly. What could be the problem?

Thanks,
Alex
Re: Bendpoint creation is hit or miss [message #778247 is a reply to message #777113] Wed, 11 January 2012 17:27 Go to previous messageGo to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
Code for bendpoints was adapted from Logic example. The only extra thing I have is EMF base classes for Relation (Wire) and Bendpoint so that information about model is persisted in EMF. This is example of Bendpoint implementation:

public class RelationBendpoint extends BendpointTypeImpl implements Bendpoint {

	private float weight = 0.5f;
	private DimensionType firstRelativeDimension, secondRelativeDimension;

	public RelationBendpoint() {
	}

	public Dimension getFirstRelativeDimension() {
		return new Dimension(firstRelativeDimension.getX(), firstRelativeDimension.getY());
	}

	public Point getLocation() {
		return null;
	}

	public Dimension getSecondRelativeDimension() {
		return new Dimension(secondRelativeDimension.getX(), secondRelativeDimension.getY());
	}

	public float getWeight() {
		return weight;
	}

	public void setRelativeDimensions(Dimension firstRelativeDimension, Dimension secondRelativeDimension) {
		this.firstRelativeDimension = dimensionToDimensionType(firstRelativeDimension);
		this.secondRelativeDimension = dimensionToDimensionType(secondRelativeDimension);
		getDimension().add(this.firstRelativeDimension);
		getDimension().add(this.secondRelativeDimension);
	}
	
	private DimensionType dimensionToDimensionType(Dimension dimension){
		DimensionType dimensionType = ModelFactory.eINSTANCE.createDimensionType();
		dimensionType.setX(dimension.width);
		dimensionType.setY(dimension.height);
		
		return dimensionType;
	}

	public void setWeight(float w) {
		weight = w;
	}

}
Re: Bendpoint creation is hit or miss [message #778248 is a reply to message #778247] Wed, 11 January 2012 17:40 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander Nyssen
Messages: 40
Registered: July 2009
Location: L√ľnen
Member
Well, I fear that code does not give much insight. Could you in addition post your EditPolicy?
Re: Bendpoint creation is hit or miss [message #778256 is a reply to message #778248] Wed, 11 January 2012 20:54 Go to previous messageGo to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
Alexander Nyssen wrote on Wed, 11 January 2012 17:40
Well, I fear that code does not give much insight. Could you in addition post your EditPolicy?


Here is bendpoint edit policy:

public class RelationBendpointEditPolicy extends BendpointEditPolicy {

	protected Command getCreateBendpointCommand(BendpointRequest request) {
		CreateBendpointCommand com = new CreateBendpointCommand();
		Point p = request.getLocation();
		Connection conn = getConnection();

		conn.translateToRelative(p);

		com.setLocation(p);
		Point ref1 = getConnection().getSourceAnchor().getReferencePoint();
		Point ref2 = getConnection().getTargetAnchor().getReferencePoint();

		conn.translateToRelative(ref1);
		conn.translateToRelative(ref2);

		com.setRelativeDimensions(setRelativeDimension(p.getDifference(ref1)), setRelativeDimension(p.getDifference(ref2)));
		com.setRelation(getRelation(request));
		com.setIndex(request.getIndex());
		return com;
	}

	protected Command getMoveBendpointCommand(BendpointRequest request) {
		MoveBendpointCommand com = new MoveBendpointCommand();
		Point p = request.getLocation();
		Connection conn = getConnection();

		conn.translateToRelative(p);

		com.setLocation(p);

		Point ref1 = getConnection().getSourceAnchor().getReferencePoint();
		Point ref2 = getConnection().getTargetAnchor().getReferencePoint();

		conn.translateToRelative(ref1);
		conn.translateToRelative(ref2);

		com.setRelativeDimensions(setRelativeDimension(p.getDifference(ref1)), setRelativeDimension(p.getDifference(ref2)));
		com.setRelation(getRelation(request));
		com.setIndex(request.getIndex());
		return com;
	}
	
	private DimensionType setRelativeDimension(Dimension dimension){
		DimensionType d = ModelFactory.eINSTANCE.createDimensionType();
		d.setX(dimension.width);
		d.setY(dimension.height);
		return d;
	}

	protected Command getDeleteBendpointCommand(BendpointRequest request) {
		BendpointCommand com = new DeleteBendpointCommand();
		Point p = request.getLocation();
		com.setLocation(p);
		com.setRelation(((ObjectConnection)request.getSource().getModel()).getEMFModel());
		com.setIndex(request.getIndex());
		return com;
	}
	
	private RelationType getRelation(BendpointRequest request){
		return ((ObjectConnection)request.getSource().getModel()).getEMFModel();
	}

}

Re: Bendpoint creation is hit or miss [message #778361 is a reply to message #778256] Thu, 12 January 2012 10:39 Go to previous messageGo to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
I was debugging the chain of calls and I think I narrowed down problem to SimpleDragTracker. In method handleDragInProgress():
protected boolean handleDragInProgress() {
	if (isInDragInProgress()) {
		updateSourceRequest();
		showSourceFeedback();
		setCurrentCommand(getCommand());
	}
	return true;
}

isInDragInProgress() returns false when I am not able to drag the bendpoint handle.
Re: Bendpoint creation is hit or miss [message #778370 is a reply to message #778361] Thu, 12 January 2012 11:01 Go to previous messageGo to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
Some more debugging shows that when isInDragInProgress() is called and drag of bendpoint fails method isInState(int state) calling getState() returns AbstractTool.STATE_DRAG which says: "The state indicating that one or more buttons are pressed, but the user has not moved past the drag threshold. Many tools will do nothing during this state but wait until {@link #STATE_DRAG_IN_PROGRESS} is entered.", which makes sense in what I am seeing here with bendpoints not being created, but why is this happening?
Re: Bendpoint creation is hit or miss [message #778385 is a reply to message #778370] Thu, 12 January 2012 12:14 Go to previous messageGo to next message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
And another observation, in AbstractTool.mouseDrag()
boolean wasDragging = movedPastThreshold();

returns true when I am not able to drag bendpoint, so call to
if(!wasDragging)	
    handleDragStarted();

is never made. When I try to move bendpoint and make the same gesture with mouse 2-3 times it would work on 3rd, sometimes it works immediately.

[Updated on: Thu, 12 January 2012 12:15]

Report message to a moderator

Re: Bendpoint creation is hit or miss [message #778487 is a reply to message #778385] Thu, 12 January 2012 15:36 Go to previous message
Alex Kravets is currently offline Alex Kravets
Messages: 372
Registered: November 2009
Senior Member
Another observation is that I don't see this issue when creating bendpoints on Windows. That is I am developing on Linux and started seeing this problem there.

[Updated on: Thu, 12 January 2012 15:38]

Report message to a moderator

Previous Topic:How to get from an EditPart to its Editor in Eclipse?
Next Topic:Scrolling the GEF Editor at the end
Goto Forum:
  


Current Time: Mon Jul 28 02:28:00 EDT 2014

Powered by FUDForum. Page generated in 0.05853 seconds