Search in sources :

Example 1 with NotificationImpl

use of org.eclipse.emf.common.notify.impl.NotificationImpl in project n4js by eclipse.

the class N4JSResource method notifyProxyResolved.

/**
 * Creates a custom notification and sends it for proxy and loaded object. Registers adapters to loaded object.
 *
 * @param idx
 *            index in the contents list (first or second slot)
 * @param oldProxy
 *            the proxified object before being loaded
 */
protected void notifyProxyResolved(int idx, EObject oldProxy) {
    if (eNotificationRequired() && idx < contents.size()) {
        EObject newObject = contents.basicGet(idx);
        Notification notification = new NotificationImpl(Notification.RESOLVE, oldProxy, newObject) {

            @Override
            public Object getNotifier() {
                return N4JSResource.this;
            }

            @Override
            public int getFeatureID(Class<?> expectedClass) {
                return RESOURCE__CONTENTS;
            }
        };
        eNotify(notification);
        for (Adapter adapter : eAdapters()) {
            if (adapter instanceof EContentAdapter && !newObject.eAdapters().contains(adapter)) {
                newObject.eAdapters().add(adapter);
            }
        }
    }
}
Also used : NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EContentAdapter(org.eclipse.emf.ecore.util.EContentAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) Notification(org.eclipse.emf.common.notify.Notification) EContentAdapter(org.eclipse.emf.ecore.util.EContentAdapter)

Example 2 with NotificationImpl

use of org.eclipse.emf.common.notify.impl.NotificationImpl in project statecharts by Yakindu.

the class DerivedEObjectEList method addUnique.

@Override
public void addUnique(int index, E object) {
    if (isNotificationRequired()) {
        boolean oldIsSet = isSet();
        super.add(index, validate(index, object));
        NotificationImpl notification = createNotification(Notification.ADD, null, object, index, oldIsSet);
        dispatchNotification(notification);
    } else {
        super.add(index, validate(index, object));
    }
}
Also used : NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with NotificationImpl

use of org.eclipse.emf.common.notify.impl.NotificationImpl in project statecharts by Yakindu.

the class DerivedEObjectEList method addAllUnique.

@Override
public boolean addAllUnique(int index, Collection<? extends E> objects) {
    int size = objects.size();
    if (size > 0) {
        if (isNotificationRequired()) {
            boolean oldIsSet = isSet();
            if (doAddAllUnique(index, objects)) {
                NotificationImpl notification = size == 1 ? createNotification(Notification.ADD, null, objects.iterator().next(), index, oldIsSet) : createNotification(Notification.ADD_MANY, null, objects, index, oldIsSet);
                dispatchNotification(notification);
                return true;
            }
        } else {
            return doAddAllUnique(index, objects);
        }
    }
    return false;
}
Also used : NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 4 with NotificationImpl

use of org.eclipse.emf.common.notify.impl.NotificationImpl in project webtools.sourceediting by eclipse.

the class XSDRedefineAdapter method notifyChanged.

public void notifyChanged(final Notification msg) {
    class CategoryNotification extends NotificationImpl {

        protected Object category;

        public CategoryNotification(Object category) {
            super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
            this.category = category;
        }

        public Object getNotifier() {
            return category;
        }

        public Object getFeature() {
            return msg.getFeature();
        }
    }
    if (children == null) {
        getChildren();
    }
    Object newValue = msg.getNewValue();
    Object oldValue = msg.getOldValue();
    if (XSDPackage.eINSTANCE.getXSDRedefine_Contents() == msg.getFeature()) {
        if ((newValue instanceof XSDAttributeGroupDefinition) || oldValue instanceof XSDAttributeGroupDefinition) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.ATTRIBUTES);
            Assert.isTrue(adapter != null);
            List list = getCategoryChildren(CategoryAdapter.ATTRIBUTES);
            adapter.setChildren(list);
            adapter.setAllChildren(list);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if ((newValue instanceof XSDComplexTypeDefinition || newValue instanceof XSDSimpleTypeDefinition) || (oldValue instanceof XSDComplexTypeDefinition || oldValue instanceof XSDSimpleTypeDefinition)) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.TYPES);
            Assert.isTrue(adapter != null);
            List types = getCategoryChildren(CategoryAdapter.TYPES);
            adapter.setChildren(types);
            adapter.setAllChildren(types);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if (newValue instanceof XSDModelGroupDefinition || oldValue instanceof XSDModelGroupDefinition) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.GROUPS);
            Assert.isTrue(adapter != null);
            List list = getCategoryChildren(CategoryAdapter.GROUPS);
            adapter.setChildren(list);
            adapter.setAllChildren(list);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_Annotations()) {
            return;
        }
    }
    super.notifyChanged(msg);
}
Also used : NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) ArrayList(java.util.ArrayList) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 5 with NotificationImpl

