I'm working with Eclipse RCP. There I have a view with the standard method createPartControl(Composite parent) which I have implemented as follows:
public void createPartControl(Composite parent) {
this.parent = parent;
createContent();
}
In createContent(), the composite parent gets a few elements (e. g. a table with the state of something) which I would like to update. Therefore, I have an update button. When you click on it, all children of parent should be disposed and the method createPartControl(parent) should be executed again.
This is my current code for that:
buttonUpdate = new Button(parent, SWT.NONE);
buttonUpdate.setText("Update");
GridData gridData = new GridData(80, 30);
buttonUpdate.setLayoutData(gridData);
buttonUpdate.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
for (Control control : parent.getChildren()) {
control.dispose();
}
createPartControl(parent);
break;
}
}
});
When I started my application and clicked on the update button, the window becomes empty but no new content appears. Only, when I open another view in my app and then switch back, I see the updated content. How to make the new content visible immediately?
You need to layout the parent composite again.
Call
after the
createPartControl
call.