Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [Zest] Layout Algorithms aren't working for me in Zest 2(All the nodes in the graph show up on one straight horizontal line.)
[Zest] Layout Algorithms aren't working for me in Zest 2 [message #730578] Wed, 28 September 2011 16:18 Go to next message
Hassan M. is currently offline Hassan M.Friend
Messages: 9
Registered: September 2011
Location: Ohio
Junior Member
I was using Zest 1.something in my application, and the layouts worked. However, they were not exactly what I needed. I was about to write a new layout algorithm, when I noticed the new ones in Zest 2 which seem to be really nice. So, I got Zest 2, installed it, changed some code to make it compatible with the new API, and now most of the layouts don't work.
TreeLayoutAlgorithm
and
SpringLayoutAlgorithm
both seem to work, but that's all. Otherwise, I just get a straight line (like in the picture I attached).

I'm not sure if this is an existing bug, or if someone already asked this question. If so, forgive me, it means I didn't search well enough for it.

Here is the code I'm using:

package analyzer_main;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphItem;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.LayoutFilter;
import org.eclipse.zest.layouts.algorithms.SpaceTreeLayoutAlgorithm;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;

public class screenWBSGraph extends Composite {
	
	protected Graph WBSGraph;
	
    public screenWBSGraph(Composite parent, int style) {
        super(parent, style);
        createContents();
    }
    
    private void createContents(){
	    this.setLayout(new FormLayout());
	    WBSGraph = new Graph(this,SWT.NONE);
	    FormData fd_WBSGraph = new FormData();
	    fd_WBSGraph.left = new FormAttachment(0);
	    fd_WBSGraph.right = new FormAttachment(100, 0);
	    fd_WBSGraph.top = new FormAttachment(0);
	    fd_WBSGraph.bottom = new FormAttachment(100, 0);
	    WBSGraph.setLayoutData(fd_WBSGraph);
	    
    }
    
    public void Load(){
		
	    if(main_window.workSpace.isActive()){
			WBSGraph.clear();
	    	
			GraphNode Project_Node = new GraphNode(WBSGraph, SWT.NONE, main_window.workSpace.primaryProject.WBSStructure.getName());
			main_window.workSpace.primaryProject.WBSStructure.toGraph(WBSGraph, Project_Node);
			//^^adds the nodes and connections to WBSGraph under Project_Node.
			
			//This part is copied (almost)exactly from one of the examples:
			//=========================================================================
			LayoutFilter filter = new LayoutFilter() {
				public boolean isObjectFiltered(GraphItem item) {
					if (item instanceof GraphConnection) {
						GraphConnection connection = (GraphConnection) item;
						Object data = connection.getData();
						if (data != null && data instanceof Boolean) {
							// If the data is false, don't filter, otherwise,
							// filter.
							return ((Boolean) data).booleanValue();
						}
						return true;
					}
					return false;
				}
			};
			WBSGraph.addLayoutFilter(filter);
			WBSGraph.setLayoutAlgorithm(new SpaceTreeLayoutAlgorithm(), true);
			//=========================================================================
	    	
	    }
    	
    }
    
}


Thanks!

[Updated on: Wed, 28 September 2011 16:43]

Report message to a moderator

Re: [Zest] Layout Algorithms aren't working for me in Zest 2 [message #730703 is a reply to message #730578] Wed, 28 September 2011 22:52 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian SteegFriend
Messages: 72
Registered: July 2009
Member
The issue here seems to be the filter, which filters all connections, but no nodes. If the filter allows all items, the layout works as expected (see example below). Still a weird behavior, so it might make sense to file a bug on this, with a minimal example.

package org.eclipse.zest.examples.layouts;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphItem;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.LayoutFilter;
import org.eclipse.zest.layouts.algorithms.SpaceTreeLayoutAlgorithm;

public class LayoutFilterExample {

