Skip to main content



      Home
Home » Modeling » EMF » Customize ChildDescriptors for TreeEditor
Customize ChildDescriptors for TreeEditor [message #1795251] Wed, 19 September 2018 06:17 Go to next message
Eclipse UserFriend
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 07:33 Go to previous messageGo to next message
Eclipse UserFriend
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 08:33 Go to previous message
Eclipse UserFriend
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 Jul 17 07:10:19 EDT 2025

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

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

Back to the top