Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to know when a child of Composite is removed(Composite, child, remove, event)
How to know when a child of Composite is removed [message #668174] Wed, 04 May 2011 10:36 Go to next message
David Luengo is currently offline David LuengoFriend
Messages: 3
Registered: May 2011
Junior Member
Hi all there.

I'm using SWT (i'm relatively new) and i had a problem i'm trying to solve but after read a lot, search a lot and think a lot i don't know how to solve it.

The problem is quite simple, i want to know when a child inside a Composite is disposed. I have extended the class Composite and i need to do some things when a child inside this new composites is disposed. First of all i thought that SWT had an Event and EventListener to handle that, something like ChildAddedEvent and ChildAddedEventListener but there wasn't something like that. I tried to use a Listener for the SWT.Modify event, something like this:

Composite my_comp = new Composite(new Shell(), SWT.NONE);
my_comp.addListener(SWT.Modify, MyOwnChildAddedListener())


Where MyOwnChildAddedListener is obviously another class i had created and that implements EventListener.

The most effective approach i had found is create a class that implements DisposeListener interface and everytime i add a new child to my composites also add explicitly an instance of this listener to that child, something like this:

public class MyDisposeListener implements DisposeListener {
@Override
public void widgetDisposed(DisposeEvent event) {
...
}
}

public class MyComposite extends Composite {
...
}

...

MyComposite my_comp = new MyComposite(new Shell(), SWT.NONE);
Control child = new Control(my_comp, SWT.NONE);
child.addDisposeListener(new MyDisposeListener());


This will do what i want to do, execute some code when a child of my composites is removed.

BUT this solution imho is quite ugly because i'm forcing the users of MyComposite to EXPLICITLY add the listener to every child s/he adds... Seriously, doesn't SWT have a way to know when a child is disposed from the composites or when a child is added?!?!

Thanks for the attention.


--
David

PD: Sorry about my English, I made my best :S
Re: How to know when a child of Composite is removed [message #668362 is a reply to message #668174] Thu, 05 May 2011 12:18 Go to previous message
Lakshmi ShanmugamFriend
Messages: 276
Registered: July 2009
Location: India
Senior Member
Hi,

When a child control is disposed the child control sends the dispose event, the Composite will not send any dispose event in this case.
You can use the Display#addFilter (int eventType, Listener listener) with eventType = SWT.Dispose to listen to all the dispose events on the widgets in the display. You could then add a check to verify if the controls's parent is your Composite.


Lakshmi P Shanmugam
Previous Topic:SWT Browser - Internet Explorer "Script Error"
Next Topic:Browser and Webkit GTK 1.3
Goto Forum:
  


Current Time: Sat Nov 28 17:38:59 GMT 2020

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

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

Back to the top