Insert a PictogramElement into another [message #1067394] |
Mon, 08 July 2013 09:53  |
Eclipse User |
|
|
|
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 #1067503 is a reply to message #1067476] |
Tue, 09 July 2013 03:11  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04649 seconds