I tried to retrieve the MPart via injection or via the EPartService, and call setLabel() on it. It worked but the change was not reflected on the rendered part. How do i update the rendered part to apply the model change?
My Part contains a CTabFolder, and i would like to set the active tab's text as the Part label:
public void showTab(String tab) {
CTabItem item = tabs.get(tab);
if (item != null) {
tabFolder.setSelection(item);
createContentsForActiveTab();
partService.findPart(PART_ID).setLabel(item.getText());
}
}
Just figured out what the problem is. If i run the code from a handler, it works perfectly. I guess the framework can detect the change after running the handler. The only problem is that i need to change the label not only from a handler. There is a SelectionListener bound to the CTabFolder i use in the part, and the label change is triggered from there.
Is there any way to manually tell the framework to scan for model changes and apply them?
Christoph Keimel Messages: 279 Registered: December 2010 Location: Germany
Senior Member
The framework will listen to model changes and apply them. Like Sopot said, you should inject the MPart directly into your contribution class.
Try this example:
public class MyPart {
@Inject private MPart part;
@PostConstruct
public void postConstruct(Composite parent) {
final Text text = new Text(parent, SWT.MULTI);
text.setText("New Part Label");
final Button btn = new Button(parent, SWT.PUSH);
btn.setText("Change Part Label");
btn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
part.setLabel(text.getText());
}
});
}
}