Setting Auto/Default layout in the diagram [message #897207] |
Mon, 23 July 2012 04:06  |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05897 seconds