use of org.eclipse.emf.common.notify.impl.NotificationImpl in project webtools.sourceediting by eclipse.

the class XSDSchemaAdapter method notifyChanged.

public void notifyChanged(final Notification msg) {
    class CategoryNotification extends NotificationImpl {

        protected Object category;

        public CategoryNotification(Object category) {
            super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
            this.category = category;
        }

        public Object getNotifier() {
            return category;
        }

        public Object getFeature() {
            return msg.getFeature();
        }
    }
    if (children == null) {
        getChildren();
    }
    Object newValue = msg.getNewValue();
    Object oldValue = msg.getOldValue();
    // Bug 245480 - Deletion of Include, Import and Redefine is not reflected in the Outline view
    // We only want to refresh the Directives folder for any changes to XSDDirectives.  The first case covers
    // changes to one directive, whereas the missing case as reported in bug 245480 covers changes to a list
    // of directives.
    boolean updateDirectivesCategory = false;
    if (oldValue instanceof XSDSchemaDirective) {
        updateDirectivesCategory = true;
    } else if (oldValue instanceof Collection) {
        Iterator iterator = ((Collection) oldValue).iterator();
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            if (obj instanceof XSDSchemaDirective) {
                // if we find at least one directive, then we should refresh the folder
                updateDirectivesCategory = true;
                break;
            }
        }
    }
    if (newValue instanceof XSDInclude || newValue instanceof XSDImport || newValue instanceof XSDRedefine || // handle the case for delete directive
    (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_Contents() && updateDirectivesCategory) || // updates to the imports/includes
    msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_IncorporatedVersions()) {
        CategoryAdapter adapter = getCategory(CategoryAdapter.DIRECTIVES);
        Assert.isTrue(adapter != null);
        XSDSchema xsdSchema = adapter.getXSDSchema();
        adapter.setChildren(getDirectives(xsdSchema));
        adapter.setAllChildren(getDirectives(xsdSchema));
        notifyListeners(new CategoryNotification(adapter), adapter.getText());
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_ElementDeclarations()) {
        CategoryAdapter adapter = getCategory(CategoryAdapter.ELEMENTS);
        Assert.isTrue(adapter != null);
        XSDSchema xsdSchema = adapter.getXSDSchema();
        adapter.setChildren(getGlobalElements(xsdSchema));
        adapter.setAllChildren(getGlobalElements(xsdSchema, true));
        notifyListeners(new CategoryNotification(adapter), adapter.getText());
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_AttributeDeclarations() || msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_AttributeGroupDefinitions()) {
        CategoryAdapter adapter = getCategory(CategoryAdapter.ATTRIBUTES);
        Assert.isTrue(adapter != null);
        XSDSchema xsdSchema = adapter.getXSDSchema();
        adapter.setChildren(getAttributeList(xsdSchema));
        adapter.setAllChildren(getAttributeList(xsdSchema, true));
        notifyListeners(new CategoryNotification(adapter), adapter.getText());
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_TypeDefinitions()) {
        CategoryAdapter adapter = getCategory(CategoryAdapter.TYPES);
        Assert.isTrue(adapter != null);
        XSDSchema xsdSchema = adapter.getXSDSchema();
        List types = getComplexTypes(xsdSchema);
        types.addAll(getSimpleTypes(xsdSchema));
        adapter.setChildren(types);
        adapter.setAllChildren(getTypes(xsdSchema, true));
        notifyListeners(new CategoryNotification(adapter), adapter.getText());
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_ModelGroupDefinitions()) {
        CategoryAdapter adapter = getCategory(CategoryAdapter.GROUPS);
        Assert.isTrue(adapter != null);
        XSDSchema xsdSchema = adapter.getXSDSchema();
        adapter.setChildren(getGroups(xsdSchema));
        adapter.setAllChildren(getGroups(xsdSchema, true));
        notifyListeners(new CategoryNotification(adapter), adapter.getText());
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_Annotations()) {
        return;
    } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_SchemaLocation()) {
        notifyListeners(msg, null);
        return;
    }
    types = null;
    getTypes();
    super.notifyChanged(msg);
}
Also used : XSDRedefine(org.eclipse.xsd.XSDRedefine) NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) XSDImport(org.eclipse.xsd.XSDImport) XSDInclude(org.eclipse.xsd.XSDInclude) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

NotificationImpl (org.eclipse.emf.common.notify.impl.NotificationImpl)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 Notification (org.eclipse.emf.common.notify.Notification)1 EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 EContentAdapter (org.eclipse.emf.ecore.util.EContentAdapter)1 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)1 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDImport (org.eclipse.xsd.XSDImport)1 XSDInclude (org.eclipse.xsd.XSDInclude)1 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)1 XSDRedefine (org.eclipse.xsd.XSDRedefine)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 XSDSchemaDirective (org.eclipse.xsd.XSDSchemaDirective)1