Skip to main content

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 13:53 Go to next message
Thomas Thonhofer is currently offline Thomas ThonhoferFriend
Messages: 25
Registered: July 2013
Junior Member

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();
		String newClassName = "Variable";
		if (newClassName == null || newClassName.trim().length() == 0) {
			return EMPTY;
		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();
		String newClassName = "Pipeline";
		if (newClassName == null || newClassName.trim().length() == 0) {
			return EMPTY;
		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 23:12 Go to previous messageGo to next message
Heeren Sharma is currently offline Heeren SharmaFriend
Messages: 7
Registered: May 2013
Junior Member
Instead of linking them with your diagram i.e.

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 07:11 Go to previous message
Albert Hofkamp is currently offline Albert HofkampFriend
Messages: 41
Registered: August 2009
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: Mon Sep 27 17:31:45 GMT 2021

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

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

Back to the top