Skip to main content



      Home
Home » Eclipse Projects » GEF » Shapes example - creating a shape
Shapes example - creating a shape [message #181502] Mon, 16 May 2005 15:19 Go to next message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Hi,

I've just started playing with GEF and at a first look I'm a little bit
scared by its complexity. After reading some articles and not
understanding how to implement a sample, I went to the Shapes example
which is really helping me to clarify some hard aspects from this complex
framework. Even so, I still have problems and I count on the help from
this community to overcome them :)
I would like to create a Shape on my diagram in response to an event
external to the Pallete toolbar. Suppose I have a timer which needs to
create a shape each 30 seconds and draw this shape on the diagram. How do
I do that?

Big thanks in advance.

Best Regards
Cleverson Schmidt
Re: Shapes example - creating a shape [message #181509 is a reply to message #181502] Mon, 16 May 2005 17:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bo.n0spam.majewski.com

> I would like to create a Shape on my diagram in response to an event
> external to the Pallete toolbar. Suppose I have a timer which needs to
> create a shape each 30 seconds and draw this shape on the diagram. How
> do I do that?

The basic philosophy of GEF is that you manipulate the model or a part
of it. The changed model (part) should post an event. The EditPart that
manages it should be smart enough to register itself for those events.
Upon receiving one it must modify the figure that represents the given
model (part) on the screen.

In case of the shape example, to add a shape your times needs to call
the addChild method of ShapeDiagram. This fires a property change event
that is received by the DiagramEditPart. Upon receiving an event with
the property name ShapesDiagram.CHILD_ADDED_PROP the DiagramEditPart
refreshes its children. This calls the getCastedModel().getChildren()
method of the ShapeDiagram through the getModelChildren() method. One of
the children returned by the model is going to be the freshly added
Shape. GEF determines that it has no edit part for it and it invokes a
factory (ShapesEditPartFactory) to create a new controller. The factory
returns ShapeEditPart, which in turn build the shape for your newly
added shape.

So all your timer needs to do is create new shapes and call the addChild
method:

public class ShapeAdder implements Runnable {
private ShapeDiagram diagram;

public ShapeAdder(ShapeDiagram diagram) {
this.diagram = diagram;
}

public void run() {
this.diagram.addChild(new RectangularShape());
}
}

You probably want to use Display.timerExec to call the run method over
and over again.
Re: Shapes example - creating a shape [message #181517 is a reply to message #181509] Mon, 16 May 2005 17:59 Go to previous message
Eclipse UserFriend
Originally posted by: cleversons.gmail.com

Bo Majewski

Thank you very much for you comprehensive answer :)

Best Regards
Cleverson Schmidt
Previous Topic:any method for getting a driagram?
Next Topic:Nested layout managers
Goto Forum:
  


Current Time: Fri May 09 17:52:06 EDT 2025

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

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

Back to the top