Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » re-using a composite
re-using a composite [message #467075] Tue, 24 January 2006 14:41 Go to next message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
I have a composite (from a FormEditor section).

I initially populate it during public void createContents(Composite
parent) and it appears.

When I get a selection event I want to clear out the composite and refill
it again. I have looked at examples but they all seem to use the same
widgets but just change their contents. In my case I cannot do that as the
first selection might require a combo and then a text wheras the next
might be the other way around.

What I don't want to do is go around orphaning widgets. I build my layout
on a new composite and add that to the parent composite so everything I
want to get rid of is on the single composite.

Can I just dispose the composite and create a new one on the parent?

Will disposing a composite manually also do the same to all its children?

Is it ok to manually dispose a composite while on a parent, does that
automatically remove it from the parents list of children ( I can't find a
removeChild(widget) method)

I have tried looking in the source but have not found anything that
answers these questions.

The dispose comments on widgets are a bit confusing as it says it disposes
all dependants (does not make it clear if direct descendants or not) but
then goes on to say it does not recursively call dependants so I am none
the wiser

Disposes of the operating system resources associated with
* the receiver and all its descendents. After this method has
* been invoked, the receiver and all descendents will answer
* <code>true</code> when sent the message <code>isDisposed()</code>.
* Any internal connections between the widgets in the tree will
* have been removed to facilitate garbage collection.
* <p>
* NOTE: This method is not called recursively on the descendents
* of the receiver. This means that, widget implementers can not
* detect when a widget is being disposed of by re-implementing
* this method, but should instead listen for the <code>Dispose</code>
* event.
Re: re-using a composite [message #467078 is a reply to message #467075] Tue, 24 January 2006 15:16 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Disposing a Composite will dispose all of its children and its children's
children all the way down the parent heirarchy.

If the widgets can change back to the old configuration when the selection
changes again, you might want to consider keeping them around. In that case
you could use a StackLayout.

See the following article for an explanation of how disposing works:

http://www.eclipse.org/articles/swt-design-2/swt-design-2.ht ml


<Phill_Perryman@Mitel.COM> wrote in message
news:dr5ebp$1ch$1@utils.eclipse.org...
>I have a composite (from a FormEditor section).
>
> I initially populate it during public void createContents(Composite
> parent) and it appears.
>
> When I get a selection event I want to clear out the composite and refill
> it again. I have looked at examples but they all seem to use the same
> widgets but just change their contents. In my case I cannot do that as the
> first selection might require a combo and then a text wheras the next
> might be the other way around.
>
> What I don't want to do is go around orphaning widgets. I build my layout
> on a new composite and add that to the parent composite so everything I
> want to get rid of is on the single composite.
>
> Can I just dispose the composite and create a new one on the parent?
>
> Will disposing a composite manually also do the same to all its children?
>
> Is it ok to manually dispose a composite while on a parent, does that
> automatically remove it from the parents list of children ( I can't find a
> removeChild(widget) method)
>
> I have tried looking in the source but have not found anything that
> answers these questions.
>
> The dispose comments on widgets are a bit confusing as it says it disposes
> all dependants (does not make it clear if direct descendants or not) but
> then goes on to say it does not recursively call dependants so I am none
> the wiser
>
> Disposes of the operating system resources associated with
> * the receiver and all its descendents. After this method has
> * been invoked, the receiver and all descendents will answer
> * <code>true</code> when sent the message <code>isDisposed()</code>.
> * Any internal connections between the widgets in the tree will
> * have been removed to facilitate garbage collection.
> * <p>
> * NOTE: This method is not called recursively on the descendents
> * of the receiver. This means that, widget implementers can not
> * detect when a widget is being disposed of by re-implementing
> * this method, but should instead listen for the <code>Dispose</code>
> * event.
Re: re-using a composite [message #467087 is a reply to message #467078] Tue, 24 January 2006 16:18 Go to previous message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
Thanks, now I just can't figure out why it does not work. I have the
following code which produces the FormText field on creation but it all
goes blank on update (called by the selection changed event and I am
getting the correct selection event in debug).

I have cut everything out but a single widget to test the process. I have
tried all combinations of the layout in the update code with no effect, am
I just missing something basic.

public void createContents(Composite parentComposite) {
parent = parentComposite;
toolkit = managedForm.getToolkit();
parentComposite.setLayout(new GridLayout());
section = toolkit.createSection(parentComposite,
ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
section.setLayoutData(new GridData(GridData.FILL_BOTH));
section.setText("Configuration");

composite = toolkit.createComposite(section, SWT.NONE);
composite.setLayout(new TableWrapLayout());
toolkit.paintBordersFor(composite);
section.setClient(composite);
FormText formText = toolkit.createFormText(composite,
false);
formText.setText("New FormText", false, false);
}

private void update() {
composite.dispose();
composite = toolkit.createComposite(section, SWT.NONE);
composite.setLayout(new TableWrapLayout());
toolkit.paintBordersFor(composite);
section.setClient(composite);
FormText formText = toolkit.createFormText(composite,
false);
formText.setText(selection.getId(), false, false);
composite.layout(true);
section.layout(true);
parent.layout(true);
}
Previous Topic:IFolder.resfreshLocal() doesn't show new files
Next Topic:Image Operations
Goto Forum:
  


Current Time: Thu Apr 25 21:13:17 GMT 2024

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

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

Back to the top