Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Possible Children
Possible Children [message #900247] Mon, 06 August 2012 07:25 Go to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

I want to create an application where you see the UML model tree and can open a context menu and add children to a certain element (similar to the UML model editor).

How can I find out the possible children of an element?

selectedElement.eClass().... and now? Smile

Regards,

Tex
Re: Possible Children [message #900262 is a reply to message #900247] Mon, 06 August 2012 08:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you think about your question you may find an answer...

What do you mean by children?

Perhaps: How do I find all classes that conform to the type of some feature?

Finding all derived classes is not possible until you supply all models
in which those classes exist. Once the models and EPackages are loaded
you can do a naive search of all EPackage.eClassifiers or use ESuperAdapter.

Regards

Ed Willink


On 06/08/2012 08:25, Tex Iano wrote:
> Hi,
>
> I want to create an application where you see the UML model tree and
> can open a context menu and add children to a certain element (similar
> to the UML model editor).
>
> How can I find out the possible children of an element?
>
> selectedElement.eClass().... and now? :)
>
> Regards,
>
> Tex
Re: Possible Children [message #900271 is a reply to message #900262] Mon, 06 August 2012 09:42 Go to previous messageGo to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Ok, I did not describe pretty well what I am looking for.

For example: I have selected a UML Package. Then within my menu I want to have:

- PackagedElement
-> Class
-> Interface
-> etc.

- Profile Application

and so on.

So obviously I can use getEAllContainments for this right? Or should I work using Features?

When using getEAllContainments I get Profile Application, Packaged Element etc. as references. Is this the right way? But then: How can I get all Packaged Elements, i.e. Class Interface etc.?

reference.eClass().getESuperTypes() does not return those.

Regards,

Tex
Re: Possible Children [message #900275 is a reply to message #900271] Mon, 06 August 2012 09:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I've really no idea what you want.

You think you know what you want, so you jump straight to a solution,
and find that it doesn't work.

I tried to encourage you to think clearly about the navigation that you
are attempting to perform. Once you understand the model navigation
steps that are needed, you may succeed in configuring your tooling to
achieve it.

Regards

Ed Willink


On 06/08/2012 10:42, Tex Iano wrote:
> Ok, I did not describe pretty well what I am looking for.
>
> For example: I have selected a UML Package. Then within my menu I want
> to have:
>
> - PackagedElement
> -> Class
> -> Interface
> -> etc.
>
> - Profile Application
>
> and so on.
>
> So obviously I can use getEAllContainments for this right? Or should I
> work using Features?
>
> When using getEAllContainments I get Profile Application, Packaged
> Element etc. as references. Is this the right way? But then: How can I
> get all Packaged Elements, i.e. Class Interface etc.?
>
> reference.eClass().getESuperTypes() does not return those.
>
> Regards,
>
> Tex
Re: Possible Children [message #900447 is a reply to message #900275] Tue, 07 August 2012 07:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
I think he wants something similar to ReflectiveItemProvider's
collectNewChildDescriptors. Likely just reusing it would be most direct.

On 06/08/2012 11:55 AM, Ed Willink wrote:
> Hi
>
> I've really no idea what you want.
>
> You think you know what you want, so you jump straight to a solution,
> and find that it doesn't work.
>
> I tried to encourage you to think clearly about the navigation that
> you are attempting to perform. Once you understand the model
> navigation steps that are needed, you may succeed in configuring your
> tooling to achieve it.
>
> Regards
>
> Ed Willink
>
>
> On 06/08/2012 10:42, Tex Iano wrote:
>> Ok, I did not describe pretty well what I am looking for.
>>
>> For example: I have selected a UML Package. Then within my menu I
>> want to have:
>>
>> - PackagedElement
>> -> Class
>> -> Interface
>> -> etc.
>>
>> - Profile Application
>>
>> and so on.
>>
>> So obviously I can use getEAllContainments for this right? Or should
>> I work using Features?
>>
>> When using getEAllContainments I get Profile Application, Packaged
>> Element etc. as references. Is this the right way? But then: How can
>> I get all Packaged Elements, i.e. Class Interface etc.?
>>
>> reference.eClass().getESuperTypes() does not return those.
>>
>> Regards,
>>
>> Tex
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Possible Children [message #900596 is a reply to message #900447] Tue, 07 August 2012 16:43 Go to previous messageGo to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

ok sorry for all that confusion. I will give you an example:

I have a UML package. Now I want to know which elements I can add as child (similar to a typical UML tool). I.e. I want to know that I can add a Class or an Interface to the packagedElements of a Package etc.

I found out that I can use the containments for that purpose:

		for (EReference ref : element.eClass().getEAllContainments()) {
			...
		}


This returns the reference lists, such as packagedElement or ownedComment. Now I want to know, which elements, i.e. EClasses I can add to these lists.

for (EClassifier classifier : UMLPackage.eINSTANCE.getEClassifiers()) {
			if (!(classifier instanceof EClass)) {
				continue;
			}
			EClass c = (EClass)classifier;
						
			if (c.isAbstract()) continue;
			
                        if (ref.getEReferenceType().isSuperTypeOf(c)) {
                           System.out.println("This EClass can be added to the list");
                        }


Is this the right way to do this? Now I want to create an instance of this EClass and add it to a certain reference list. And here I don't know how.

But is the rest ok? Never heard about collectNewChildDescriptors etc. But I think my solution looks not too bad doesn't it? Smile

Regards,

Tex
Re: Possible Children [message #900659 is a reply to message #900596] Wed, 08 August 2012 05:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Try: eClass.getEPackage().getEFactoryInstance().create(eClass)

Regards

Ed Willink

On 07/08/2012 17:43, Tex Iano wrote:
> Hi,
>
> ok sorry for all that confusion. I will give you an example:
>
> I have a UML package. Now I want to know which elements I can add as
> child (similar to a typical UML tool). I.e. I want to know that I can
> add a Class or an Interface to the packagedElements of a Package etc.
> I found out that I can use the containments for that purpose:
>
>
> for (EReference ref : element.eClass().getEAllContainments()) {
> ...
> }
>
>
> This returns the reference lists, such as packagedElement or
> ownedComment. Now I want to know, which elements, i.e. EClasses I can
> add to these lists.
>
>
> for (EClassifier classifier : UMLPackage.eINSTANCE.getEClassifiers()) {
> if (!(classifier instanceof EClass)) {
> continue;
> }
> EClass c = (EClass)classifier;
>
> if (c.isAbstract()) continue;
>
> if (ref.getEReferenceType().isSuperTypeOf(c)) {
> System.out.println("This EClass can be added
> to the list");
> }
>
>
> Is this the right way to do this? Now I want to create an instance of
> this EClass and add it to a certain reference list. And here I don't
> know how.
> But is the rest ok? Never heard about collectNewChildDescriptors etc.
> But I think my solution looks not too bad doesn't it? :)
>
> Regards,
>
> Tex
Re: Possible Children [message #900686 is a reply to message #900659] Wed, 08 August 2012 07:42 Go to previous messageGo to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Hi,

ok thanks, that works. But the created instance is not yet part of the superior element. I.e. for example I create a class and want to add it to the packagedElements list of a UML package:

//This returns an instance of the packagedElement, for example Class
EObject e = umlPackage.eClass().getEPackage().getEFactoryInstance().create(c);

umlPackage.eContents().add(e);

But this does not seem to work. I think that I have to consider the reference lists right? So I have to use the references I requested by using the containments list. But don't know how.

Regards,

Tex
Re: Possible Children [message #900706 is a reply to message #900686] Wed, 08 August 2012 08:48 Go to previous messageGo to next message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Btw: collectNewChildDescriptors seems to be exactly what I am looking for. But is there a good tutorial/example? Google was not really helpful.

Regards,

Tex
Re: Possible Children [message #900723 is a reply to message #900706] Wed, 08 August 2012 09:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Buy the EMF book by Ed Merks wet al. See the EMF Project page.

Regards

Ed Willink


On 08/08/2012 09:48, Tex Iano wrote:
> Btw: collectNewChildDescriptors seems to be exactly what I am looking
> for. But is there a good tutorial/example? Google was not really helpful.
>
> Regards,
>
> Tex
Re: Possible Children [message #900770 is a reply to message #900723] Wed, 08 August 2012 12:37 Go to previous message
Tex Iano is currently offline Tex IanoFriend
Messages: 99
Registered: February 2012
Member
Ok thanks. I already found this out:

EditingDomain ed = AdapterFactoryEditingDomain.getEditingDomainFor(currentElement);
Collection c = ed.getNewChildDescriptors(currentElement, null);

This returns a generic collection. Looks not bad Smile
Previous Topic:Unique element ID before saving
Next Topic:Insert Package Content into another Package
Goto Forum:
  


Current Time: Fri Apr 19 18:31:47 GMT 2024

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

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

Back to the top