Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Setting Auto/Default layout in the diagram(Setting Auto/Default layout in the diagram)
Setting Auto/Default layout in the diagram [message #897207] Mon, 23 July 2012 08:06 Go to next message
Surya Kathayat is currently offline Surya KathayatFriend
Messages: 44
Registered: July 2012
Member
Hi,

I am loading graph nodes and links from a database, creating corresponding domain model (EMF ojects) and displaying on the Graphiti editor. What I have to do now is to specity the location of each nodes (in the context) manually.

Is there any way that I can just add nodes and links in the diagram and set their location/layout somewhat automatically?

		// Add all tasks to diagram
		int x = 20;
		int y = 20;
		for (int i = 0; i < tasks.size(); i++) {
			// Create the context information
			AddContext addContext = new AddContext();
			addContext.setNewObject(tasks.get(i));
			addContext.setTargetContainer(diagram);
			addContext.setX(x); I dont want to specify here...
			addContext.setY(y);I dont want to specify here...
			x = x + 200; // I dont want to specify here...
			y = y + 200; // I dont want to specify here...

			IAddFeature addFeature = featureProvider.getAddFeature(addContext);
			if (addFeature.canAdd(addContext)) {
				addFeature.add(addContext);
			}
		}
		
		
		PictogramLink plink = PictogramsFactory.eINSTANCE.createPictogramLink();
		diagram.setLink(plink);
		
		ICreateConnectionFeature[] createCFeatureList = featureProvider.getCreateConnectionFeatures();
		ICreateConnectionFeature createCFeature = createCFeatureList[0];
			
		// add all links to a diagram
		for (int i = 0; i < linkss.size(); i++) {
			// Create the context information
			OrderLink link = (OrderLink) linkss.get(i);
			
			plink.getBusinessObjects().add(link);

			CreateConnectionContext createContext = new CreateConnectionContext();
			
			Task src = link.getSource();
			Task tar = link.getTarget();

			EList<PictogramLink> plinks = diagram.getPictogramLinks();
			
			ContainerShape srcContainerShape = (ContainerShape) getAnchorFromPE(plinks, src);
			ContainerShape tarContainerShape = (ContainerShape) getAnchorFromPE(plinks, tar);
			
			createContext.setSourcePictogramElement(srcContainerShape);
			createContext.setSourceAnchor(srcContainerShape.getAnchors().get(0));
			createContext.setTargetPictogramElement(tarContainerShape);
			createContext.setTargetAnchor(tarContainerShape.getAnchors().get(0));
			if(createCFeature.canCreate(createContext)){
				createCFeature.create(createContext);
			}
		}



Thank you.

-Surya
Re: Setting Auto/Default layout in the diagram [message #897236 is a reply to message #897207] Mon, 23 July 2012 10:44 Go to previous messageGo to next message
Matthias Gorning is currently offline Matthias GorningFriend
Messages: 81
Registered: April 2010
Location: Germany
Member
Hi Surya,

Graphiti does not provide any feature or an automatically layout. The layout is completely in the response of the editor developer.

You can write your own layouter or you can use an external layouter, e.g. yFiles ( http://www.yworks.com/de/products_yfiles_about.html)

If you use an external layouter, you have typically 3 steps:

- transform your pictogram model to the expected model of the layouter
- let the layouter do the work
- transform the model from the layouter back to your pictogram model

Perhaps you can use this project for your purpose: http://www.eclipse.org/gef/zest/
This project contains a graph layout package.

BR,
Matthias
Re: Setting Auto/Default layout in the diagram [message #897242 is a reply to message #897236] Mon, 23 July 2012 11:31 Go to previous message
Surya Kathayat is currently offline Surya KathayatFriend
Messages: 44
Registered: July 2012
Member
Hi Matthias,

Thank you for the pointers. I will have a look into that...

BR
Surya
Previous Topic:Creating Connections Programtically
Next Topic:Remove,Delete, Update Action
Goto Forum:
  


Current Time: Tue Apr 23 09:59:38 GMT 2024

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

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

Back to the top