Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Re: Custom code after initialization (Short question)
Re: Custom code after initialization (Short question) [message #167362] Tue, 08 January 2008 10:23 Go to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #167550 is a reply to message #167362] Thu, 10 January 2008 05:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

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 #167657 is a reply to message #167550] Thu, 10 January 2008 11:55 Go to previous messageGo to next message
Eclipse UserFriend
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 #167695 is a reply to message #167657] Thu, 10 January 2008 16:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

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 #168081 is a reply to message #167695] Mon, 14 January 2008 15:48 Go to previous messageGo to next message
Eclipse UserFriend
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 #168113 is a reply to message #167362] Mon, 14 January 2008 20:11 Go to previous messageGo to next message
Eclipse UserFriend
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 #168120 is a reply to message #168113] Mon, 14 January 2008 20:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #168128 is a reply to message #168120] Mon, 14 January 2008 21:29 Go to previous messageGo to next message
Eclipse UserFriend
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 #168172 is a reply to message #168128] Tue, 15 January 2008 06:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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) [message #168242 is a reply to message #168172] Tue, 15 January 2008 09:33 Go to previous messageGo to next message
Eclipse UserFriend
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 #168707 is a reply to message #168081] Fri, 18 January 2008 06:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

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 #168812 is a reply to message #168707] Fri, 18 January 2008 11:49 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Custom code after initialization (Short question) [to: Zac] [message #168874 is a reply to message #168812] Sun, 20 January 2008 12:39 Go to previous message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

SKuhn wrote:
> I'm not sure if I got you right, but when creating elements on startup,
> you don't want to create diagram elements.

Yep :) What I meant was that the diagram element does not have a
XYZCreateCommand class. I want to add some classes when a diagram is
created - if I override the doDefaultElementCreation() of an object the
code will only execute at creation time of those objects.

You would rather want to
> create semantic elements of you domain model and let gmf choose the
> representation later on.

I succeeded in adding semantic elements in the createDiagram method of
the XYZUtil method, but now I'm wondering: I want to set a specific
location for my new elements. The only way I know of is through commands
(request.setLocation etc.).

Any ideas?


Best Regards,

Tomas Zijdemans






>
>
> 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:Label positioning outside a Node
Next Topic:why does not my objectContribution to the pop menu work?
Goto Forum:
  


Current Time: Mon May 12 00:28:23 EDT 2025

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

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

Back to the top