Adding classes to generated Package [message #903945] |
Mon, 27 August 2012 07:38  |
Eclipse User |
|
|
|
Hi,
What is the best way to add classes dynamically to a running editor.
Let me specify this a little bit more:
I have a base model, that contains a EClass named ResourceContainer (containing a zero to many EReference called resources of EType Resource) and a EClass named Resource (containing a EAttribute called id).
I created the model, edit and editor code out of that model.
EClass Resource has a overridden constructor that creates a value for EAttribute id.
That works fine. Its possible to create a model where the root is a ResourceContainer and its possible to add Resources. (The ECLass Resource should be abstract later)
What i wanna do is to enable the user to create his own Resources (ESuperType Resource) in a extended model and load them into the editor. I already have a Button to (re)load a file (so the editor need not get restarted - later a FileChangeListener should do that).
Unfortunately till now i didn't find a way to add those new EClasses to the EPackage the editor is using.
-----------------------
So what i wanna do is the following:
When starting the editor (and when the user is pressing the reload button), i want to add EClasses specified in a ecore file to the base EPackage.
|
|
|
|
|
Re: Adding classes to generated Package [message #903979 is a reply to message #903967] |
Mon, 27 August 2012 09:38   |
Eclipse User |
|
|
|
Dominik,
Comments below.
On 27/08/2012 3:14 PM, Dominik Muttenthaler wrote:
> Thanks for the fast answer(s),
>
>> It's generally a bad idea for the constructor to populate features...
> What i do is the following:
> id = eClass().getName() + EcoreUtil.generateUUID();
>
> I already see that this isn't good, as soon as i have a dynamic class
> with supertype Resource since EMF creates the Resource Class and then
> sets the eClass Property.
> Where else would u suggest to do this?
Presumably your derived class extends Resource and then the ResourceImpl
is still constructed. The problem is that when you deserialize or copy
some instance, you needlessly create IDs...
Probably better is to compute and cache the ID in the getter. That way
there's an ID there is anything asks for it, but until then, there isn't
one and when you deserialize, the value from the serialization will be set.
>
>
>> That sounds complex for the user to manage. Probably better is that
>> you provide some type of mechanism whereby the user can annotate
>> resources with additional properties (much like EModelElement can be
>> annotated).
> My users are software-developers, and they would like to edit a
> ecore-file.
:-P
>
>
>> You can't modify a generated package at all. You can create new
>> dynamic packages and use those. ReflectiveItemProviderAdapter shows
>> how such newly discovered packages can contribute to the child
>> creation menu.
> Manged to do that already
> Is it possible that classes created out of the dynamic package have
> the same xmlns as classes created out of the genereated package?
No, each package must have a unique nsURI.
> ATM i have 2 xmlns that correspond to the URIs of the Resources
>
>
>> You can only do that if your base package itself is dynamic. Is that
>> the case?
> Not sure where to set that. But the base package is generated code so
> i guess its not.
Yes, that should have been obvious to me given you talked about
specializing the constructor.
So you need to create new packages with new classes.
|
|
|
|
|
Re: Adding classes to generated Package [message #904896 is a reply to message #904844] |
Wed, 29 August 2012 06:42  |
Eclipse User |
|
|
|
> Are you using ReflectiveItemProviderAdapter? It sounds like an issue of
> having populated the cache of allEClasses. A brute for approach would
> be to call IEditingDomainItemProvider.getNewChildDescriptors for each
> EObject in the tree (or at least once for each EObject with a different
> eClass()).
Thank you very much.
It looks like the "magic" happens in ReflectiveItemProvider.gatherMetaData.
Since its going up to the package and adds all Classes of that Package i thinks its enough to call IEditingDomainItemProvider.getNewChildDescriptors for one EObject (doesn't matter witch) in EPackage.
[Updated on: Wed, 29 August 2012 06:58] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03547 seconds