[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Adding widgets to a composite after creation.

Hi,
Yestoday I just try a way: switch parent of composite, but problemed, I cannot dare use it:
(Main code)


client.setLayout(new MigLayout());
Group g1= new Group(client, SWT.DEFAULT);
g1.setText("group1");
g1.setLayout(new MigLayout());
Group g2= new Group(client, SWT.DEFAULT);
g2.setText("group2");
g2.setLayout(new MigLayout());

Text t1 = new Text(g1, SWT.NONE);
final Label l1 = new Label(g1, SWT.NONE);
l1.setText("label1");
final Label l2 = new Label(g2, SWT.NONE);
l2.setText("label2");
Text t2 = new Text(g2, SWT.NONE);
Button b = new Button(client, SWT.PUSH);
b.setText("change");
b.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
Composite parent = l1.getParent();
l1.setParent(l2.getParent());
l2.getParent().changed(l2.getParent().getChildren());
l2.setParent(parent);
parent.changed(parent.getChildren());
parent.redraw();
}});

At later of the code, changed and redraw call just try to try, soso. No effective.
It works in a case: same order. You can change the g1 and t1 order, seems works.
I not dig into, why order important? because of LayoutManager or OS getChildren, I Not into.
So, After-creation-solution should not an all-right way.Indeed at windows My before experiences tell me that it's a real way.:)
But now I not care this way.:)
So, What you want, maybe should a cache solution.But should a Object Level cache instead of Class Level cache.
f.e.
class Activity{
BaseContent content;
BaseContent getContent(){return content;}
}


new Activity(){content=new SimpleContent();}//simple content
new Activity(){content = new GroupContent();}//not so simple content

You cannot cache Activity class Form to reuse. If not, error would must be occured when switch 2 different activity objects.

haha, I just make noise at this, you see yours.:)

Cheers,
Qinxian

Mark Hibberd åé:
Adding widgets to a composite after creation.

Does anyone know if it is possible to add more widgets to a composite after creation, say via an action or something similar.
The basic idea is I need to build up a dynamic form, based on user input. I could use something very generic (something like the PropertySheetView) but I want to be able to add some more advanced input widgets depending on field type etc...


At the moment I have tried what I thought was the most obvious path, which is to store off the parent passed to 'createPartControl' then just use it from the actions like you would normally do during creation (new Label(storedParent, SWT...). But obviously that does not work or I wouldn't have to ask?

Any help appreciated (even if it is to call me stupid and point me at a way simpler way to achieve what I want).