Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Implementing Setters for Derived references
Implementing Setters for Derived references [message #425144] Mon, 17 November 2008 03:17 Go to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
I have a base class which contains a list of products (0 to many)

I have a whole sub set of these which always take 2 products and these
products are a sub type of Product. For convenience (particularly for ocl)
I want to add two derived references for these

i.e.

class Base
EList<Product> products

class TwoFooProducts extends Base
FooProduct p1; // derived from products.get(0)
FooProduct p2; // derived from products.get(1)

To implement this I set p1 & p2 as derived, transient and volatile. I then
need to provide implementations of getP1(), basicSetP1() and setP1 &
similar for p2. Not entirely sure what I should be doing in the setters in
regards to the NotificationChain?

e.g. I've so far implemented basicSetP1 as follows but suspect this is not
correct.

public NotificationChain basicSetP1(FooProduct newP1,
NotificationChain msgs)
{
if (getProduct().size() == 0)
getProduct().add(newP1);
else
getProduct().set(0, newP1);

return msgs;
}

public void setP1(FooProduct newP1)
{
basicSetP1(newP1, null);
}


How should I have implemented these?
Re: Implementing Setters for Derived references [message #425146 is a reply to message #425144] Mon, 17 November 2008 08:30 Go to previous messageGo to next message
Tristan Faure is currently offline Tristan FaureFriend
Messages: 460
Registered: July 2009
Senior Member
Hi !
maybe you should use mechanism described in this bug :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=216701

for more information Ed merks or Christian W Damus will more capable


Andrew H a écrit :
> I have a base class which contains a list of products (0 to many)
>
> I have a whole sub set of these which always take 2 products and these
> products are a sub type of Product. For convenience (particularly for
> ocl) I want to add two derived references for these
>
> i.e.
>
> class Base
> EList<Product> products
>
> class TwoFooProducts extends Base
> FooProduct p1; // derived from products.get(0)
> FooProduct p2; // derived from products.get(1)
>
> To implement this I set p1 & p2 as derived, transient and volatile. I
> then need to provide implementations of getP1(), basicSetP1() and setP1
> & similar for p2. Not entirely sure what I should be doing in the
> setters in regards to the NotificationChain?
>
> e.g. I've so far implemented basicSetP1 as follows but suspect this is
> not correct.
>
> public NotificationChain basicSetP1(FooProduct newP1,
> NotificationChain msgs)
> {
> if (getProduct().size() == 0)
> getProduct().add(newP1);
> else
> getProduct().set(0, newP1);
> return msgs;
> }
>
> public void setP1(FooProduct newP1)
> {
> basicSetP1(newP1, null);
> }
>
>
> How should I have implemented these?
>
>




Re: Implementing Setters for Derived references [message #425165 is a reply to message #425146] Mon, 17 November 2008 23:22 Go to previous messageGo to next message
Andrew H is currently offline Andrew HFriend
Messages: 117
Registered: July 2009
Senior Member
Thanks Tristan

I thought that bugzilla was still a bit of an R&D project, not ready for
general use.

Are you saying that some part of it is ready for use?

thanks

Andrew

Tristan FAURE wrote:

> Hi !
> maybe you should use mechanism described in this bug :
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=216701

> for more information Ed merks or Christian W Damus will more capable


> Andrew H a écrit :
>> I have a base class which contains a list of products (0 to many)
>>
>> I have a whole sub set of these which always take 2 products and these
>> products are a sub type of Product. For convenience (particularly for
>> ocl) I want to add two derived references for these
>>
>> i.e.
>>
>> class Base
>> EList<Product> products
>>
>> class TwoFooProducts extends Base
>> FooProduct p1; // derived from products.get(0)
>> FooProduct p2; // derived from products.get(1)
>>
>> To implement this I set p1 & p2 as derived, transient and volatile. I
>> then need to provide implementations of getP1(), basicSetP1() and setP1
>> & similar for p2. Not entirely sure what I should be doing in the
>> setters in regards to the NotificationChain?
>>
>> e.g. I've so far implemented basicSetP1 as follows but suspect this is
>> not correct.
>>
>> public NotificationChain basicSetP1(FooProduct newP1,
>> NotificationChain msgs)
>> {
>> if (getProduct().size() == 0)
>> getProduct().add(newP1);
>> else
>> getProduct().set(0, newP1);
>> return msgs;
>> }
>>
>> public void setP1(FooProduct newP1)
>> {
>> basicSetP1(newP1, null);
>> }
>>
>>
>> How should I have implemented these?
>>
>>
Re: Implementing Setters for Derived references [message #425170 is a reply to message #425165] Tue, 18 November 2008 06:54 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Andrew,

It's not quite ready yet...

Andrew H wrote:
> Thanks Tristan
>
> I thought that bugzilla was still a bit of an R&D project, not ready
> for general use.
>
> Are you saying that some part of it is ready for use?
>
> thanks
>
> Andrew
>
> Tristan FAURE wrote:
>
>> Hi !
>> maybe you should use mechanism described in this bug :
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=216701
>
>> for more information Ed merks or Christian W Damus will more capable
>
>
>> Andrew H a écrit :
>>> I have a base class which contains a list of products (0 to many)
>>>
>>> I have a whole sub set of these which always take 2 products and
>>> these products are a sub type of Product. For convenience
>>> (particularly for ocl) I want to add two derived references for these
>>>
>>> i.e.
>>>
>>> class Base
>>> EList<Product> products
>>>
>>> class TwoFooProducts extends Base
>>> FooProduct p1; // derived from products.get(0)
>>> FooProduct p2; // derived from products.get(1)
>>>
>>> To implement this I set p1 & p2 as derived, transient and volatile.
>>> I then need to provide implementations of getP1(), basicSetP1() and
>>> setP1 & similar for p2. Not entirely sure what I should be doing in
>>> the setters in regards to the NotificationChain?
The list implements InternalEList which has the methods you need. One
problem though is you can't use inverseAdd/inverseRemove with a position
and of course you can't set the second item of the list if the first
doesn't exist yet.
>>>
>>> e.g. I've so far implemented basicSetP1 as follows but suspect this
>>> is not correct.
>>>
>>> public NotificationChain basicSetP1(FooProduct newP1,
>>> NotificationChain msgs)
>>> {
>>> if (getProduct().size() == 0)
>>> getProduct().add(newP1);
>>> else
>>> getProduct().set(0, newP1);
>>> return msgs;
>>> }
>>>
>>> public void setP1(FooProduct newP1)
>>> {
>>> basicSetP1(newP1, null);
>>> }
>>>
>>>
>>> How should I have implemented these?
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Attributes of type EnumSet<E>?
Next Topic:FeatureID=-1
Goto Forum:
  


Current Time: Fri Sep 20 14:48:16 GMT 2024

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

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

Back to the top