Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Custom code after initialization (Short question)
Custom code after initialization (Short question) [message #415823] Tue, 08 January 2008 14:26 Go to next message
Tomas Zijdemans is currently offline Tomas ZijdemansFriend
Messages: 90
Registered: July 2009
Member
Hi all :)

I'm trying to execute some model specific code after a diagram has been
initialized (add some elements that always should be present at
startup). I've experimented with the constructor of the diagram element,
but this constructor gets called many times at startup, and my code
should only be run once per diagram. Where should I rather put my code?


Best Regards,

Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415825 is a reply to message #415823] Tue, 08 January 2008 15:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33138
Registered: July 2009
Senior Member
Tomas,

This sounds like purely a GMF question so I've added the GMF newsgroup
to the "to" list of the reply so it can be answered there.


Tomas Zijdemans wrote:
> Hi all :)
>
> I'm trying to execute some model specific code after a diagram has
> been initialized (add some elements that always should be present at
> startup). I've experimented with the constructor of the diagram
> element, but this constructor gets called many times at startup, and
> my code should only be run once per diagram. Where should I rather put
> my code?
>
>
> Best Regards,
>
> Tomas Zijdemans


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom code after initialization (Short question) [message #415905 is a reply to message #415825] Thu, 10 January 2008 10:29 Go to previous messageGo to next message
Tomas Zijdemans is currently offline Tomas ZijdemansFriend
Messages: 90
Registered: July 2009
Member
This is truly strange and frustrating.

When a diagram is constructed, 3 diagram elements are created. I add 2
nodes programmatically. In the visible diagram 4 nodes are created (!).
I've tried adding nodes in the createDiagram(...) method, but this
doesn't work. I've also tried adding them through commands when the
editpart of the diagram gets created.

Surely there must be an easiers way to add nodes to a diagram upon
creation ???

Any input appreciated !


Best Regards,

Tomas Zijdemans


Ed Merks wrote:
> Tomas,
>
> This sounds like purely a GMF question so I've added the GMF newsgroup
> to the "to" list of the reply so it can be answered there.
>
>
> Tomas Zijdemans wrote:
>> Hi all :)
>>
>> I'm trying to execute some model specific code after a diagram has
>> been initialized (add some elements that always should be present at
>> startup). I've experimented with the constructor of the diagram
>> element, but this constructor gets called many times at startup, and
>> my code should only be run once per diagram. Where should I rather put
>> my code?
>>
>>
>> Best Regards,
>>
>> Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415910 is a reply to message #415905] Thu, 10 January 2008 16:55 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Tomas,

Geneated ???CreationWizard responsible for creating new diagram, so you can
start from there. I suggest you to modify ???DiagramUtil.createDiagram()
method and create your elements there.

-----------------
Alex Shatalin
Re: Custom code after initialization (Short question) [message #415914 is a reply to message #415910] Thu, 10 January 2008 21:13 Go to previous messageGo to next message
Tomas Zijdemans is currently offline Tomas ZijdemansFriend
Messages: 90
Registered: July 2009
Member
Alex Shatalin wrote:
> Hello Tomas,
>
> Geneated ???CreationWizard responsible for creating new diagram, so you
> can start from there. I suggest you to modify
> ???DiagramUtil.createDiagram() method and create your elements there.

Hi :)

I've tried adding elements here (both via adding objects to the diagram
element's collection, and through commands - known to work), but without
luck.

Well, anyways, thanks for helping.


Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415971 is a reply to message #415914] Mon, 14 January 2008 20:48 Go to previous messageGo to next message
Zac Wolfe is currently offline Zac WolfeFriend
Messages: 11
Registered: July 2009
Junior Member
I had a similar requirement and I ended up overriding the
doDefaultElementCreation() method in the CreateCommand class for my
element and creating the child objects there on the actual EObject.
Something like this:

/**
* @generated NOT
*/
@Override
protected EObject doDefaultElementCreation() {
MyObject obj = (MyObject) super.doDefaultElementCreation();
obj.createChildObjects();
return obj;
}



Tomas Zijdemans wrote:
> Alex Shatalin wrote:
>> Hello Tomas,
>>
>> Geneated ???CreationWizard responsible for creating new diagram, so
>> you can start from there. I suggest you to modify
>> ???DiagramUtil.createDiagram() method and create your elements there.
>
> Hi :)
>
> I've tried adding elements here (both via adding objects to the diagram
> element's collection, and through commands - known to work), but without
> luck.
>
> Well, anyways, thanks for helping.
>
>
> Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415982 is a reply to message #415825] Tue, 15 January 2008 01:11 Go to previous messageGo to next message
Stefan Kuhn is currently offline Stefan KuhnFriend
Messages: 355
Registered: July 2009
Senior Member
hi ed,

maybe it would be worth it executing the EditHelper for the root/canvas
element?

should I file a feature request?

-stefan

