Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [ecp] PostContruct for model element(How can I modify an element after its construction)
| | |
Re: [ecp] PostContruct for model element [message #1071021 is a reply to message #1070869] |
Fri, 19 July 2013 07:11 |
Ed Merks Messages: 33136 Registered: July 2009 |
Senior Member |
|
|
Daniel,
Look for the protected void
collectNewChildDescriptors(Collection<Object> newChildDescriptors,
Object object) that creates the object. Of course if it's a "Foo"
you're creating that needs to be prepopulated in some way, you won't
find it in FooItemProvider but rather in the container of Foo's item
provider, i.e., the one for the object on which you click to create a
new Foo.
On 18/07/2013 11:13 PM, Daniel Golesny wrote:
> Hi Jonas,
>
> I've found the item provider of the element, but ...
> 1. I can't find the correct place to add the "mandatory" child
> 2. it is generated ... how can I modify/override it? I can't find any
> registration point
>
> I've added the mandatory child in the FactoryImpl and that worked, but
> after the model code generation my changes were lost, so this seems
> not to be the right way.
>
> Finally, I've found another way that works: I'm using a
> ECPProjectContentChangedObserver and if there is an element without
> the mandatory child I will create it. Feels that this will slow down
> the application, right?
>
> Could you please explain me your suggestion more detailed?
>
> Regards
> Daniel
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: [ecp] PostContruct for model element [message #1074179 is a reply to message #1071021] |
Fri, 26 July 2013 08:26 |
Maximilian Koegel Messages: 253 Registered: July 2009 |
Senior Member |
|
|
Daniel,
ypu can modify the generated method and add a @generated NOT annotation
to keep the generator from overwriting it on the next regeneration of
you code.
The content provider is generally pretty expensive since it will trigger
on every change on every object in the project and also it will install
an adapter (observer) to every object, furthermore I think it is not the
correct place for your requirements to be implemented. You should use a
newChildDescriptor as suggested. It needs to be added to the parent´s
class (the class the child is mandatory for) item provider.
Cheers,
Maximilian
Am 19.07.2013 09:11, schrieb Ed Merks:
> Daniel,
>
> Look for the protected void
> collectNewChildDescriptors(Collection<Object> newChildDescriptors,
> Object object) that creates the object. Of course if it's a "Foo"
> you're creating that needs to be prepopulated in some way, you won't
> find it in FooItemProvider but rather in the container of Foo's item
> provider, i.e., the one for the object on which you click to create a
> new Foo.
>
>
> On 18/07/2013 11:13 PM, Daniel Golesny wrote:
>> Hi Jonas,
>>
>> I've found the item provider of the element, but ...
>> 1. I can't find the correct place to add the "mandatory" child
>> 2. it is generated ... how can I modify/override it? I can't find any
>> registration point
>>
>> I've added the mandatory child in the FactoryImpl and that worked, but
>> after the model code generation my changes were lost, so this seems
>> not to be the right way.
>>
>> Finally, I've found another way that works: I'm using a
>> ECPProjectContentChangedObserver and if there is an element without
>> the mandatory child I will create it. Feels that this will slow down
>> the application, right?
>>
>> Could you please explain me your suggestion more detailed?
>>
>> Regards
>> Daniel
>>
>>
>
--
Maximilian Kögel
Get Professional Eclipse Support: http://eclipsesource.com/munich
|
|
| |
Re: [ecp] PostContruct for model element [message #1075133 is a reply to message #1074383] |
Sun, 28 July 2013 21:13 |
Jonas Helming Messages: 699 Registered: July 2009 |
Senior Member |
|
|
Hi,
you are right, there is no "ProjectItemProvider" so the described
solution does not work for the root level. Modifying the factories, as
you described is unfortunately no a good solution. The factories will be
used whenever objects are created, e.g. also on loading them. That means
your initialization will be repeated on every restart of the
application. So actually you are right, there is a feature missing here.
The question is, how many different elements your application allows to
be created on the root level. If there are only very few, it might be
better to remove the existing dialog and add menu items for every
element, creatable on the root level. With custom handlers, you can call
any method you want, e.g. createWithInitiliaztion.
If you have more elements, and you want to keep the filtered dialog on
the root level, we need to add a feature, which allows the optional
specification of custom factory code.
Regards
Jonas
Am 26.07.2013 18:06, schrieb Daniel Golesny:
> I've tried it again with EMFCLient 1.0.1 and 1.0.2, I think the code is
> already generated --> didn't work.
> #collectNewChildDescriptors is only called on right-click on the
> container-element but on creating a new container-element as project
> root the mandatory child is not added.
>
> ---- MalmsturmCharacterItemProvider (the container) ----
> protected void collectNewChildDescriptors(Collection<Object>
> newChildDescriptors, Object object) {
> super.collectNewChildDescriptors(newChildDescriptors, object);
> newChildDescriptors.add (createChildParameter
> (MalmsturmPackage.Literals.MALMSTURM_CHARACTER__SKILLS,
> MalmsturmFactory.eINSTANCE.createSkillPyramid()));
> ..
> --------------------
> The mandatory child is the "skills" attribute, type "skillPyramid"
>
> Ahhhh, I think I know the mistake.
> MalmsturmCharacter (the container element) is added to the project as
> root element by using the New-Element-Wizard.
> So I don't have a "Project"ItemProvider, right?
>
> My solution:
> I've modified the
> MalmsturmCharacterFactoryImpl#createMalmsturmCharacter() and add
> @generated NOT.
> That works fine!
> Could you please confirm that for root-elements this is correct way?
> Or is the a SuperItemProvider that I can't find? Or perhaps a bug?
>
> Thanks a lot for your patience,
> Daniel
>
|
|
| | |
Goto Forum:
Current Time: Fri Apr 19 03:48:17 GMT 2024
Powered by FUDForum. Page generated in 0.02796 seconds
|