Search code examples
eclipseemfecore

Get notified on EAnnotation references list change


I'm creating a custom Ecore editor based on the Sample Ecore editor (org.eclipse.emf.ecore* plugins) and found out that changes in lists do not manifest in model change notifications. For example, changes to the EAnnotation.references list will not result in model change notifications, whereas the EAnnotation.setSource() method creates a notification. I guess, this is one of the reasons why the default getText() method in the EAnnotationItemProvider uses only the source field.

I'm using the value of the references field to generate the UI presentation of the EAnnotation, so seeing the changes to this field would be necessary for correct operation.

Is there some standard way to observe these changes and fire a refresh() on the model views?


Solution

  • I figured out that the notification was created but the notifyChanged() method initially ignored it. This is what worked for me:

    @Override
    public void notifyChanged(Notification notification) {
        updateChildren(notification);
    
        switch (notification.getFeatureID(EAnnotation.class)) {
            case EcorePackage.EANNOTATION__SOURCE:
            case EcorePackage.EANNOTATION__REFERENCES: /*ADDED*/
                fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
                return;
            case EcorePackage.EANNOTATION__CONTENTS:
                fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
                return;
            case EcorePackage.EANNOTATION__DETAILS: /*MODIFIED TO UPDATE VIEW*/
                fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, true));
                return;
        }
        super.notifyChanged(notification);
    }