Ed Merks wrote:
> Tomas,
>
> This sounds like purely a GMF question so I've added the GMF newsgroup
> to the "to" list of the reply so it can be answered there.
>
>
> Tomas Zijdemans wrote:
>> Hi all :)
>>
>> I'm trying to execute some model specific code after a diagram has
>> been initialized (add some elements that always should be present at
>> startup). I've experimented with the constructor of the diagram
>> element, but this constructor gets called many times at startup, and
>> my code should only be run once per diagram. Where should I rather put
>> my code?
>>
>>
>> Best Regards,
>>
>> Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415983 is a reply to message #415982] Tue, 15 January 2008 01:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33138
Registered: July 2009
Senior Member
Stefan,

I'm not sure I understand the issue very well, but it seems a reasonable
thing...


SKuhn wrote:
> hi ed,
>
> maybe it would be worth it executing the EditHelper for the
> root/canvas element?
>
> should I file a feature request?
>
> -stefan
>
> Ed Merks wrote:
>> Tomas,
>>
>> This sounds like purely a GMF question so I've added the GMF
>> newsgroup to the "to" list of the reply so it can be answered there.
>>
>>
>> Tomas Zijdemans wrote:
>>> Hi all :)
>>>
>>> I'm trying to execute some model specific code after a diagram has
>>> been initialized (add some elements that always should be present at
>>> startup). I've experimented with the constructor of the diagram
>>> element, but this constructor gets called many times at startup, and
>>> my code should only be run once per diagram. Where should I rather
>>> put my code?
>>>
>>>
>>> Best Regards,
>>>
>>> Tomas Zijdemans


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom code after initialization (Short question) [message #415984 is a reply to message #415983] Tue, 15 January 2008 02:29 Go to previous messageGo to next message
Stefan Kuhn is currently offline Stefan KuhnFriend
Messages: 355
Registered: July 2009
Senior Member
hi ed,

normally you can add additional behavior, e.g. initializing an element
with an EditHelper(Advice). Since they are in reality called by the
parent element, this is not possible for the root element right now.

-stefan

P.S. I've fixed this genmodel bug (id=215282) ... 3 lines of code :(

Ed Merks wrote:
> Stefan,
>
> I'm not sure I understand the issue very well, but it seems a reasonable
> thing...
>
>
> SKuhn wrote:
>> hi ed,
>>
>> maybe it would be worth it executing the EditHelper for the
>> root/canvas element?
>>
>> should I file a feature request?
>>
>> -stefan
>>
>> Ed Merks wrote:
>>> Tomas,
>>>
>>> This sounds like purely a GMF question so I've added the GMF
>>> newsgroup to the "to" list of the reply so it can be answered there.
>>>
>>>
>>> Tomas Zijdemans wrote:
>>>> Hi all :)
>>>>
>>>> I'm trying to execute some model specific code after a diagram has
>>>> been initialized (add some elements that always should be present at
>>>> startup). I've experimented with the constructor of the diagram
>>>> element, but this constructor gets called many times at startup, and
>>>> my code should only be run once per diagram. Where should I rather
>>>> put my code?
>>>>
>>>>
>>>> Best Regards,
>>>>
>>>> Tomas Zijdemans
Re: Custom code after initialization (Short question) [message #415987 is a reply to message #415984] Tue, 15 January 2008 11:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33138
Registered: July 2009
Senior Member
Stefan,

I see. Allowing an EditHelper for the root would make really good sense
then.

I've commented on the bug that the option should to serialize with a
schema location, which is essential for supporting purely dynamic models
as the document suggests is supported, should be added at the time the
resource is created so anyone saving the resource will do so correctly.
It also seems to me that this decorator approach should allow a static
model to be used and that in that case, the generated item providers
could be used in the properties view (because item providers are
registered and could be discovered as needed).


SKuhn wrote:
> hi ed,
>
> normally you can add additional behavior, e.g. initializing an element
> with an EditHelper(Advice). Since they are in reality called by the
> parent element, this is not possible for the root element right now.
>
> -stefan
>
> P.S. I've fixed this genmodel bug (id=215282) ... 3 lines of code :(
>
> Ed Merks wrote:
>> Stefan,
>>
>> I'm not sure I understand the issue very well, but it seems a
>> reasonable thing...
>>
>>
>> SKuhn wrote:
>>> hi ed,
>>>
>>> maybe it would be worth it executing the EditHelper for the
>>> root/canvas element?
>>>
>>> should I file a feature request?
>>>
>>> -stefan
>>>
>>> Ed Merks wrote:
>>>> Tomas,
>>>>
>>>> This sounds like purely a GMF question so I've added the GMF
>>>> newsgroup to the "to" list of the reply so it can be answered there.
>>>>
>>>>
>>>> Tomas Zijdemans wrote:
>>>>> Hi all :)
>>>>>
>>>>> I'm trying to execute some model specific code after a diagram has
>>>>> been initialized (add some elements that always should be present
>>>>> at startup). I've experimented with the constructor of the diagram
>>>>> element, but this constructor gets called many times at startup,
>>>>> and my code should only be run once per diagram. Where should I
>>>>> rather put my code?
>>>>>
>>>>>
>>>>> Best Regards,
>>>>>
>>>>> Tomas Zijdemans


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom code after initialization (Short question) [message #415992 is a reply to message #415987] Tue, 15 January 2008 14:33 Go to previous messageGo to next message
Stefan Kuhn is currently offline Stefan KuhnFriend
Messages: 355
Registered: July 2009
Senior Member
vote for:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=215344

-stefan

Ed Merks wrote:
> Stefan,
>
> I see. Allowing an EditHelper for the root would make really good sense
> then.
>
> I've commented on the bug that the option should to serialize with a
> schema location, which is essential for supporting purely dynamic models
> as the document suggests is supported, should be added at the time the
> resource is created so anyone saving the resource will do so correctly.
> It also seems to me that this decorator approach should allow a static
> model to be used and that in that case, the generated item providers
> could be used in the properties view (because item providers are
> registered and could be discovered as needed).
>
>
> SKuhn wrote:
>> hi ed,
>>
>> normally you can add additional behavior, e.g. initializing an element
>> with an EditHelper(Advice). Since they are in reality called by the
>> parent element, this is not possible for the root element right now.
>>
>> -stefan
>>
>> P.S. I've fixed this genmodel bug (id=215282) ... 3 lines of code :(
>>
>> Ed Merks wrote:
>>> Stefan,
>>>
>>> I'm not sure I understand the issue very well, but it seems a
>>> reasonable thing...
>>>
>>>
>>> SKuhn wrote:
>>>> hi ed,
>>>>
>>>> maybe it would be worth it executing the EditHelper for the
>>>> root/canvas element?
>>>>
>>>> should I file a feature request?
>>>>
>>>> -stefan
>>>>
>>>> Ed Merks wrote:
>>>>> Tomas,
>>>>>
>>>>> This sounds like purely a GMF question so I've added the GMF
>>>>> newsgroup to the "to" list of the reply so it can be answered there.
>>>>>
>>>>>
>>>>> Tomas Zijdemans wrote:
>>>>>> Hi all :)
>>>>>>
>>>>>> I'm trying to execute some model specific code after a diagram has
>>>>>> been initialized (add some elements that always should be present
>>>>>> at startup). I've experimented with the constructor of the diagram
>>>>>> element, but this constructor gets called many times at startup,
>>>>>> and my code should only be run once per diagram. Where should I
>>>>>> rather put my code?
>>>>>>
>>>>>>
>>>>>> Best Regards,
>>>>>>
>>>>>> Tomas Zijdemans
Re: Custom code after initialization (Short question) [to: Zac] [message #416113 is a reply to message #415971] Fri, 18 January 2008 11:44 Go to previous messageGo to next message
Tomas Zijdemans is currently offline Tomas ZijdemansFriend
Messages: 90
Registered: July 2009
Member
Zac Woof wrote:
> I had a similar requirement and I ended up overriding the
> doDefaultElementCreation() method in the CreateCommand class for my
> element and creating the child objects there on the actual EObject.
> Something like this:
>
> /**
> * @generated NOT
> */
> @Override
> protected EObject doDefaultElementCreation() {
> MyObject obj = (MyObject) super.doDefaultElementCreation();
> obj.createChildObjects();
> return obj;
> }
>
Hi!

This worked great for running customized code when an object is created,
but my problem now is that the diagram element do not have a create
command - so I can't create objects on diagram startup using this method.


Regards,

Tomas Zijdemans
Re: Custom code after initialization (Short question) [to: Zac] [message #416143 is a reply to message #416113] Fri, 18 January 2008 16:49 Go to previous message
Stefan Kuhn is currently offline Stefan KuhnFriend
Messages: 355
Registered: July 2009
Senior Member
hi tomas,
I'm not sure if I got you right, but when creating elements on startup,
you don't want to create diagram elements. You would rather want to
create semantic elements of you domain model and let gmf choose the
representation later on.

-stefan


Tomas Zijdemans wrote:
> Zac Woof wrote:
>> I had a similar requirement and I ended up overriding the
>> doDefaultElementCreation() method in the CreateCommand class for my
>> element and creating the child objects there on the actual EObject.
>> Something like this:
>>
>> /**
>> * @generated NOT
>> */
>> @Override
>> protected EObject doDefaultElementCreation() {
>> MyObject obj = (MyObject) super.doDefaultElementCreation();
>> obj.createChildObjects();
>> return obj;
>> }
>>
> Hi!
>
> This worked great for running customized code when an object is created,
> but my problem now is that the diagram element do not have a create
> command - so I can't create objects on diagram startup using this method.
>
>
> Regards,
>
> Tomas Zijdemans
Previous Topic:Wrapper for arbitrary values or objects
Next Topic:Design Question: multiple viewers on one model
Goto Forum:
  


Current Time: Sat Apr 20 07:04:32 GMT 2024

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

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

Back to the top