Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [ecp] PostContruct for model element(How can I modify an element after its construction)
[ecp] PostContruct for model element [message #1069915] Tue, 16 July 2013 17:45 Go to next message
Daniel Golesny is currently offline Daniel Golesny
Messages: 12
Registered: January 2013
Junior Member
Hi,
could you give me some hints how to modify a model element after its construction/creation?
In my model one element has a reference to a mandatory child (upper and lower bound "1"). Currently in ECP I get a validation error, because it is missing (until I've created it manually).
I want that this mandatory child is created automatically with its parent.

Thanks, Daniel
Re: [ecp] PostContruct for model element [message #1070094 is a reply to message #1069915] Wed, 17 July 2013 04:16 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas Helming
Messages: 410
Registered: July 2009
Senior Member
Hi Daniel,

this is something, which is solved best on the EMF side.
If you create the model element as a child of an existing EObject, you
could for example adapt the "NewChildDescriptior" to add the manditory
child. This is found in the Item Provider of the respective model
element. Instead of just creating the object, you also create the
manditory child. The only thing you should not do is to adapt the factories.

Does that solve your case?

Regards

Jonas

Am 16.07.2013 23:45, schrieb Daniel Golesny:
> Hi,
> could you give me some hints how to modify a model element after its
> construction/creation?
> In my model one element has a reference to a mandatory child (upper and
> lower bound "1"). Currently in ECP I get a validation error, because it
> is missing (until I've created it manually).
> I want that this mandatory child is created automatically with its parent.
>
> Thanks, Daniel
Re: [ecp] PostContruct for model element [message #1070869 is a reply to message #1070094] Thu, 18 July 2013 17:13 Go to previous messageGo to next message
Daniel Golesny is currently offline Daniel Golesny
Messages: 12
Registered: January 2013
Junior Member
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

Re: [ecp] PostContruct for model element [message #1071021 is a reply to message #1070869] Fri, 19 July 2013 03:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25919
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
>
>
Re: [ecp] PostContruct for model element [message #1074179 is a reply to message #1071021] Fri, 26 July 2013 04:26 Go to previous messageGo to next message
Maximilian Koegel is currently offline Maximilian Koegel
Messages: 184
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 #1074383 is a reply to message #1074179] Fri, 26 July 2013 12:06 Go to previous messageGo to next message
Daniel Golesny is currently offline Daniel Golesny
Messages: 12
Registered: January 2013
Junior Member
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
Re: [ecp] PostContruct for model element [message #1075133 is a reply to message #1074383] Sun, 28 July 2013 17:13 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas Helming
Messages: 410
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
>
Re: [ecp] PostContruct for model element [message #1080205 is a reply to message #1075133] Mon, 05 August 2013 12:06 Go to previous messageGo to next message
Daniel Golesny is currently offline Daniel Golesny
Messages: 12
Registered: January 2013
Junior Member
Oh I understand. Then I'll better remove the wizard and add my own "New" menu entry.
I have only a small set of root items, so this is not a problem or I guess it is the better solution for my application. The wizard is too generic for the common user.

Thanks to you all,
Daniel
Re: [ecp] PostContruct for model element [message #1080710 is a reply to message #1080205] Tue, 06 August 2013 05:49 Go to previous message
Jonas Helming is currently offline Jonas Helming
Messages: 410
Registered: July 2009
Senior Member
Great! That is the common case anyways. Most users start with the
generic wizard, but add explicit items, once the model is more stable...

Am 05.08.2013 18:06, schrieb Daniel Golesny:
> Oh I understand. Then I'll better remove the wizard and add my own "New"
> menu entry.
> I have only a small set of root items, so this is not a problem or I
> guess it is the better solution for my application. The wizard is too
> generic for the common user.
>
> Thanks to you all,
> Daniel
Previous Topic:[CDO][ECP] Authentication support
Next Topic:create model from .ecore
Goto Forum:
  


Current Time: Sat Jul 26 07:11:18 EDT 2014

Powered by FUDForum. Page generated in 0.09069 seconds