	public static void main(String[] args) {
		Display d = new Display();
		Shell shell = new Shell(d);
		shell.setText("Layout Filter Example");
		shell.setLayout(new FillLayout());
		shell.setSize(400, 400);
		Graph g = new Graph(shell, SWT.NONE);
		GraphNode n = new GraphNode(g, SWT.NONE, "Paper");
		GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");
		GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors");
		new GraphConnection(g, SWT.NONE, n, n2);
		new GraphConnection(g, SWT.NONE, n2, n3);
		new GraphConnection(g, SWT.NONE, n3, n);

		LayoutFilter filter = new LayoutFilter() {
			public boolean isObjectFiltered(GraphItem item) {
				Object data = item.getData();
				if (data != null && data instanceof Boolean) {
					// If the data is false, don't filter, otherwise, filter.
					return ((Boolean) data).booleanValue();
				}
				System.out.println("Don't filter: " + item);
				return false;
			}
		};

		g.addLayoutFilter(filter);
		g.setLayoutAlgorithm(new SpaceTreeLayoutAlgorithm(), true);

		shell.open();
		while (!shell.isDisposed()) {
			while (!d.readAndDispatch()) {
				d.sleep();
			}
		}
	}

}
Re: [Zest] Layout Algorithms aren't working for me in Zest 2 [message #730743 is a reply to message #730703] Thu, 29 September 2011 03:48 Go to previous messageGo to next message
Hassan M. is currently offline Hassan M.Friend
Messages: 9
Registered: September 2011
Location: Ohio
Junior Member
When I do what you said, or even just take out the filter completely, I get a single node on the graph, without any connections. Am I missing something?
Re: [Zest] Layout Algorithms aren't working for me in Zest 2 [message #731081 is a reply to message #730743] Thu, 29 September 2011 22:00 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian SteegFriend
Messages: 72
Registered: July 2009
Member
Not sure what could be causing your issue. Does my example work for you? If it does, try to eliminate things that are different. If without a filter, you see just a single node with SpaceTreeLayoutAlgorithm but more with TreeLayoutAlgorithm, then it's probably a bug. If that is the case, it would be great if you could file a bug with a self-contained code snippet showing the issue (I can't run your code because it references code that is not included).
Re: [Zest] Layout Algorithms aren't working for me in Zest 2 [message #731113 is a reply to message #731081] Fri, 30 September 2011 02:57 Go to previous message
Hassan M. is currently offline Hassan M.Friend
Messages: 9
Registered: September 2011
Location: Ohio
Junior Member
Yes, the code you gave me worked. But I can't really see any difference with the way I implemented it. I want to be cautious in submitting a bug, in case it's just my mistake...

The class I posted above isn't self contained, but the rest of the program is a bit lengthy for a forum. However, there is a very relevant method, toGraph(), in the class 'WBS' which I use for adding the nodes and edges to the graph:

package analyzer_main;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;

class WBS{
	private String Name;
	public  List<WBS> Children;
	public  List<Activity> Activities;
	
	public  String getName(){
		return Name;
	}
	
	public void setName(String name){
		Name = name;
	}
	
	public String toString(){
		return Name;
	}
	
	public void toGraph(Graph WBSGraph, GraphNode Parent){
		for(int i=0;i<this.Children.size();i++){
			GraphNode gnode = new GraphNode(WBSGraph, ZestStyles.CONNECTIONS_DIRECTED, this.Children.get(i).getName());
			new GraphConnection(WBSGraph, ZestStyles.CONNECTIONS_DIRECTED, Parent, gnode);
			
			toGraph(WBSGraph,gnode,Children.get(i));
		}
	}
	
	private void toGraph(Graph WBSGraph, GraphNode Parent, WBS structure){
		for(int x=0;x<structure.Activities.size();x++)structure.Activities.get(x).toGraph(WBSGraph, Parent);
		for(int i=0;i<structure.Children.size();i++){
			GraphNode gnode = new GraphNode(WBSGraph, ZestStyles.CONNECTIONS_DIRECTED, structure.Children.get(i).getName());
			new GraphConnection(WBSGraph, ZestStyles.CONNECTIONS_DIRECTED, Parent, gnode);
			toGraph(WBSGraph,gnode,structure.Children.get(i));
		}
	}
	
	public List<WBS> toFlatList(){
		List<WBS> list = new ArrayList<WBS>();
		populateList(list,this);
		return list;
	}
	
	private void populateList(List<WBS> list,WBS structure){
		list.add(structure);
		for(int i=0;i<structure.Children.size();i++){
			populateList(list,structure.Children.get(i));
		}
	}
}


And, btw this code isn't self contained either, sorry. The only difference I can see is that this code outputs a lot more nodes and edges than the example, which only creates three of each. Could this possibly be an issue?

EDIT: btw, I don't think the above code is relevant, since I do get a working graph with the TreeLayoutAlgorithm, and I attached what it looks like (not bad actually, minus the overlapping).

[Updated on: Fri, 30 September 2011 03:05]

Report message to a moderator

Previous Topic:Increase size of Zest graph
Next Topic:ZEST Custom figures
Goto Forum:
  


Current Time: Mon Dec 22 08:36:23 GMT 2014

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

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