Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Insert a PictogramElement into another
Insert a PictogramElement into another [message #1067394] Mon, 08 July 2013 09:53 Go to next message
Thomas Thonhofer is currently offline Thomas Thonhofer
Messages: 18
Registered: July 2013
Junior Member
Hello

I am working on a project with graphiti and having some problems. In my editor there are the elements "Variable" and "Pipline", based on EClasses from my Domain Model. I can add both to my diagram.
What I want is that the "Variable" objects can be added as children to a "Pipeline" object, but I don't know how to do that. Couldn't find any help in the tutorial or in the forum so far. The code for the create classes for "Variable" and "Pipeline is below.


public class CreateVariableFeature extends AbstractCreateFeature  {
	public CreateVariableFeature(IFeatureProvider fp) {
		super(fp, "Variable", "Create Variable");
	}
	public boolean canCreate(ICreateContext context) {
		return getBusinessObjectForPictogramElement(context.getTargetContainer()) instanceof Pipeline;
	}
	public Object[] create(ICreateContext context) {
		Variable newClass = ModellFactory.eINSTANCE.createVariable();
		getDiagram().eResource().getContents().add(newClass);
		String newClassName = "Variable";
		if (newClassName == null || newClassName.trim().length() == 0) {
			return EMPTY;
		}
		newClass.setName(newClassName);
		addGraphicalRepresentation(context, newClass);
		return new Object[] { newClass };
	}

}


public class CreatePipelineFeature extends AbstractCreateFeature  {

	
	public CreatePipelineFeature(IFeatureProvider fp) {
		super(fp, "Pipeline", "Create Pipeline");
	}
	public boolean canCreate(ICreateContext context) {
		return context.getTargetContainer() instanceof Diagram;
	}
	public Object[] create(ICreateContext context) {
		Pipeline line = ModellFactory.eINSTANCE.createPipeline();
		getDiagram().eResource().getContents().add(line);
		String newClassName = "Pipeline";
		if (newClassName == null || newClassName.trim().length() == 0) {
			return EMPTY;
		}
		line.setName(newClassName);
		addGraphicalRepresentation(context, line);
		return new Object[] { line };
	}

}


I hope someone can help me. Thank you.
Re: Insert a PictogramElement into another [message #1067476 is a reply to message #1067394] Mon, 08 July 2013 19:12 Go to previous messageGo to next message
Heeren Sharma is currently offline Heeren Sharma
Messages: 7
Registered: May 2013
Junior Member
Instead of linking them with your diagram i.e.
getDiagram().eResource().getContents.add(eobject);

Follow the following steps:
1. Get the parent containershape over which you want to add the child element
2. Then add the associate business Object or EObject from that context.getTargetContainer();
3. ((parent_object)context.getTargetContainer()).add(selected_object);

Remember the step 3 depends on your model.
I hope you get the idea.

Re: Insert a PictogramElement into another [message #1067503 is a reply to message #1067476] Tue, 09 July 2013 03:11 Go to previous message
Albert Hofkamp is currently offline Albert Hofkamp
Messages: 41
Registered: August 2009
Member
If you mean adding in the editor shape tree instead of adding in EMF, then the create call of the outermost container shape is the point that you should change.
In the 'add' tutorial
ContainerShape containerShape =
             peCreateService.createContainerShape(targetDiagram, true);
the "targetDiagram" is actually just the parent ContainerShape of the added object (the diagram just happens to be the root container shape). You get this parent from context.getTargetContainer() in the Variable add() implementation.
Previous Topic:Trying to get the sample to work
Next Topic:Issue with drop in Compartment Pattern
Goto Forum:
  


Current Time: Fri Jul 25 13:37:47 EDT 2014

Powered by FUDForum. Page generated in 0.02249 seconds