svn commit: r16525 - trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-01-05 10:51:30-0800
New Revision: 16525

Modified:
   trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java

Log:
Make sure that model events are handled on the awt thread.

Modified: trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java?view=diff&pathrev=16525&r1=16524&r2=16525
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/ui/explorer/ExplorerEventAdaptor.java	2009-01-05 10:51:30-0800
@@ -24,8 +24,12 @@
 
 package org.argouml.ui.explorer;
 
+import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
+import javax.swing.SwingUtilities;
+
+import org.apache.log4j.Logger;
 import org.argouml.application.events.ArgoEventPump;
 import org.argouml.application.events.ArgoEventTypes;
 import org.argouml.application.events.ArgoProfileEvent;
@@ -35,8 +39,10 @@
 import org.argouml.model.AddAssociationEvent;
 import org.argouml.model.AttributeChangeEvent;
 import org.argouml.model.DeleteInstanceEvent;
+import org.argouml.model.InvalidElementException;
 import org.argouml.model.Model;
 import org.argouml.model.RemoveAssociationEvent;
+import org.argouml.model.UmlChangeEvent;
 import org.argouml.notation.Notation;
 
 /**
@@ -56,6 +62,10 @@
  */
 public final class ExplorerEventAdaptor
     implements PropertyChangeListener {
+    
+    private static final Logger LOG =
+        Logger.getLogger(ExplorerEventAdaptor.class);
+
     /**
      * The singleton instance.
      *
@@ -161,33 +171,27 @@
      *
      * @see PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
      */
-    public void propertyChange(java.beans.PropertyChangeEvent pce) {
+    public void propertyChange(final PropertyChangeEvent pce) {
         if (treeModel == null) {
             return;
         }
 
         // uml model events
-        if (pce instanceof AttributeChangeEvent) {
-            // TODO: Can this be made more restrictive?
-            // Do we care about any attributes other than name? - tfm
-            treeModel.modelElementChanged(pce.getSource());
-        } else if (pce instanceof RemoveAssociationEvent) {
-            // TODO: This should really be coded the other way round,
-            // to only act on associations which are important for
-            // representing the current perspective (and to only act
-            // on a single end of the association) - tfm
-            if (!("namespace".equals(pce.getPropertyName()))) {
-                treeModel.modelElementChanged(((RemoveAssociationEvent) pce)
-                        .getChangedValue());
-            }
-        } else if (pce instanceof AddAssociationEvent) {
-            if (!("namespace".equals(pce.getPropertyName()))) {
-                treeModel.modelElementAdded(
-                        ((AddAssociationEvent) pce).getSource());
-            }
-        } else if (pce instanceof DeleteInstanceEvent) {
-            treeModel.modelElementRemoved(((DeleteInstanceEvent) pce)
-                    .getSource());
+        if (pce instanceof UmlChangeEvent) {
+            Runnable doWorkRunnable = new Runnable() {
+                public void run() {
+                    try {
+                        modelChanged((UmlChangeEvent) pce);
+                    } catch (InvalidElementException e) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("updateLayout method accessed "
+                                    + "deleted element", e);
+                        }
+                    }
+                }  
+            };
+            SwingUtilities.invokeLater(doWorkRunnable);
+            
         } else if (pce.getPropertyName().equals(
                 // TODO: No one should be sending the deprecated event
                 // from outside ArgoUML, but keep responding to it for now
@@ -205,12 +209,41 @@
             // notation events
             treeModel.structureChanged();
         } else if (pce.getSource() instanceof ProjectManager) {
+            // TODO: Bob says - I think we don't need this any more
+            // we no longer get "remove" from ProjectManager but instead
+            // a DeleteInstanceEvent (trapped above)
             if ("remove".equals(pce.getPropertyName())) {
                 treeModel.modelElementRemoved(pce.getOldValue());
             }
         }
     }
     
+    private void modelChanged(UmlChangeEvent event) {
+        if (event instanceof AttributeChangeEvent) {
+            // TODO: Can this be made more restrictive?
+            // Do we care about any attributes other than name? - tfm
+            treeModel.modelElementChanged(event.getSource());
+        } else if (event instanceof RemoveAssociationEvent) {
+            // TODO: This should really be coded the other way round,
+            // to only act on associations which are important for
+            // representing the current perspective (and to only act
+            // on a single end of the association) - tfm
+            if (!("namespace".equals(event.getPropertyName()))) {
+                treeModel.modelElementChanged(((RemoveAssociationEvent) event)
+                        .getChangedValue());
+            }
+        } else if (event instanceof AddAssociationEvent) {
+            if (!("namespace".equals(event.getPropertyName()))) {
+                treeModel.modelElementAdded(
+                        ((AddAssociationEvent) event).getSource());
+            }
+        } else if (event instanceof DeleteInstanceEvent) {
+            treeModel.modelElementRemoved(((DeleteInstanceEvent) event)
+                    .getSource());
+        }
+    }
+    
+    
     /**
      * Listener for additions and removals of profiles.
      * Since they generally have a major impact on the explorer tree,

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

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.