Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Customize ChildDescriptors for TreeEditor
Customize ChildDescriptors for TreeEditor [message #1795251] Wed, 19 September 2018 10:17 Go to next message
Bo Liu is currently offline Bo LiuFriend
Messages: 32
Registered: July 2016
Member
Hello Community,

I wonder if there is a way to customize which children I can create under some certain element.

I know I can control that by changing the collectNewChildDescriptors Method in ItemProvider Class.

But that customizer will not be changed if I regenerate the code.

If there is a way I can control that in the ecore or genmodel, sothat this change will also be generated?

Regards,
Bo
Re: Customize ChildDescriptors for TreeEditor [message #1795261 is a reply to message #1795251] Wed, 19 September 2018 11:33 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Bo,

The EMF code generator supports a pattern that lets you customize the output of a generated method while still letting the generator update that method as the model changes.

If you rename any generated method with a Gen suffix, then the code generator will update that instead, so you can implement the original method yourself to delegate and filter the output. For example, in your case, you can do

    /** @generated */
    protected void collectNewChildDescriptorsGen(Collection<Object> newChildDescriptors, Object object) {
        // ... as generated by EMF ...
    }

    // this will not be re-generated by EMF
    protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
        // delegate to the generated implementation
        collectNewChildDescriptors(newChildDescriptors, object);

        // filter the result
        newChildDescriptors.removeIf(this::isUnwantedChildDescriptor);
    }
Re: Customize ChildDescriptors for TreeEditor [message #1795265 is a reply to message #1795261] Wed, 19 September 2018 12:33 Go to previous message
Bo Liu is currently offline Bo LiuFriend
Messages: 32
Registered: July 2016
Member
Hi Christian,

thanks for the reply!
That pattern is great! I'll try that out!

Regards,
Bo
Previous Topic:EMF Query deprecated?
Next Topic:Measuring execution time and memory usage in QVTD
Goto Forum:
  


Current Time: Thu Apr 25 16:47:27 GMT 2024

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

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

Back to the top