Author: bobtarling
Date: 2011-02-13 04:11:30-0800
New Revision: 19025

Modified:
   
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
   
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java

Log:
For the event pump to generate an event when a stereotype is added/removed

Modified: 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java?view=diff&pathrev=19025&r1=19024&r2=19025
==============================================================================
--- 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
        (original)
+++ 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
        2011-02-13 04:11:30-0800
@@ -28,6 +28,7 @@
 import org.argouml.model.Model;
 import org.argouml.model.NotImplementedException;
 import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.edit.command.AddCommand;
 import org.eclipse.emf.edit.command.CommandParameter;
@@ -125,9 +126,32 @@
         RunnableClass run = new RunnableClass() {
             public void run() {
                 for (Object o : stereos) {
-                    ((Element) modelElement).applyStereotype((Stereotype) o);
+                    Stereotype stereotype = (Stereotype) o;
+                    ((Element) modelElement).applyStereotype(stereotype);
+                    fireApplyStereotypeEvent(modelElement, stereotype);
                 }
             }
+            /**
+             * Call the model event pump and ask it to fire an event 
indicating a
+             * stereotype has been added. This is a stop-gap until we have
+             * determined how the event pump can detect itself that a 
stereotype
+             * has been added.
+             *  
+             * @param modelElement
+             * @param stereotype
+             */
+            private void fireApplyStereotypeEvent(Object modelElement, Object 
stereotype) {
+                final ModelEventPumpEUMLImpl pump =
+                    (ModelEventPumpEUMLImpl) Model.getPump();
+                pump.fireEvent(
+                        modelElement, 
+                        null, 
+                        stereotype, 
+                        Notification.ADD, 
+                        "stereotype",  //$NON-NLS-1$ 
+                        null);
+            }
+            
         };
         ChangeCommand cmd;
         if (stereos.size() == 1) {
@@ -1193,21 +1217,44 @@
     }
 
 
-    public void removeStereotype(final Object handle, final Object stereo) {
-        UMLUtil.checkArgs(new Object[] {handle, stereo},
+    public void removeStereotype(final Object modelElement, final Object 
stereo) {
+        UMLUtil.checkArgs(new Object[] {modelElement, stereo},
                 new Class[] {Element.class, Stereotype.class});
         RunnableClass run = new RunnableClass() {
             public void run() {
-                ((Element) handle).unapplyStereotype((Stereotype) stereo);
-        }
+                Stereotype stereotype = (Stereotype) stereo;
+                ((Element) modelElement).unapplyStereotype(stereotype);
+                fireUnapplyStereotypeEvent(modelElement, stereotype);
+            }
+            /**
+             * Call the model event pump and ask it to fire an event 
indicating a
+             * stereotype has been removed. This is a stop-gap until we have
+             * determined how the event pump can detect itself that a 
stereotype
+             * has been removed.
+             *  
+             * @param modelElement
+             * @param stereotype
+             */
+            private void fireUnapplyStereotypeEvent(Object modelElement, 
Object stereotype) {
+                final ModelEventPumpEUMLImpl pump =
+                    (ModelEventPumpEUMLImpl) Model.getPump();
+                pump.fireEvent(
+                        modelElement, 
+                        stereotype, 
+                        null, 
+                        Notification.REMOVE, 
+                        "stereotype", //$NON-NLS-1$
+                        null);
+            }
+
         };
         editingDomain.getCommandStack().execute(
                 new ChangeCommand(
                         modelImpl, run,
                         "Remove the stereotype # from the element #",
-                        stereo, handle));
+                        stereo, modelElement));
     }
