svn commit: r17345 - trunk/src/argouml-core-model-euml/src/org/argouml/model/euml

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-09-22 10:35:27-0700
New Revision: 17345

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:
Workaround for issue 5853. Don't send a delete event when the user changes navigability

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=17345&r1=17344&r2=17345
==============================================================================
--- 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	2009-09-22 10:35:27-0700
@@ -34,6 +34,7 @@
 import java.util.List;
 
 import org.argouml.model.CoreHelper;
+import org.argouml.model.Model;
 import org.argouml.model.NotImplementedException;
 import org.eclipse.emf.common.command.Command;
 import org.eclipse.emf.ecore.EClass;
@@ -1495,6 +1496,14 @@
                 // WARNING - This has containment side effects!
                 // Eclipse UML2 will move the Property from the Classifier to
                 // the Association when the navigability is changed.
+                if (!flag) {
+                    // Because of this side effect we add the element to
+                    // a special list of elements that we do not create
+                    // a delete event for. See issue 5853.
+                    ModelEventPumpEUMLImpl pump =
+                        (ModelEventPumpEUMLImpl) Model.getPump();
+                    pump.addElementForDeleteEventIgnore(prop);
+                }
                 prop.setIsNavigable(flag);
             }
         };
@@ -1504,7 +1513,7 @@
                         "Set isNavigable to # for the association end #", flag,
                         handle));
     }
-
+    
     public void setOperations(Object classifier, List operations) {
         throw new NotYetImplementedException();
     }

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=17345&r1=17344&r2=17345
==============================================================================
--- 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	2009-09-22 10:35:27-0700
@@ -43,6 +43,7 @@
 import org.argouml.model.AddAssociationEvent;
 import org.argouml.model.AttributeChangeEvent;
 import org.argouml.model.DeleteInstanceEvent;
+import org.argouml.model.Model;
 import org.argouml.model.RemoveAssociationEvent;
 import org.eclipse.emf.common.command.CommandStackListener;
 import org.eclipse.emf.common.notify.Notification;
@@ -51,6 +52,7 @@
 import org.eclipse.emf.ecore.ENamedElement;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
+import org.eclipse.uml2.uml.Property;
 
 /**
  * The implementation of the ModelEventPump for eUML.
@@ -58,6 +60,13 @@
 class ModelEventPumpEUMLImpl extends AbstractModelEventPump {
 
     /**
+     * A list of model elements that when removed should not create delete
+     * events. See issue 
+     */
+    final private List<Property> deleteEventIgnoreList =
+        new ArrayList<Property>();
+    
+    /**
      * A listener attached to a UML element
      */
     private class Listener {
@@ -292,10 +301,10 @@
         }
 
         ENamedElement feature = (ENamedElement) notification.getFeature();
-        String featureName = feature == null ? "" : feature.getName(); //$NON-NLS-1$
-        String oldValue = notification.getOldValue() != null ? notification.getOldValue().toString() : "Null";
-        String newValue = notification.getNewValue() != null ? notification.getNewValue().toString() : "Null";
-//        LOG.debug(notification.toString());
+        String featureName =
+            feature == null ? "" : feature.getName(); //$NON-NLS-1$
+        Object oldValue = notification.getOldValue();
+        Object newValue = notification.getNewValue();
         LOG.debug("event  - Property: " //$NON-NLS-1$
                 + featureName 
                 + " Old: " + oldValue //$NON-NLS-1$
@@ -347,11 +356,19 @@
                             notification.getNewValue(), null), getListeners(
                                     notification.getNotifier(), propName)));
                 } else {
-                    events.add(new EventAndListeners(
-                            new DeleteInstanceEvent(
-                                    notification.getOldValue(),
-                                    "remove", null, null, null),  //$NON-NLS-1$
-                                    getListeners(notification.getOldValue())));
+                    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,
@@ -419,6 +436,32 @@
             }
         }
     }
+    
+    /**
+     * Determine of we should create a delete event for the given property
+     * when EMF tells us it has been removed. This is currently used to
+     * work around the problem discussed in issue 5853.
+     * @param element
+     * @return
+     */
+    private boolean isDeleteEventRequired(
+            final Object element) {
+        if (element instanceof Property) {
+            synchronized (deleteEventIgnoreList) {
+                if (deleteEventIgnoreList.contains(element)) {
+                    deleteEventIgnoreList.remove(element);
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+    
+    void addElementForDeleteEventIgnore(Property property) {
+        synchronized (deleteEventIgnoreList) {
+            deleteEventIgnoreList.add(property);
+        }
+    }
 
     private List<PropertyChangeListener> getListeners(Object element) {
         return getListeners(element, null);

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

To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.