Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [GEF4] connection questions
[GEF4] connection questions [message #1715358] Sun, 22 November 2015 19:23 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 134
Registered: July 2009
Senior Member
Hi

I try to create an MVC example, which connects element.
fyi, https://github.com/keinfarbton/gef4.mvc.tutorial/tree/master/gef4.mvc.tutorial8/src/gef4/mvc/tutorial

1.
It seems to me, that each connection itself needs an object in the model. Because only when it exists, a connection part can be created to represent the connection. Is this true?

2.
I created an example to have connection between the nodes, but they start /end in the middle of the nodes.

index.php/fa/24045/0/

I would like to have the red connections.
Can you give me a pointer (some keywords), which way to go?

3.
One node has a 1-N relation. Later I want to draw the lines like this:
index.php/fa/24046/0/

Is it then good to go for one part per connection, or for one part to visualize all lines for one 1-N relation?

thanks
Frank

Re: [GEF4] connection questions [message #1715505 is a reply to message #1715358] Tue, 24 November 2015 07:55 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 235
Registered: July 2009
Location: L√ľnen
Senior Member
1) Yes, IContentPart is bound to some content. That's needed for creation, synchronization, and lookup. If there is no such content, you could e.g. use a Pair to represent your connection.
2) You can bind a Provider<IAnchor> to your node parts, which can then be used by the connections in their attachToAnchorageVisual() to retrieve an anchor (the logo example demonstrates this). The Provider would have to provide a respective Anchor. You could most easily tweak the ChopBoxAnchor to return the nearest border middle point (the computation strategy is exchangeable) as anchor position.
3) Connection (i.e. the visual node) currently is implemented for bi-directional connections only. On the level of visual parts (controller) the question of whether to use a single controller or not pretty much depends on how interaction is to be handled. If you want to interact which each "segment" on its own, that probably several controllers are the better choice.
Re: [GEF4] connection questions [message #1715641 is a reply to message #1715505] Tue, 24 November 2015 21:56 Go to previous message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 134
Registered: July 2009
Senior Member
Hi

i copied ChopBoxProvider and changed it as SideAnchorProvider
When I just compare the location of the parts, it get weired results, because in the beginning, the positions are not yet layed out. I need to understand layout first, other story Smile

Instead, I want to compute the anchorage point by the role given. As this seems to me the right solution.

In TextNode getContentAnchorages()
	@Override
	public SetMultimap<TextNode, String> getContentAnchorages() {
		HashMultimap<TextNode, String> res = HashMultimap.create();
		res.put(getContent(), "START");
		res.put(getContent(), "END");
		return res;
	}


In TextNodeRelation (the part for the connection) getContentAnchorages()
	@Override
	public SetMultimap<? extends Object, String> getContentAnchorages() {
		HashMultimap<Object, String> res = HashMultimap.create();
		TextNodeRelation nr = getContent();
		res.put( nr.getParent(), "START");
		res.put( nr.getChild(), "END");
		return res;
	}


I use this code to get the roles.
public class SideAnchorProvider implements Provider<IAnchor>, IAdaptable.Bound<IVisualPart<Node, ? extends Node>> {
	private ChopBoxAnchor.IComputationStrategy strategy = new ChopBoxAnchor.IComputationStrategy(){
		@Override
		public Point computePositionInScene(Node anchorage, Node anchored, Point anchoredReferencePointInLocal) {
			Map<Node, IVisualPart<Node, ? extends Node>> partMap = visualPart.getRoot().getViewer().getVisualPartMap();
			
			IVisualPart<Node, ? extends Node> anchoredPart = partMap.get(anchored);
			IVisualPart<Node, ? extends Node> anchoragePart = partMap.get(anchorage);
			
			String role = anchoredPart.getAnchorages()
					.get(anchoragePart)
					.iterator().next();
			
			if( "START".equals(role) ){
				Bounds bnds = anchorage.getBoundsInLocal();
				bnds = anchorage.localToScene(bnds);
				return new Point( bnds.getMaxX(), bnds.getMinY() + bnds.getHeight() /2 );
			}
			if( "END".equals(role) ){
				Bounds bnds = anchorage.getBoundsInLocal();
				bnds = anchorage.localToScene(bnds);
				return new Point( bnds.getMinX(), bnds.getMinY() + bnds.getHeight() /2 );
			}
			throw new RuntimeException();
		}
	};
	@Override
	public IAnchor get() {
		if (anchor == null) {
			anchor = new ChopBoxAnchor(getAdaptable().getVisual(), strategy );
		}
		return anchor;
	}

	@Override
	public IVisualPart<Node, ? extends Node> getAdaptable() {
		return visualPart;
	}

	@Override
	public void setAdaptable(IVisualPart<Node, ? extends Node> adaptable) {
		this.visualPart = adaptable;
	}

}


My question is:
Is this a recommended way to handle this?




With the customized router in TextNodeRelation createVisual():
		visual.setRouter(new IConnectionRouter(){
			@Override
			public ICurve routeConnection(Point[] points) {
				if (points == null || points.length < 2) {
					return new Line(0, 0, 0, 0);
				}
				if( points.length > 2 ) throw new RuntimeException("len: "+points.length);
				Point start = ( points[0].x < points[1].x ) ? points[0] : points[1];
				Point end   = ( points[0].x > points[1].x ) ? points[0] : points[1];
				Point p1 = new Point( start.x + HSPACE, start.y );
				Point p2 = new Point( start.x + HSPACE, end.y );
				Polyline poly = new Polyline(start, p1, p2, end );
				return poly;
			}
		});


it look now as expected.
index.php/fa/24071/0/

thx
Frank


Previous Topic:[GEF4] Manifest error
Next Topic:No scrollbar appears
Goto Forum:
  


Current Time: Fri Sep 21 21:30:24 GMT 2018

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

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

Back to the top