-
+    
     public void removeSupplierDependency(final Object supplier,
             final Object dependency) {
         if (!(supplier instanceof NamedElement)) {

Modified: 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java?view=diff&pathrev=19025&r1=19024&r2=19025
==============================================================================
--- 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
    (original)
+++ 
trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
    2011-02-13 04:11:30-0800
@@ -282,20 +282,50 @@
      *                The notification event
      */
     public void notifyChanged(Notification notification) {
+        
         if (notification.getEventType() == Notification.REMOVING_ADAPTER) {
             return;
         }
-
-        ENamedElement feature = (ENamedElement) notification.getFeature();
-        String featureName =
+        
+        final ENamedElement feature = (ENamedElement) 
notification.getFeature();
+        
+        final String featureName =
             feature == null ? "" : feature.getName(); //$NON-NLS-1$
-        Object oldValue = notification.getOldValue();
-        Object newValue = notification.getNewValue();
+
+        final EReference oppositeRef;
+        if (feature instanceof EReference) {
+            oppositeRef = ((EReference) feature).getEOpposite();
+        } else {
+            oppositeRef = null;
+        }
+
+        fireEvent(
+                notification.getNotifier(), 
+                notification.getOldValue(), 
+                notification.getNewValue(), 
+                notification.getEventType(), 
+                featureName,
+                oppositeRef);
+    }
+
+    /**
+     * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(Notification)
+     * @param notification
+     *                The notification event
+     */
+    void fireEvent(
+            Object notifier, 
+            Object oldValue, 
+            Object newValue, 
+            int eventType, 
+            String featureName,
+            EReference oppositeRef) {
+
         LOG.debug("event  - Property: " //$NON-NLS-1$
                 + featureName 
                 + " Old: " + oldValue //$NON-NLS-1$
                 + " New: " + newValue //$NON-NLS-1$
-                + " From: " + notification.getNotifier()); //$NON-NLS-1$
+                + " From: " + notifier); //$NON-NLS-1$
         
         class EventAndListeners {
             public EventAndListeners(PropertyChangeEvent e,
@@ -311,101 +341,94 @@
 
         List<EventAndListeners> events = new ArrayList<EventAndListeners>();
 
-        if (notification.getEventType() == Notification.SET) {
-            if (notification.getFeature() instanceof ENamedElement) {
-                String propName =
-                        mapPropertyName(((ENamedElement) notification
-                                .getFeature()).getName());
+        if (eventType == Notification.SET) {
+            String propName =
+                    mapPropertyName(featureName);
+            events.add(new EventAndListeners(new AttributeChangeEvent(
+                    notifier, propName,
+                    oldValue, newValue,
+                    null), getListeners(
+                            notifier, propName)));
+        } else if (eventType == Notification.ADD
+                || eventType == Notification.REMOVE) {
+            String propName = mapPropertyName(featureName);
+            if (eventType == Notification.ADD) {
+                events.add(new EventAndListeners(new AddAssociationEvent(
+                        notifier, propName, null,
+                        newValue,
+                        newValue, null), getListeners(
+                                notifier, propName)));
                 events.add(new EventAndListeners(new AttributeChangeEvent(
-                        notification.getNotifier(), propName,
-                        notification.getOldValue(), notification.getNewValue(),
-                        null), getListeners(
-                                notification.getNotifier(), propName)));
+                        notifier, propName, null,
+                        newValue, null), getListeners(
+                                notifier, propName)));
+            } else {
+                if (isDeleteEventRequired(oldValue)) {
+                    // Changing of a property can result in the property
+                    // being removed and added again (eclipse behaviour)
+                    // we don't want to mistake this for deletion of the
+                    // property. See issue 5853
+                    events.add(new EventAndListeners(
+                            new DeleteInstanceEvent(
+                                    oldValue,
+                                    "remove",  //$NON-NLS-1$
+                                    null, null, null),
+                                    getListeners(
+                                        oldValue)));
+                }
+                events.add(new EventAndListeners(
+                        new RemoveAssociationEvent(
+                                notifier, propName,
+                                oldValue, null,
+                                oldValue, null),
+                        getListeners(
+                                notifier, propName)));
+                events.add(new EventAndListeners(
+                        new AttributeChangeEvent(
+                                notifier, propName,
+                                oldValue, null, null),
+                        getListeners(
+                                notifier, propName)));
             }
-        } else if (notification.getEventType() == Notification.ADD
-                || notification.getEventType() == Notification.REMOVE) {
-            if (notification.getFeature() instanceof EReference) {
-                EReference ref = (EReference) notification.getFeature();
-                String propName = mapPropertyName(ref.getName());
-                if (notification.getEventType() == Notification.ADD) {
-                    events.add(new EventAndListeners(new AddAssociationEvent(
-                            notification.getNotifier(), propName, null,
-                            notification.getNewValue(),
-                            notification.getNewValue(), null), getListeners(
-                                    notification.getNotifier(), propName)));
-                    events.add(new EventAndListeners(new AttributeChangeEvent(
-                            notification.getNotifier(), propName, null,
-                            notification.getNewValue(), null), getListeners(
-                                    notification.getNotifier(), propName)));
+
+            if (oppositeRef != null) {
+                propName = mapPropertyName(oppositeRef.getName());
+                if (eventType == Notification.ADD) {
+                    events.add(new EventAndListeners(
+                            new AddAssociationEvent(
+                                    newValue,
+                                    propName, null,
+                                    notifier,
+                                    notifier, null),
+                            getListeners(
+                                    newValue,
+                                    propName)));
+                    events.add(new EventAndListeners(
+                            new AttributeChangeEvent(
+                                    newValue,
+                                    propName, null,
+                                    notifier, null),
+                            getListeners(
+                                    newValue,
+                                    propName)));
                 } else {
-                    if (isDeleteEventRequired(oldValue)) {
-                        // Changing of a property can result in the property
-                        // being removed and added again (eclipse behaviour)
-                        // we don't want to mistake this for deletion of the
-                        // property. See issue 5853
-                        events.add(new EventAndListeners(
-                                new DeleteInstanceEvent(
-                                        notification.getOldValue(),
-                                        "remove",  //$NON-NLS-1$
-                                        null, null, null),
-                                        getListeners(
-                                            notification.getOldValue())));
-                    }
                     events.add(new EventAndListeners(
-                            new RemoveAssociationEvent(
-                                    notification.getNotifier(), propName,
-                                    notification.getOldValue(), null,
-                                    notification.getOldValue(), null),
+                            new AddAssociationEvent(
+                                    oldValue,
+                                    propName,
+                                    notifier, null,
+                                    notifier, null),
                             getListeners(
-                                    notification.getNotifier(), propName)));
+                                    oldValue,
+                                    propName)));
                     events.add(new EventAndListeners(
                             new AttributeChangeEvent(
-                                    notification.getNotifier(), propName,
-                                    notification.getOldValue(), null, null),
+                                    oldValue,
+                                    propName,
+                                    notifier, null, null),
                             getListeners(
-                                    notification.getNotifier(), propName)));
-                }
-
-                EReference oppositeRef = ref.getEOpposite();
-                if (oppositeRef != null) {
-                    propName = mapPropertyName(oppositeRef.getName());
-                    if (notification.getEventType() == Notification.ADD) {
-                        events.add(new EventAndListeners(
-                                new AddAssociationEvent(
-                                        notification.getNewValue(),
-                                        propName, null,
-                                        notification.getNotifier(),
-                                        notification.getNotifier(), null),
-                                getListeners(
-                                        notification.getNewValue(),
-                                        propName)));
-                        events.add(new EventAndListeners(
-                                new AttributeChangeEvent(
-                                        notification.getNewValue(),
-                                        propName, null,
-                                        notification.getNotifier(), null),
-                                getListeners(
-                                        notification.getNewValue(),
-                                        propName)));
-                    } else {
-                        events.add(new EventAndListeners(
-                                new AddAssociationEvent(
-                                        notification.getOldValue(),
-                                        propName,
-                                        notification.getNotifier(), null,
-                                        notification.getNotifier(), null),
-                                getListeners(
-                                        notification.getOldValue(),
-                                        propName)));
-                        events.add(new EventAndListeners(
-                                new AttributeChangeEvent(
-                                        notification.getOldValue(),
-                                        propName,
-                                        notification.getNotifier(), null, 
null),
-                                getListeners(
-                                        notification.getOldValue(),
-                                        propName)));
-                    }
+                                    oldValue,
+                                    propName)));
                 }
             }
         }
@@ -419,6 +442,8 @@
         }
     }
     
+    
+    
     /**
      * Determine if we should create a delete event for the given property
      * when EMF tells us it has been removed. This is currently used to

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2703650

To unsubscribe from this discussion, e-mail: 
[[email protected]].

Reply via email to