Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Defining my own types
Defining my own types [message #414542] Mon, 12 November 2007 13:29 Go to next message
Florin Banica is currently offline Florin BanicaFriend
Messages: 14
Registered: July 2009
Junior Member
Hi all,

I would like to ask for your help with this one: I want to define my own
type into the .ecore file.

Let's say MyType is an abstract class inherited by XType and YType. I have
another class A which has an EAttribute called isOfType, pointing to MyType
(it's EType property ponits MyType).

I would like to let the user choose (into the PropertiesView) the acttual
type (XType or YType) when he creates an A element into the editor.

At the moment, I have to create an instance of XType and an instance of
YType (when opening a new model into the editor), otherwise, the user will
see nothing into the combo box of the isOfType property (into the
PropertiesView).

It would seem more like it to me just to see the possible types (XType or
YType) into that combo box, instead of a list of their instances.

Am I wrong about this? Could it be done like I want to? Help, please...



Floppy
Re: Defining my own types [message #414544 is a reply to message #414542] Mon, 12 November 2007 14:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Florin,

It sounds a little like you should use a containment reference and then
the suer could create an XType or a YType instance. If you have a
non-containment reference, the object it references needs to be
contained elsewhere in order for the over all result to be
serializeable. You can use the GenFeature's properties to make the
reference show up as children in the tree and to support creation
commands, and to eliminate the properties view for it, but you'll need
to do something to ensure that any children you create are actually
containment somewhere...


Florin Banica wrote:
> Hi all,
>
> I would like to ask for your help with this one: I want to define my own
> type into the .ecore file.
>
> Let's say MyType is an abstract class inherited by XType and YType. I have
> another class A which has an EAttribute called isOfType, pointing to MyType
> (it's EType property ponits MyType).
>
> I would like to let the user choose (into the PropertiesView) the acttual
> type (XType or YType) when he creates an A element into the editor.
>
> At the moment, I have to create an instance of XType and an instance of
> YType (when opening a new model into the editor), otherwise, the user will
> see nothing into the combo box of the isOfType property (into the
> PropertiesView).
>
> It would seem more like it to me just to see the possible types (XType or
> YType) into that combo box, instead of a list of their instances.
>
> Am I wrong about this? Could it be done like I want to? Help, please...
>
>
>
> Floppy
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Defining my own types [message #414545 is a reply to message #414542] Mon, 12 November 2007 16:29 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Florin Banica wrote:
> Hi all,
>
> I would like to ask for your help with this one: I want to define my own
> type into the .ecore file.
>
> Let's say MyType is an abstract class inherited by XType and YType. I have
> another class A which has an EAttribute called isOfType, pointing to MyType
> (it's EType property ponits MyType).
>
> I would like to let the user choose (into the PropertiesView) the acttual
> type (XType or YType) when he creates an A element into the editor.

Not sure if I understand this correctly, but: You say your Model Class A
has an EAttribute whose EAttributeType feature is "MyType" while MyType
is an EClass? This shouldn´ t be possible, since an EAttributes
EAttributeType feature is of type EDatatype which an EClass does not
comply with.

So I guess you mean you have an EReference "isOfType" whose type is MyType?


Felix
Re: Defining my own types [message #414546 is a reply to message #414544] Mon, 12 November 2007 16:29 Go to previous messageGo to next message
Florin Banica is currently offline Florin BanicaFriend
Messages: 14
Registered: July 2009
Junior Member
Hi Ed,

and thsnks for the answer. But, maybe I wasn't very clear in what I said.
Sorry about that.

You suggested to use a EReference... So I have this .ecore:
- MyModel
- MyType (abstract class)
- XType (inherits form MyType)
- YType (inherits form MyType)
- AElement
-> isOfType (EReference, containment: true): MyType

What I want is to select the type from the combo box (in the
PropertiesView), but this combo box is empty; it should only contain XType
and YType as types, not instances of these types. Since XType and YType are
delcared into the metamodel, I should be able to point them, shouldn't I?

I just want to say that AElement is of type XType, not to create an instance
of XType and point it (the instance of the XType will be created later by
some other part of the application which takes my model and uses it).

Thanks again,



Floppy



"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fh9olk$bro$1@build.eclipse.org...
> Florin,
>
> It sounds a little like you should use a containment reference and then
> the suer could create an XType or a YType instance. If you have a
> non-containment reference, the object it references needs to be contained
> elsewhere in order for the over all result to be serializeable. You can
> use the GenFeature's properties to make the reference show up as children
> in the tree and to support creation commands, and to eliminate the
> properties view for it, but you'll need to do something to ensure that any
> children you create are actually containment somewhere...
>
>
> Florin Banica wrote:
>> Hi all,
>>
>> I would like to ask for your help with this one: I want to define my own
>> type into the .ecore file.
>>
>> Let's say MyType is an abstract class inherited by XType and YType. I
>> have another class A which has an EAttribute called isOfType, pointing to
>> MyType (it's EType property ponits MyType).
>>
>> I would like to let the user choose (into the PropertiesView) the acttual
>> type (XType or YType) when he creates an A element into the editor.
>>
>> At the moment, I have to create an instance of XType and an instance of
>> YType (when opening a new model into the editor), otherwise, the user
>> will see nothing into the combo box of the isOfType property (into the
>> PropertiesView).
>>
>> It would seem more like it to me just to see the possible types (XType or
>> YType) into that combo box, instead of a list of their instances.
>>
>> Am I wrong about this? Could it be done like I want to? Help, please...
>>
>>
>>
>> Floppy
>>
>>
>>
Re: Defining my own types [message #414547 is a reply to message #414546] Mon, 12 November 2007 16:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040601020401000405080803
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Florin,

Comments below.


Florin Banica wrote:
> Hi Ed,
>
> and thsnks for the answer. But, maybe I wasn't very clear in what I said.
> Sorry about that.
>
> You suggested to use a EReference... So I have this .ecore:
> - MyModel
> - MyType (abstract class)
> - XType (inherits form MyType)
> - YType (inherits form MyType)
> - AElement
> -> isOfType (EReference, containment: true): MyType
>
> What I want is to select the type from the combo box (in the
> PropertiesView), but this combo box is empty; it should only contain XType
> and YType as types, not instances of these types. Since XType and YType are
> delcared into the metamodel, I should be able to point them, shouldn't I?
>
So it sounds like you want an EReference to an EClass and have the
choices limited to EClasses for which MyType is a super type. Is that
right? You could certainly do that with a non-containment EReference
to EClass. You could specialize the property descriptor's
getChoiceOfValues() to list only the EClasses you intend to have
listed. It might be better to enumerate the choices and represent them
as an EEnum.
> I just want to say that AElement is of type XType, not to create an instance
> of XType and point it (the instance of the XType will be created later by
> some other part of the application which takes my model and uses it).
>
> Thanks again,
>
>
>
> Floppy
>
>
>
> "Ed Merks" <merks@ca.ibm.com> wrote in message
> news:fh9olk$bro$1@build.eclipse.org...
>
>> Florin,
>>
>> It sounds a little like you should use a containment reference and then
>> the suer could create an XType or a YType instance. If you have a
>> non-containment reference, the object it references needs to be contained
>> elsewhere in order for the over all result to be serializeable. You can
>> use the GenFeature's properties to make the reference show up as children
>> in the tree and to support creation commands, and to eliminate the
>> properties view for it, but you'll need to do something to ensure that any
>> children you create are actually containment somewhere...
>>
>>
>> Florin Banica wrote:
>>
>>> Hi all,
>>>
>>> I would like to ask for your help with this one: I want to define my own
>>> type into the .ecore file.
>>>
>>> Let's say MyType is an abstract class inherited by XType and YType. I
>>> have another class A which has an EAttribute called isOfType, pointing to
>>> MyType (it's EType property ponits MyType).
>>>
>>> I would like to let the user choose (into the PropertiesView) the acttual
>>> type (XType or YType) when he creates an A element into the editor.
>>>
>>> At the moment, I have to create an instance of XType and an instance of
>>> YType (when opening a new model into the editor), otherwise, the user
>>> will see nothing into the combo box of the isOfType property (into the
>>> PropertiesView).
>>>
>>> It would seem more like it to me just to see the possible types (XType or
>>> YType) into that combo box, instead of a list of their instances.
>>>
>>> Am I wrong about this? Could it be done like I want to? Help, please...
>>>
>>>
>>>
>>> Floppy
>>>
>>>
>>>
>>>
>
>
>


--------------040601020401000405080803
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Florin,<br>
<br>
Comments below.<br>
<br>
<br>
Florin Banica wrote:
<blockquote cite="mid:fh9v20$ut6$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,

and thsnks for the answer. But, maybe I wasn't very clear in what I said.
Sorry about that.

You suggested to use a EReference... So I have this .ecore:
- MyModel
- MyType (abstract class)
- XType (inherits form MyType)
- YType (inherits form MyType)
- AElement
-&gt; isOfType (EReference, containment: true): MyType

What I want is to select the type from the combo box (in the
PropertiesView), but this combo box is empty; it should only contain XType
and YType as types, not instances of these types. Since XType and YType are
delcared into the metamodel, I should be able to point them, shouldn't I?
</pre>
</blockquote>
So it sounds like you want an EReference to an EClass and have the
choices limited to EClasses for which MyType is a super type.&nbsp; Is that
right?&nbsp;&nbsp; You could certainly do that with a non-containment EReference
to EClass.&nbsp; You could specialize the property descriptor's
getChoiceOfValues() to list only the EClasses you intend to have
listed.&nbsp; It might be better to enumerate the choices and represent them
as an EEnum. <br>
<blockquote cite="mid:fh9v20$ut6$1@build.eclipse.org" type="cite">
<pre wrap="">
I just want to say that AElement is of type XType, not to create an instance
of XType and point it (the instance of the XType will be created later by
some other part of the application which takes my model and uses it).

Thanks again,



Floppy



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:fh9olk$bro$1@build.eclipse.org">news:fh9olk$bro$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Florin,

It sounds a little like you should use a containment reference and then
the suer could create an XType or a YType instance. If you have a
non-containment reference, the object it references needs to be contained
elsewhere in order for the over all result to be serializeable. You can
use the GenFeature's properties to make the reference show up as children
in the tree and to support creation commands, and to eliminate the
properties view for it, but you'll need to do something to ensure that any
children you create are actually containment somewhere...


Florin Banica wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,

I would like to ask for your help with this one: I want to define my own
type into the .ecore file.

Let's say MyType is an abstract class inherited by XType and YType. I
have another class A which has an EAttribute called isOfType, pointing to
MyType (it's EType property ponits MyType).

I would like to let the user choose (into the PropertiesView) the acttual
type (XType or YType) when he creates an A element into the editor.

At the moment, I have to create an instance of XType and an instance of
YType (when opening a new model into the editor), otherwise, the user
will see nothing into the combo box of the isOfType property (into the
PropertiesView).

It would seem more like it to me just to see the possible types (XType or
YType) into that combo box, instead of a list of their instances.

Am I wrong about this? Could it be done like I want to? Help, please...



Floppy



</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------040601020401000405080803--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Defining my own types [message #414548 is a reply to message #414545] Mon, 12 November 2007 16:45 Go to previous messageGo to next message
Florin Banica is currently offline Florin BanicaFriend
Messages: 14
Registered: July 2009
Junior Member
Hi Felix,

you're right, but my problem persists (see above, the answer to Ed). Any
idea how to face it? Is my idea wrong/impossible? I would be happy to
understand why...


Thank you,



Floppy



"Felix Dorner" <felix_do@web.de> wrote in message
news:fh9v0r$upt$1@build.eclipse.org...
> Florin Banica wrote:
>> Hi all,
>>
>> I would like to ask for your help with this one: I want to define my own
>> type into the .ecore file.
>>
>> Let's say MyType is an abstract class inherited by XType and YType. I
>> have another class A which has an EAttribute called isOfType, pointing to
>> MyType (it's EType property ponits MyType).
>>
>> I would like to let the user choose (into the PropertiesView) the acttual
>> type (XType or YType) when he creates an A element into the editor.
>
> Not sure if I understand this correctly, but: You say your Model Class A
> has an EAttribute whose EAttributeType feature is "MyType" while MyType is
> an EClass? This shouldn
Re: Defining my own types [message #414549 is a reply to message #414547] Mon, 12 November 2007 16:56 Go to previous messageGo to next message
Florin Banica is currently offline Florin BanicaFriend
Messages: 14
Registered: July 2009
Junior Member
This is a multi-part message in MIME format.

------=_NextPart_000_00DC_01C8255D.B531B8A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

"So it sounds like you want an EReference to an EClass and have the =
choices limited to EClasses for which MyType is a super type. Is that =
right?"

It's right. I mean if I say that is of type MyType, I would excpect to =
see a list of classes that are of this type (MyType) or inherit from =
this one. The problem is that I see nothing in the list! Only if I =
create some instances of these classes, then I can see them in the =
list...

Then, where is this "getChoiceOfValues()"?

Thanks a lot again,



Floppy


"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:fh9vuj$1ec$1@build.eclipse.org...
Florin,

Comments below.


Florin Banica wrote:=20
Hi Ed,

and thsnks for the answer. But, maybe I wasn't very clear in what I =
said.
Sorry about that.

You suggested to use a EReference... So I have this .ecore:
- MyModel
- MyType (abstract class)
- XType (inherits form MyType)
- YType (inherits form MyType)
- AElement
-> isOfType (EReference, containment: true): MyType

What I want is to select the type from the combo box (in the
PropertiesView), but this combo box is empty; it should only contain =
XType
and YType as types, not instances of these types. Since XType and YType =
are
delcared into the metamodel, I should be able to point them, shouldn't =
I?
So it sounds like you want an EReference to an EClass and have the =
choices limited to EClasses for which MyType is a super type. Is that =
right? You could certainly do that with a non-containment EReference =
to EClass. You could specialize the property descriptor's =
getChoiceOfValues() to list only the EClasses you intend to have listed. =
It might be better to enumerate the choices and represent them as an =
EEnum.=20

I just want to say that AElement is of type XType, not to create an =
instance
of XType and point it (the instance of the XType will be created later =
by
some other part of the application which takes my model and uses it).

Thanks again,



Floppy



"Ed Merks" <merks@ca.ibm.com> wrote in message=20
news:fh9olk$bro$1@build.eclipse.org...
Florin,

It sounds a little like you should use a containment reference and then=20
the suer could create an XType or a YType instance. If you have a=20
non-containment reference, the object it references needs to be =
contained=20
elsewhere in order for the over all result to be serializeable. You =
can=20
use the GenFeature's properties to make the reference show up as =
children=20
in the tree and to support creation commands, and to eliminate the=20
properties view for it, but you'll need to do something to ensure that =
any=20
children you create are actually containment somewhere...


Florin Banica wrote:
Hi all,

I would like to ask for your help with this one: I want to define my own =

type into the .ecore file.

Let's say MyType is an abstract class inherited by XType and YType. I=20
have another class A which has an EAttribute called isOfType, pointing =
to=20
MyType (it's EType property ponits MyType).

I would like to let the user choose (into the PropertiesView) the =
acttual=20
type (XType or YType) when he creates an A element into the editor.

At the moment, I have to create an instance of XType and an instance of=20
YType (when opening a new model into the editor), otherwise, the user=20
will see nothing into the combo box of the isOfType property (into the=20
PropertiesView).

It would seem more like it to me just to see the possible types (XType =
or=20
YType) into that combo box, instead of a list of their instances.

Am I wrong about this? Could it be done like I want to? Help, please...



Floppy



=20

=20

------=_NextPart_000_00DC_01C8255D.B531B8A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.6000.16544" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV>"So it sounds like you want an EReference to an EClass and have the =
choices=20
limited to EClasses for which MyType is a super type.&nbsp; Is that=20
right?"</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>It's right. I mean if I say that is of type MyType, =
I would=20
excpect to see a list of classes that are of this type (MyType) or =
inherit from=20
this one. The problem is that I see nothing in the list! Only if I =
create some=20
instances of these classes, then I can see them in the =
list...</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Then, where is this </FONT><FONT=20
size=3D3>"getChoiceOfValues()"</FONT><FONT size=3D2>?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Thanks a lot again,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Floppy</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:fh9vuj$1ec$1@build.eclipse.org">news:fh9vuj$1ec$1@build.ecli=
pse.org</A>...</DIV>Florin,<BR><BR>Comments=20
below.<BR><BR><BR>Florin Banica wrote:=20
<BLOCKQUOTE cite=3Dmid:fh9v20$ut6$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Hi Ed,

and thsnks for the answer. But, maybe I wasn't very clear in what I =
said.
Sorry about that.

You suggested to use a EReference... So I have this .ecore:
- MyModel
- MyType (abstract class)
- XType (inherits form MyType)
- YType (inherits form MyType)
- AElement
-&gt; isOfType (EReference, containment: true): MyType

What I want is to select the type from the combo box (in the
PropertiesView), but this combo box is empty; it should only contain =
XType
and YType as types, not instances of these types. Since XType and YType =
are
delcared into the metamodel, I should be able to point them, shouldn't =
I?
</PRE></BLOCKQUOTE>So it sounds like you want an EReference to an =
EClass and=20
have the choices limited to EClasses for which MyType is a super =
type.&nbsp;=20
Is that right?&nbsp;&nbsp; You could certainly do that with a =
non-containment=20
EReference to EClass.&nbsp; You could specialize the property =
descriptor's=20
getChoiceOfValues() to list only the EClasses you intend to have =
listed.&nbsp;=20
It might be better to enumerate the choices and represent them as an =
EEnum.=20
<BR>
<BLOCKQUOTE cite=3Dmid:fh9v20$ut6$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">I just want to say that AElement is of type =
XType, not to create an instance
of XType and point it (the instance of the XType will be created later =
by
some other part of the application which takes my model and uses it).

Thanks again,



Floppy



"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</A> wrote in =
message=20
<A class=3Dmoz-txt-link-freetext =
href=3D"news:fh9olk$bro$1@build.eclipse.org">news:fh9olk$bro$1@build.ecli=
pse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Florin,

It sounds a little like you should use a containment reference and then=20
the suer could create an XType or a YType instance. If you have a=20
non-containment reference, the object it references needs to be =
contained=20
elsewhere in order for the over all result to be serializeable. You =
can=20
use the GenFeature's properties to make the reference show up as =
children=20
in the tree and to support creation commands, and to eliminate the=20
properties view for it, but you'll need to do something to ensure that =
any=20
children you create are actually containment somewhere...


Florin Banica wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hi all,

I would like to ask for your help with this one: I want to define my own =

type into the .ecore file.

Let's say MyType is an abstract class inherited by XType and YType. I=20
have another class A which has an EAttribute called isOfType, pointing =
to=20
MyType (it's EType property ponits MyType).

I would like to let the user choose (into the PropertiesView) the =
acttual=20
type (XType or YType) when he creates an A element into the editor.

At the moment, I have to create an instance of XType and an instance of=20
YType (when opening a new model into the editor), otherwise, the user=20
will see nothing into the combo box of the isOfType property (into the=20
PropertiesView).

It would seem more like it to me just to see the possible types (XType =
or=20
YType) into that combo box, instead of a list of their instances.

Am I wrong about this? Could it be done like I want to? Help, please...



Floppy



</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_00DC_01C8255D.B531B8A0--
Re: Defining my own types [message #414552 is a reply to message #414548] Mon, 12 November 2007 17:28 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Florin Banica wrote:
> Hi Felix,
>
> you're right, but my problem persists (see above, the answer to Ed). Any
> idea how to face it? Is my idea wrong/impossible? I would be happy to
> understand why...

You could really do what Ed suggessted in the other part of this message
tree. But: You see that this involves some more complicated stuff like
overriding some methods (in the generated editor code ?) If I am right
then the constraint would just be on the editor and not intrinsic to the
model. The model would say, isOfType can be set to ANY EClass. The other
way Ed suggested is to model an EEnumeration with two literals that
represent the two types "XType" and "YType". Possibly this is the better
and certainly the easier solution.
Possibly the best solution is to rethink what you want to do, I´m
thinking that you might be creating an antipattern with your current
approach. If you´d like to explain further what your intentions are
maybe people could help more.

Felix
Re: Defining my own types [message #414553 is a reply to message #414549] Mon, 12 November 2007 17:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030704020302000007090303
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Florin,

Comments below.

Florin Banica wrote:
> "So it sounds like you want an EReference to an EClass and have the
> choices limited to EClasses for which MyType is a super type. Is that
> right?"
>
> It's right. I mean if I say that is of type MyType, I would excpect to
> see a list of classes that are of this type (MyType) or inherit from
> this one.
No, you should expect to see a list of instances of MyType, not of
subclasses of MyType.
> The problem is that I see nothing in the list! Only if I create some
> instances of these classes, then I can see them in the list...
And that's why. What you are saying you want to see in the list are
EClasses and so the feature needs to be of type EClass.
>
> Then, where is this "getChoiceOfValues()"?

Here's an example from ETypedElementItemProvider for how to specialize
the choices in the dropdown:

protected void addETypePropertyDescriptor(Object object)
{
itemPropertyDescriptors.add
(new ItemPropertyDescriptor

(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("_UI_ETypedElement_eType_feature"),
getString("_UI_PropertyDescriptor_description",
"_UI_ETypedElement_eType_feature", "_UI_ETypedElement_type"),
EcorePackage.eINSTANCE.getETypedElement_EType(),
true,
false,
true,
null,
null,
null)
{
@Override
public Collection<?> getChoiceOfValues(Object object)
{
// Filter out types that aren't permitted.
//
Collection<Object> result = new
ArrayList<Object>(super.getChoiceOfValues(object));

for (Object classifier :
EcorePackage.eINSTANCE.getEClassifiers())
{
if (classifier instanceof EClass)
{
result.remove(classifier);
}
else if (!result.contains(classifier))
{
result.add(classifier);
}
}
result.add(EcorePackage.Literals.EOBJECT);

if (object instanceof EAttribute)
{
for (Iterator<Object> i = result.iterator(); i.hasNext(); )
{
if (i.next() instanceof EClass)
{
i.remove();
}
}
}
else if (object instanceof EReference)
{
for (Iterator<Object> i = result.iterator(); i.hasNext(); )
{
if (i.next() instanceof EDataType)
{
i.remove();
}
}
}

// Let them choose type parameters as well.
//
for (EObject eObject = (EObject)object; eObject != null;
eObject = eObject.eContainer())
{
if (eObject instanceof EClassifier)
{
result.addAll(((EClassifier)eObject).getETypeParameters());
}
else if (eObject instanceof EOperation)
{
result.addAll(((EOperation)eObject).getETypeParameters());
}
}

return result;
}

@Override
public void setPropertyValue(Object object, Object value)
{
EditingDomain editingDomain = getEditingDomain(object);
if (editingDomain == null)
{
super.setPropertyValue(object, value);
}
else
{

EGenericType eGenericType = null;
if (value instanceof EClassifier)
{
EClassifier eClassifier = (EClassifier)value;
eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setEClassifier(eClassifier);
for (int i = 0, size =
eClassifier.getETypeParameters().size(); i < size; ++i)
{

eGenericType.getETypeArguments().add(EcoreFactory.eINSTANCE. createEGenericType());
}
}
else if (value instanceof ETypeParameter)
{
eGenericType = EcoreFactory.eINSTANCE.createEGenericType();
eGenericType.setETypeParameter((ETypeParameter)value);
}
editingDomain.getCommandStack().execute
(SetCommand.create(editingDomain, object,
EcorePackage.Literals.ETYPED_ELEMENT__EGENERIC_TYPE, eGenericType));
}
}
});
}


>
> Thanks a lot again,
>
>
>
> Floppy
>
>
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:fh9vuj$1ec$1@build.eclipse.org...
> Florin,
>
> Comments below.
>
>
> Florin Banica wrote:
>> Hi Ed,
>>
>> and thsnks for the answer. But, maybe I wasn't very clear in what I said.
>> Sorry about that.
>>
>> You suggested to use a EReference... So I have this .ecore:
>> - MyModel
>> - MyType (abstract class)
>> - XType (inherits form MyType)
>> - YType (inherits form MyType)
>> - AElement
>> -> isOfType (EReference, containment: true): MyType
>>
>> What I want is to select the type from the combo box (in the
>> PropertiesView), but this combo box is empty; it should only contain XType
>> and YType as types, not instances of these types. Since XType and YType are
>> delcared into the metamodel, I should be able to point them, shouldn't I?
>>
> So it sounds like you want an EReference to an EClass and have the
> choices limited to EClasses for which MyType is a super type. Is
> that right? You could certainly do that with a non-containment
> EReference to EClass. You could specialize the property
> descriptor's getChoiceOfValues() to list only the EClasses you
> intend to have listed. It might be better to enumerate the
> choices and represent them as an EEnum.
>> I just want to say that AElement is of type XType, not to create an instance
>> of XType and point it (the instance of the XType will be created later by
>> some other part of the application which takes my model and uses it).
>>
>> Thanks again,
>>
>>
>>
>> Floppy
>>
>>
>>
>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>> news:fh9olk$bro$1@build.eclipse.org...
>>
>>> Florin,
>>>
>>> It sounds a little like you should use a containment reference and then
>>> the suer could create an XType or a YType instance. If you have a
>>> non-containment reference, the object it references needs to be contained
>>> elsewhere in order for the over all result to be serializeable. You can
>>> use the GenFeature's properties to make the reference show up as children
>>> in the tree and to support creation commands, and to eliminate the
>>> properties view for it, but you'll need to do something to ensure that any
>>> children you create are actually containment somewhere...
>>>
>>>
>>> Florin Banica wrote:
>>>
>>>> Hi all,
>>>>
>>>> I would like to ask for your help with this one: I want to define my own
>>>> type into the .ecore file.
>>>>
>>>> Let's say MyType is an abstract class inherited by XType and YType. I
>>>> have another class A which has an EAttribute called isOfType, pointing to
>>>> MyType (it's EType property ponits MyType).
>>>>
>>>> I would like to let the user choose (into the PropertiesView) the acttual
>>>> type (XType or YType) when he creates an A element into the editor.
>>>>
>>>> At the moment, I have to create an instance of XType and an instance of
>>>> YType (when opening a new model into the editor), otherwise, the user
>>>> will see nothing into the combo box of the isOfType property (into the
>>>> PropertiesView).
>>>>
>>>> It would seem more like it to me just to see the possible types (XType or
>>>> YType) into that combo box, instead of a list of their instances.
>>>>
>>>> Am I wrong about this? Could it be done like I want to? Help, please...
>>>>
>>>>
>>>>
>>>> Floppy
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>


--------------030704020302000007090303
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Florin,<br>
<br>
Comments below.<br>
<br>
Florin Banica wrote:
<blockquote cite="mid:fha0jj$34m$1@build.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.6000.16544" name="GENERATOR">
<style></style>
<div>"So it sounds like you want an EReference to an EClass and have
the choices limited to EClasses for which MyType is a super type.&nbsp; Is
that right?"</div>
<div>&nbsp;</div>
<div><font size="2">It's right. I mean if I say that is of type
MyType, I would excpect to see a list of classes that are of this type
(MyType) or inherit from this one.</font></div>
</blockquote>
No, you should expect to see a list of instances of MyType, not of
subclasses of MyType.<br>
<blockquote cite="mid:fha0jj$34m$1@build.eclipse.org" type="cite">
<div><font size="2"> The problem is that I see nothing in the list!
Only if I create some instances of these classes, then I can see them
in the list...</font></div>
</blockquote>
And that's why.&nbsp; What you are saying you want to see in the list are
EClasses and so the feature needs to be of type EClass.<br>
<blockquote cite="mid:fha0jj$34m$1@build.eclipse.org" type="cite">
<div>&nbsp;</div>
<div><font size="2">Then, where is this </font><font size="3">"getChoiceOfValues()"</font><font
size="2">?</font></div>
</blockquote>
<br>
Here's an example from ETypedElementItemProvider for how to specialize
the choices in the dropdown:<br>
<br>
<small><small>&nbsp; protected void addETypePropertyDescriptor(Object object)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; itemPropertyDescriptors.add<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (new ItemPropertyDescriptor<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(), <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; getResourceLocator(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; getString("_UI_ETypedElement_eType_feature"),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; getString("_UI_PropertyDescriptor_description",
"_UI_ETypedElement_eType_feature", "_UI_ETypedElement_type"),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; EcorePackage.eINSTANCE.getETypedElement_EType(),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; false,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; true,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; null,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; null,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public Collection&lt;?&gt; getChoiceOfValues(Object object)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; // Filter out types that aren't permitted.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; Collection&lt;Object&gt; result = new
ArrayList&lt;Object&gt;(super.getChoiceOfValues(obje ct)); <br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for (Object classifier :&nbsp;
EcorePackage.eINSTANCE.getEClassifiers())<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (classifier instanceof EClass)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; result.remove(classifier);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (!result.contains(classifier))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; result.add(classifier);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; result.add(EcorePackage.Literals.EOBJECT);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if (object instanceof EAttribute)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Iterator&lt;Object&gt; i = result.iterator();
i.hasNext(); )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if (i.next() instanceof EClass)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; i.remove();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; else if (object instanceof EReference)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Iterator&lt;Object&gt; i = result.iterator();
i.hasNext(); )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if (i.next() instanceof EDataType)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; i.remove();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; // Let them choose type parameters as well.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for (EObject eObject = (EObject)object; eObject != null;
eObject = eObject.eContainer())<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eObject instanceof EClassifier)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
result.addAll(((EClassifier)eObject).getETypeParameters());<br >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (eObject instanceof EOperation)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
result.addAll(((EOperation)eObject).getETypeParameters());<br >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; return result;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; public void setPropertyValue(Object object, Object value)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; EditingDomain editingDomain = getEditingDomain(object);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if (editingDomain == null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.setPropertyValue(object, value);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; else <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EGenericType eGenericType = null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (value instanceof EClassifier)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; EClassifier eClassifier = (EClassifier)value;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; eGenericType.setEClassifier(eClassifier);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; for (int i = 0, size =
eClassifier.getETypeParameters().size(); i &lt; size; ++i)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
eGenericType.getETypeArguments().add(EcoreFactory.eINSTANCE. createEGenericType()); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (value instanceof ETypeParameter)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; eGenericType =
EcoreFactory.eINSTANCE.createEGenericType();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; eGenericType.setETypeParameter((ETypeParameter)value);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; editingDomain.getCommandStack().execute<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; (SetCommand.create(editingDomain, object,
EcorePackage.Literals.ETYPED_ELEMENT__EGENERIC_TYPE, eGenericType));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>
&nbsp; }</small></small><br>
<br>
<br>
<blockquote cite="mid:fha0jj$34m$1@build.eclipse.org" type="cite">
<div>&nbsp;</div>
<div><font size="2">Thanks a lot again,</font></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><font size="2">Floppy</font></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div>"Ed Merks" &lt;<a moz-do-not-send="true"
href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>&gt; wrote in
message <a moz-do-not-send="true"
href="news:fh9vuj$1ec$1@build.eclipse.org">news:fh9vuj$1ec$1@build.eclipse.org</a>...</div>
Florin,<br>
<br>
Comments below.<br>
<br>
<br>
Florin Banica wrote:
<blockquote cite="mid:fh9v20$ut6$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,

and thsnks for the answer. But, maybe I wasn't very clear in what I said.
Sorry about that.

You suggested to use a EReference... So I have this .ecore:
- MyModel
- MyType (abstract class)
- XType (inherits form MyType)
- YType (inherits form MyType)
- AElement
-&gt; isOfType (EReference, containment: true): MyType

What I want is to select the type from the combo box (in the
PropertiesView), but this combo box is empty; it should only contain XType
and YType as types, not instances of these types. Since XType and YType are
delcared into the metamodel, I should be able to point them, shouldn't I?
</pre>
</blockquote>
So it sounds like you want an EReference to an EClass and have the
choices limited to EClasses for which MyType is a super type.&nbsp; Is that
right?&nbsp;&nbsp; You could certainly do that with a non-containment EReference
to EClass.&nbsp; You could specialize the property descriptor's
getChoiceOfValues() to list only the EClasses you intend to have
listed.&nbsp; It might be better to enumerate the choices and represent them
as an EEnum. <br>
<blockquote cite="mid:fh9v20$ut6$1@build.eclipse.org" type="cite">
<pre wrap="">I just want to say that AElement is of type XType, not to create an instance
of XType and point it (the instance of the XType will be created later by
some other part of the application which takes my model and uses it).

Thanks again,



Floppy



"Ed Merks" <a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href="news:fh9olk$bro$1@build.eclipse.org">news:fh9olk$bro$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Florin,

It sounds a little like you should use a containment reference and then
the suer could create an XType or a YType instance. If you have a
non-containment reference, the object it references needs to be contained
elsewhere in order for the over all result to be serializeable. You can
use the GenFeature's properties to make the reference show up as children
in the tree and to support creation commands, and to eliminate the
properties view for it, but you'll need to do something to ensure that any
children you create are actually containment somewhere...


Florin Banica wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,

I would like to ask for your help with this one: I want to define my own
type into the .ecore file.

Let's say MyType is an abstract class inherited by XType and YType. I
have another class A which has an EAttribute called isOfType, pointing to
MyType (it's EType property ponits MyType).

I would like to let the user choose (into the PropertiesView) the acttual
type (XType or YType) when he creates an A element into the editor.

At the moment, I have to create an instance of XType and an instance of
YType (when opening a new model into the editor), otherwise, the user
will see nothing into the combo box of the isOfType property (into the
PropertiesView).

It would seem more like it to me just to see the possible types (XType or
YType) into that combo box, instead of a list of their instances.

Am I wrong about this? Could it be done like I want to? Help, please...



Floppy



</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------030704020302000007090303--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Defining my own types [message #414554 is a reply to message #414552] Mon, 12 November 2007 17:37 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010102010608070100000207
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Felix,

I agree that it sounds all very odd. Understanding the point of the
design would likely help guide it in a better direction.


Felix Dorner wrote:
> Florin Banica wrote:
>
>> Hi Felix,
>>
>> you're right, but my problem persists (see above, the answer to Ed). Any
>> idea how to face it? Is my idea wrong/impossible? I would be happy to
>> understand why...
>>
>
> You could really do what Ed suggessted in the other part of this message
> tree. But: You see that this involves some more complicated stuff like
> overriding some methods (in the generated editor code ?) If I am right
> then the constraint would just be on the editor and not intrinsic to the
> model. The model would say, isOfType can be set to ANY EClass. The other
> way Ed suggested is to model an EEnumeration with two literals that
> represent the two types "XType" and "YType". Possibly this is the better
> and certainly the easier solution.
> Possibly the best solution is to rethink what you want to do, I


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Problem with Generics, inheritance and ecore validation
Next Topic:Which rose edition is suitable for creating/exporting ecore models
Goto Forum:
  


Current Time: Fri Apr 26 14:14:13 GMT 2024

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

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

Back to the top