Adding Shapes Programmatically [message #705480] |
Fri, 29 July 2011 19:30  |
Eclipse User |
|
|
|
Hi,
Started to explore the Graphiti little bit and it seems to provide lots of capabilities. The task which I'm working towards to now is to create a diagram representing the the business model (it is a class diagram I'm trying to create) consisting of many classes. I would like to show only the read-only editor where in application shows the model.
I have opened the Graphiti editor and it is showing with empty area and empty palette. Now the question is, how do I add the existing business model objects into the diagrams?
Thank you for your time to reply and any help is appreciated.
|
|
|
|
Re: Adding Shapes Programmatically [message #715652 is a reply to message #707120] |
Sun, 14 August 2011 23:50   |
Eclipse User |
|
|
|
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;
}
|
|
|
Re: Adding Shapes Programmatically [message #717110 is a reply to message #705480] |
Fri, 19 August 2011 06:53  |
Eclipse User |
|
|
|
Santosh,
another alternative to solve this is implemented in the tutorial. The
"Create Diagram with all Classes" context menu entry (defined in plugin.xml)
creates a new diagram and adds all existing classes of the project to it.
The functionlity is implemented in the classes AddAllClassesCommand and
CreateDiagramWithAllClassesHandler.
Michael
"Santhosh" schrieb im Newsbeitrag news:j0vf70$joc$1@news.eclipse.org...
Hi,
Started to explore the Graphiti little bit and it seems to provide lots of
capabilities. The task which I'm working towards to now is to create a
diagram representing the the business model (it is a class diagram I'm
trying to create) consisting of many classes. I would like to show only the
read-only editor where in application shows the model.
I have opened the Graphiti editor and it is showing with empty area and
empty palette. Now the question is, how do I add the existing business model
objects into the diagrams?
Thank you for your time to reply and any help is appreciated.
|
|
|
Powered by
FUDForum. Page generated in 0.07633 seconds