Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » AbstractEditPart>>refreshChildren bug?
AbstractEditPart>>refreshChildren bug? [message #185972] Thu, 30 June 2005 22:31 Go to next message
Emerson Murphy-Hill is currently offline Emerson Murphy-HillFriend
Messages: 22
Registered: July 2009
Junior Member
Howdy Y'all,

This appears to be a bug to me, but I could easily be doing something
wrong. I have had a problem where, when I delete a node from a
container, some other element in the container gets deleted. Bad. I
think I have tracked down the problem...

The scenario:

I have a subclass of AbstractGraphicalEditPart that redefines
getChildren() and returns a new List every time (this is necessary
because I return a typed list, using covariance). Now
AbstractEditPart>>refreshChildren looks something like this:

protected void refreshChildren() {
...
List children = getChildren();
...
if (editPart != null)
reorderChild (editPart, i);
...

List trash = new ArrayList();
for (; i < children.size(); i++)
trash.add(children.get(i));
for (i = 0; i < trash.size(); i++) {
EditPart ep = (EditPart)trash.get(i);
removeChild(ep);
...
}

The problem is, reorderChild does the reordering on the children
*field*, which happens to reorder the children *local variable* iff the
two reference the same object. In my case, they do not, since
getChildren() returns a new List. When this happens, the wrong EditPart
gets added to the trash.

So I hope this makes sense. Am I right in thinking this is a bug?

Thanks!

e
Re: AbstractEditPart>>refreshChildren bug? [message #186005 is a reply to message #185972] Fri, 01 July 2005 02:13 Go to previous messageGo to next message
Dazhen Gao is currently offline Dazhen GaoFriend
Messages: 21
Registered: July 2009
Junior Member
I think the other element don't gets deleted.See layoutmanager of the
contend pane.Debuge the layout method, I guess the fit the wrong position.
Above is my guess.
"Emerson" <emerson@cs.pdx.edu> wrote in message
news:da1rnq$l5u$1@main1.eclipse.org...
> Howdy Y'all,
>
> This appears to be a bug to me, but I could easily be doing something
> wrong. I have had a problem where, when I delete a node from a container,
> some other element in the container gets deleted. Bad. I think I have
> tracked down the problem...
>
> The scenario:
>
> I have a subclass of AbstractGraphicalEditPart that redefines
> getChildren() and returns a new List every time (this is necessary because
> I return a typed list, using covariance). Now
> AbstractEditPart>>refreshChildren looks something like this:
>
> protected void refreshChildren() {
> ...
> List children = getChildren();
> ...
> if (editPart != null)
> reorderChild (editPart, i);
> ...
>
> List trash = new ArrayList();
> for (; i < children.size(); i++)
> trash.add(children.get(i));
> for (i = 0; i < trash.size(); i++) {
> EditPart ep = (EditPart)trash.get(i);
> removeChild(ep);
> ...
> }
>
> The problem is, reorderChild does the reordering on the children *field*,
> which happens to reorder the children *local variable* iff the two
> reference the same object. In my case, they do not, since getChildren()
> returns a new List. When this happens, the wrong EditPart gets added to
> the trash.
>
> So I hope this makes sense. Am I right in thinking this is a bug?
>
> Thanks!
>
> e
Re: AbstractEditPart>>refreshChildren bug? [message #186072 is a reply to message #185972] Fri, 01 July 2005 09:22 Go to previous messageGo to next message
Andreas Holtz is currently offline Andreas HoltzFriend
Messages: 53
Registered: July 2009
Member
Emerson schrieb am 01.07.2005 00:31:
> I have a subclass of AbstractGraphicalEditPart that redefines
> getChildren() and returns a new List every time (this is necessary
> because I return a typed list, using covariance).

You should always use getModelChildren() and let GEF creates (via your
EditPartFactory) and order the corresponding Editparts. If you do it
your way, you are responsible for the consistency between the children
of your model and the children of your editpart.
If you delete an editpart, you should not do this within your
editpart-list, but within your model.
the editparts should listen on changes on the model and refresh
themselves when neccesary.

Andreas

PS: i hope, i did not tell you something, that you already know. but i
don't understand, why you overwrite getChildren().
Re: AbstractEditPart>>refreshChildren bug? [message #186106 is a reply to message #186072] Fri, 01 July 2005 18:00 Go to previous message
Emerson Murphy-Hill is currently offline Emerson Murphy-HillFriend
Messages: 22
Registered: July 2009
Junior Member
I think you are correct and your suggestion is a good strategy.

However, the reason for overriding getChildren() is because my EditPart
contains generic children. So My EditPart looks something like:

MyEditPart<ChildPartType extends EditPart>
extends GraphicalAbstractEditPart {
....
protected List<ChildPartType> getChildren(){
...//call super, and cast all children
}
....
}


From my perspective, in order to make up for the fact that EditPart is
not generic (yet!), this is a perfectly reasonable thing to do.

So I think my point still stands.

-e

Andreas Holtz wrote:
>
> You should always use getModelChildren() and let GEF creates (via your
> EditPartFactory) and order the corresponding Editparts. If you do it
> your way, you are responsible for the consistency between the children
> of your model and the children of your editpart.
> If you delete an editpart, you should not do this within your
> editpart-list, but within your model.
> the editparts should listen on changes on the model and refresh
> themselves when neccesary.
>
> Andreas
>
> PS: i hope, i did not tell you something, that you already know. but i
> don't understand, why you overwrite getChildren().
Previous Topic:Refreshing the Properties view
Next Topic:F2 key not working!!!
Goto Forum:
  


Current Time: Mon Dec 02 21:07:58 GMT 2024

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

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

Back to the top