|Correct way to initialize sub-objects? [message #509884]
||Mon, 25 January 2010 16:21
| Christoph Wienands
Registered: July 2009
First of all, I previously asked this question in the
eclipse.technology.emft group but the answer there was that the "proper EMF
way" does not apply to a solution with GMF. Therefore, I hope you don't mind
I have just implemented the following functionality in a GMF editor: When a
user creates an object of type A in a diagram, the DSL automatically creates
two contained sub-objects of type B in object of type A. This is because
type A mandates that there are always two contained objects of type B and it
makes the language more usable because the user does not manually have to
create those two objects.
Currently, I modified some generated code in the GMF-generated .diagram
plug-in to add the two B objects. Specifically, I modified the
'doExecuteWithResult' method in the generated CreateCommand class of the
respective model class. However, this is kind of ugly and I think there must
be a better way.
During execution of the creation command, the GMF code retrieves an object
of 'IElementType' that represents the A
class. The 'IElementType' objects are provided by EMF's
'ElementTypeRegistry'. So on this IElementType object, GMF calls the
'getEditCommand' function, which returns an object of type 'ICommand' (named
'configureCommand' in GMF). When debugging, the call returns NULL. However,
I believe that I somehow could register my own configure command so that GMF
automatically executes it. But that's where I lost the trail.
My question is, is this functionality the right place and mechanism for
custom object initialization code? And what is the proper place in the
lifecycle and in code to to register my own edit command?
Thanks a lot,
Powered by FUDForum
. Page generated in 0.01517 seconds