Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Adding Shapes Programmatically
Adding Shapes Programmatically [message #705480] Fri, 29 July 2011 23:30 Go to next message
K Kumar is currently offline K KumarFriend
Messages: 18
Registered: March 2011
Junior Member
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 #707120 is a reply to message #705480] Mon, 01 August 2011 09:07 Go to previous messageGo to next message
Veit Hoffmann is currently offline Veit HoffmannFriend
Messages: 20
Registered: July 2009
Junior Member
Am 30.07.2011 01:30, schrieb Santhosh:
> 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.

Hi Santosh,

you have to implement AddFeatures for the business elements you want to
show and build an UpdateFeature for the root business feature (the one
that is represented by the diagram figure) that delegates to the
AddFeatures for each element that should be added.

So in your UpdateFeature identify the business objects to add and do
something like this for each of them:

EObject eobject = <<the element to add>>
AddContext context2 = new AddContext();
context2.setNewObject(eobject);
context2.setLocation(x, y);
context2.setSize(width, height);
context2.setTargetContainer((ContainerShape) pictogramElement);
getFeatureProvider().addIfPossible(context2);

Moreover if you want the update to happen automatically you need to
overwrite isAutoUpdateAtStartup() to return true in your
DiagramTypeProvider class

Cheers,

Veit
Re: Adding Shapes Programmatically [message #715652 is a reply to message #707120] Mon, 15 August 2011 03:50 Go to previous messageGo to next message
K Kumar is currently offline K KumarFriend
Messages: 18
Registered: March 2011
Junior 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;
    }

Re: Adding Shapes Programmatically [message #717110 is a reply to message #705480] Fri, 19 August 2011 10:53 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
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.
Previous Topic:TransactionalEditing Domain problem
Next Topic:Root domain object linked to Diagram?
Goto Forum:
  


Current Time: Sun Dec 21 20:09:54 GMT 2014

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

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