|
|
Re: Adding Shapes Programmatically [message #715652 is a reply to message #707120] |
Mon, 15 August 2011 03:50 |
Santhosh Kumar Messages: 44 Registered: March 2011 |
Member |
|
|
Hi Veit,
Thank you for your reply. I did what you suggested below. Execution is coming to AddFeature.add method. I'm creating a container shape corresponding to the resource. When I tried to link it (as shown in Graphiti tutorial example), I'm getting an exception
org.eclipse.core.runtime.AssertionFailedException: null argument: Business object com.brsanthu.rfe.sfdcobjectmodel.impl.SfdcObjectImpl@12231e35 (name: Test) is not contained in a resource
Full exception is at pastebin.com/Wke8UXhj
Here is the Add feature code (modified over tutorial example).
@Override
public PictogramElement add(IAddContext context) {
SfdcObject object = (SfdcObject) context.getNewObject();
Diagram targetDiagram = (Diagram) context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape =
peCreateService.createContainerShape(targetDiagram, true);
// define a default size for the shape
int width = 100;
int height = 50;
IGaService gaService = Graphiti.getGaService();
{
// create and set graphics algorithm
RoundedRectangle roundedRectangle =
gaService.createRoundedRectangle(containerShape, 5, 5);
roundedRectangle.setForeground(manageColor(CLASS_FOREGROUND));
roundedRectangle.setBackground(manageColor(CLASS_BACKGROUND));
roundedRectangle.setLineWidth(2);
gaService.setLocationAndSize(roundedRectangle,
context.getX(), context.getY(), width, height);
// create link and wire it
link(containerShape, object);
}
// SHAPE WITH LINE
{
// create shape for line
Shape shape = peCreateService.createShape(containerShape, false);
// create and set graphics algorithm
Polyline polyline =
gaService.createPolyline(shape, new int[] { 0, 20, width, 20 });
polyline.setForeground(manageColor(CLASS_FOREGROUND));
polyline.setLineWidth(2);
}
// SHAPE WITH TEXT
{
// create shape for text
Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
Text text = gaService.createDefaultText(getDiagram(), shape, object.getName());
text.setForeground(manageColor(CLASS_TEXT_FOREGROUND));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.getFont().setBold(true);
gaService.setLocationAndSize(text, 0, 0, width, 20);
// create link and wire it
link(shape, object);
}
return containerShape;
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03741 seconds