Problems caused by the call to the factory as part of the collectNewChildDescriptors in the Edit Plu [message #425292] |
Fri, 21 November 2008 15:54  |
Eclipse User |
|
|
|
Hi all,
I have created an EMF model that contains Node that can have Nodes as
children (Node contains a list of children). In the Edit setting of the
..genmodel, I set both the Children and Create Child to true (so that I
can see them and select them in the outline).
While this result in having the required behaviour in the Outline view,
I found that the collectNewChildDescriptors() method in the
NodeItemProvider actually calls the plugin factory to instanciate a Node
every time I select a node in the outline.
In my application, this causes problems. I have a Robot class that
inherits from Node. This robot, when created by the RobotFactory,
initialize a connection with the robot hardware. Lets say I load an XML
file that contains a Robot using the generated EMF editor. Then when I
explore the hierarchy of Node in the Outline, I get a Robot instanciated
every time I select the robot in the outline !
It seem to me that the only case where my RobotFactory,createRobot()
should be called is when a model is loaded or I explicitly make such a
call in my code. I could see that this could also become a problem if my
factory implements some sort of tracking of instances created. Having
instances created "in the background" by the GUI is a bit misleading.
Is there a way of preventing the Edit layer from instantiating objects
while retaining the capability to display an Object's child in the outline ?
Thanks in advance,
Pierre.
|
|
|
Re: Problems caused by the call to the factory as part of the collectNewChildDescriptors in the Edit [message #425295 is a reply to message #425292] |
Fri, 21 November 2008 18:42  |
Eclipse User |
|
|
|
Pierre,
Comments below.
Pierre Allard wrote:
> Hi all,
>
> I have created an EMF model that contains Node that can have Nodes as
> children (Node contains a list of children). In the Edit setting of
> the .genmodel, I set both the Children and Create Child to true (so
> that I can see them and select them in the outline).
>
> While this result in having the required behaviour in the Outline
> view, I found that the collectNewChildDescriptors() method in the
> NodeItemProvider actually calls the plugin factory to instanciate a
> Node every time I select a node in the outline.
>
> In my application, this causes problems. I have a Robot class that
> inherits from Node. This robot, when created by the RobotFactory,
> initialize a connection with the robot hardware.
Creating initialized objects sounds like a bad idea. When you
deserialize, the created object should not be initialized at all.
> Lets say I load an XML file that contains a Robot using the generated
> EMF editor. Then when I explore the hierarchy of Node in the Outline,
> I get a Robot instanciated every time I select the robot in the
> outline !
Well, there you go. That's why it's a bad idea.
>
> It seem to me that the only case where my RobotFactory,createRobot()
> should be called is when a model is loaded or I explicitly make such a
> call in my code. I could see that this could also become a problem if
> my factory implements some sort of tracking of instances created.
> Having instances created "in the background" by the GUI is a bit
> misleading.
A copier could create instances. Any client could create instances. I
don't think you should make assumptions about why instances are created
and when it's valid.
>
> Is there a way of preventing the Edit layer from instantiating objects
> while retaining the capability to display an Object's child in the
> outline ?
I think you should reconsider creating objects that aren't in the
"ground" state.
>
> Thanks in advance,
>
> Pierre.
>
|
|
|
Powered by
FUDForum. Page generated in 0.04166 seconds