Customize ChildDescriptors for TreeEditor [message #1795251] |
Wed, 19 September 2018 06:17  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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);
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.70566 seconds