Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to make different figures share same model and part
How to make different figures share same model and part [message #177630] Thu, 14 April 2005 18:08 Go to next message
Eclipse UserFriend
Originally posted by: jduley.mail.arc.nasa.gov

Hello,
I am creating an application where a node can be represented by either a
rectangle-like figure or an ellipse-like figure (both are on my
palette). Each node is really the same so I would like to use thesame
editpart and model. What is the preferred way to acheive this? In the
editpart createFigure method, I suppose I could look at the model and
check for value "isRectangle" or something? In this approach, how can I
initialize the model before this method runs? Any assistance would be
most appreciated. Thanks.
Jason
Re: How to make different figures share same model and part [message #177646 is a reply to message #177630] Thu, 14 April 2005 19:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Have you tried doing this? It should work exactly as you describe.
See the shape example.

"Jason Duley" <jduley@mail.arc.nasa.gov> wrote in message
news:d3mbu6$9a7$1@news.eclipse.org...
> Hello,
> I am creating an application where a node can be represented by either a
> rectangle-like figure or an ellipse-like figure (both are on my palette).
> Each node is really the same so I would like to use thesame editpart and
> model. What is the preferred way to acheive this? In the editpart
> createFigure method, I suppose I could look at the model and check for
> value "isRectangle" or something? In this approach, how can I initialize
> the model before this method runs? Any assistance would be most
> appreciated. Thanks.
> Jason
Re: How to make different figures share same model and part [message #177684 is a reply to message #177646] Thu, 14 April 2005 20:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jduley.mail.arc.nasa.gov

Randy Hudson wrote:
> Have you tried doing this? It should work exactly as you describe.
> See the shape example.
>
> "Jason Duley" <jduley@mail.arc.nasa.gov> wrote in message
> news:d3mbu6$9a7$1@news.eclipse.org...
>
>>Hello,
>>I am creating an application where a node can be represented by either a
>>rectangle-like figure or an ellipse-like figure (both are on my palette).
>>Each node is really the same so I would like to use thesame editpart and
>>model. What is the preferred way to acheive this? In the editpart
>>createFigure method, I suppose I could look at the model and check for
>>value "isRectangle" or something? In this approach, how can I initialize
>>the model before this method runs? Any assistance would be most
>>appreciated. Thanks.
>>Jason
>
>
>
Randy,
It appears that in the shape example, there are two different models in
use for the two figures.

private IFigure createFigureForModel() {
if (getModel() instanceof EllipticalShape) {
return new Ellipse();
}
else if (getModel() instanceof RectangularShape) {
return new RectangleFigure();
}
else {
// if Shapes gets extended the conditions above must be updated
throw new IllegalArgumentException();
}

I am trying to create the figure based on the same model type so this
"instanceof" test will not work. If it is possible to intialize the
model class when the node is created via the palette, where would this
be done?
Re: How to make different figures share same model and part [message #178052 is a reply to message #177684] Mon, 18 April 2005 03:46 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Instead of an instancof test, you could do some other test like
shape.getType(), etc. If you cannot distinguish the models, it is
impossible to know which shape to create.

> Randy,
> It appears that in the shape example, there are two different models in
> use for the two figures.
>
> private IFigure createFigureForModel() {
> if (getModel() instanceof EllipticalShape) {
> return new Ellipse();
> }
> else if (getModel() instanceof RectangularShape) {
> return new RectangleFigure();
> }
> else {
> // if Shapes gets extended the conditions above must be updated
> throw new IllegalArgumentException();
> }
>
> I am trying to create the figure based on the same model type so this
> "instanceof" test will not work. If it is possible to intialize the model
> class when the node is created via the palette, where would this be done?
Previous Topic:use same model in different editpart
Next Topic:a problem of drawing line
Goto Forum:
  


Current Time: Thu Apr 25 16:25:52 GMT 2024

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

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

Back to the top