From the model to the SWT component
Well, it is time to see how a setText("Olivier rules"); will be reflected on the SWT Text component and by the way, looking forward the complete notification chain.
Let's start our example:
1. setText("Olivier rules"); on the TextImpl
2. As the Edit part is an adapter of the model, the notifyChange event will arrive on the TextEditPartImpl. The Edit part inheritance hierarchy defines the role hierarchy, that is why the change event will arrive in the AbstractTextEditPart:
public void notifyChanged(Notification notification) {
switch (notification.getFeatureID(org.wazaabi.model.core.widgets.AbstractTextComponent.class)) {
case org.wazaabi.model.core.widgets.WidgetsPackage.ABSTRACT_TEXT_COMPONENT__TEXT:
switch (notification.getEventType()) {
case Notification.SET:
refreshWidgetViewText();
break;
}
break;
default:
super.notifyChanged(notification);
}
}
3. The refreshWidgetViewText() method will set the text and asking for component re-validation
public void refreshWidgetViewText() {
String candidate = getModelText().getText();
String existing = ((AbstractTextComponentView) getWidgetView()).getText();
if (candidate == null && existing == null)
return;
if ((candidate == null && existing != null)|| (candidate != null && !candidate.equals(existing))) {
((AbstractTextComponentView) getWidgetView()).setText(candidate);
getWidgetView().invalidate();
getWidgetView().getParent().invalidate();
getWidgetView().getParent().validate();
getWidgetView().fireWidgetViewRepainted();
}
}
4. That's all !
In order to highlight the role hierarchy of the edit part the Figure below shows a clear view of the Edit part hierarchy.