Bug 379152

Summary: CompoundDirectedGraph does not layout properly, nodes overlap.
Product: [Tools] GEF Reporter: Kamil Fejfar <comediant>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 3.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Correct and wrong layout
none
Flow graph example none

Description Kamil Fejfar CLA 2012-05-10 11:44:45 EDT
Build Identifier: M20100211-1343

When I layout a graph using CompoundDirectedGraphLayout, some nodes overlap. This happens when nodes (org.eclipse.draw2d.graph.Node) have no parent. If I create these nodes (org.eclipse.draw2d.graph.Node) with common parent (org.eclipse.draw2d.graph.Subgraph), it seems to work fine.

The problem can be reproduced using GEF flow example with following change in
StructuredActivityPart class:

public void contributeNodesToGraph(CompoundDirectedGraph graph, Subgraph s, Map map) {
	GraphAnimation.recordInitialState(getContentPane());
//	Subgraph me = new Subgraph(this, s);
//	me.rowOrder = getActivity().getSortIndex();
//	me.outgoingOffset = 5;
//	me.incomingOffset = 5;
//	IFigure fig = getFigure();
//	if (fig instanceof SubgraphFigure) {
//		me.width = fig.getPreferredSize(me.width, me.height).width;
//		int tagHeight = ((SubgraphFigure)fig).getHeader().getPreferredSize().height;
//		me.insets.top = tagHeight;
//		me.insets.left = 0;
//		me.insets.bottom = tagHeight;
//	}
//	me.innerPadding = INNER_PADDING;
//	me.setPadding(PADDING);
//	map.put(this, me);
//	graph.nodes.add(me);
	for (int i = 0; i < getChildren().size(); i++) {
		ActivityPart activity = (ActivityPart)getChildren().get(i);
		activity.contributeNodesToGraph(graph, null/*me*/, map);
	}
}

Notes:
1) The attached graph is the smallest graph where it happens to me.
2) The order the nodes are added to graph using graph.nodes.add() is important. Some orders do not cause this problem. The problem can be reproduced when nodes are sorted alphabetically (a1, b1, b2, ...).
3) I think the problem is in org.eclipse.draw2d.graph.HorizontalPlacement.balanceClusters() method. If this 
method is not called, then the nodes do not overlap (no matter the nodes have common parent or not).



Reproducible: Always

Steps to Reproduce:
1. Run the example plugin with change mentioned above.
2. Open attached flow file.
3. Nodes overlap.
Comment 1 Kamil Fejfar CLA 2012-05-10 11:46:48 EDT
Created attachment 215412 [details]
Correct and wrong layout
Comment 2 Kamil Fejfar CLA 2012-05-10 11:50:18 EDT
Created attachment 215413 [details]
Flow graph example