|
|
|
Re: Notification between EObjects (used for updating calculated fields) [message #429157 is a reply to message #429156] |
Fri, 10 April 2009 13:29 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------040007070009010304000702
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Cristi,
Comments below.
Cristian wrote:
> Dear Ed,
>
> Thanks a lot for your answer. I have one more question regarding this
> technique and regarding possible memory leaks.
Yes, that's definitely a cause for concern.
>
> I will add my adapter to the "listened" object within the setLabel
> method like this:
>
> if (oldLabel != newLabel) {
> oldLabel.eAdapters().remove(myChangeListenerAdapter);
> newLabel.eAdapters().add(myChangeListenerAdapter);
> }
>
> Is there another place when I should be careful to remove
> myChangeListener?
Is it a proxy resolving reference? If so, the getter will need attention.
> * I guess that if I delete the listened object, the setter will be
> automatically called with a null argument.
Yes.
> * What happens if I delete the main object (Proxy in my case)? I have
> looked briefly at the code of DeleteCommand and I'm under the
> impression that it doesn't notify in any way the deleted object (and
> there is no "dispose" method). Does this means that I need to override
> the DeleteCommand as well?
Just keep in mind that a delete can be undone too. Perhaps it would be
good for the adapter to have a weak reference to the Proxy and you could
set it up so that when the adapter is notified and the Proxy reference
has been collected, that the adapter removes itself. Or better yet,
though I've not played much with finalize, but I suppose the finalize
could be specialized to remove the adapter. I.e., do something that
will work purely at the model level... Probably we should have some
type of nice recipe in the wiki for something like this...
http://wiki.eclipse.org/EMF/Recipes
> * Are there any other use cases which can lead to "memory leak"? I.e.
> one or both of the objects don't exist anymore in the model, but they
> will be still in memory (in a state that won't allow the garbage
> collector to finally destroy them)?
I can't think of anything else at the moment. It will be nice to hear
back about your experience. Perhaps you'd be so kind as to create a new
recipe in the wiki so we can work on polishing it together...
>
> Best regards,
> Cristi.
>
--------------040007070009010304000702
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Cristi,<br>
<br>
Comments below.<br>
<br>
Cristian wrote:
<blockquote
cite="mid:36976b274b2c9b26ae32d4c14b7b8dbf$1@www.eclipse.org"
type="cite">Dear Ed,
<br>
<br>
Thanks a lot for your answer. I have one more question regarding this
technique and regarding possible memory leaks.
<br>
</blockquote>
Yes, that's definitely a cause for concern.<br>
<blockquote
cite="mid:36976b274b2c9b26ae32d4c14b7b8dbf$1@www.eclipse.org"
type="cite"><br>
I will add my adapter to the "listened" object within the setLabel
method like this:
<br>
<br>
if (oldLabel != newLabel) {
<br>
oldLabel.eAdapters().remove(myChangeListenerAdapter);
<br>
newLabel.eAdapters().add(myChangeListenerAdapter);
<br>
}
<br>
<br>
Is there another place when I should be careful to remove
myChangeListener? <br>
</blockquote>
Is it a proxy resolving reference? If so, the getter will need
attention.<br>
<blockquote
cite="mid:36976b274b2c9b26ae32d4c14b7b8dbf$1@www.eclipse.org"
type="cite">* I guess that if I delete the listened object, the setter
will be automatically called with a null argument.
<br>
</blockquote>
Yes.<br>
<blockquote
cite="mid:36976b274b2c9b26ae32d4c14b7b8dbf$1@www.eclipse.org"
type="cite">* What happens if I delete the main object (Proxy in my
case)? I have looked briefly at the code of DeleteCommand and I'm under
the impression that it doesn't notify in any way the deleted object
(and there is no "dispose" method). Does this means that I need to
override the DeleteCommand as well?
<br>
</blockquote>
Just keep in mind that a delete can be undone too.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Notification between EObjects (used for updating calculated fields) [message #429195 is a reply to message #429193] |
Mon, 13 April 2009 18:03 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Cristi,
Yes, DeleteCommand is handled directly by the editing domain and would
be specialized there. The item providers only see the RemoveCommands.
Cristian wrote:
> Dear Ed,
>
>> I can't think of anything else at the moment. It will be nice to
>> hear back about your experience. Perhaps you'd be so kind as to
>> create a new recipe in the wiki so we can work on polishing it
>> together...
> I didn't know about this page. I have almost finished the
> implementation. I will be glad to contribute with it. I get back when
> completly finished.
>
> Regarding the DeleteCommand, I have seen that it cannot be replaced
> using the standard ContentProvidar way if i use the
> AdapterFactoryEditingDomain. Making a custom EditingDomain (based on
> AdapterFactoryEditingDomain for example) and overriding the
> createCommand() method seems the only way to replace the
> DeleteCommand. Am I right, or am I missing something?
>
> Thanks.
> Best regards,
> Cristi.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03298 seconds