svn commit: r17621 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-12-10 03:33:07-0800
New Revision: 17621

Modified:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java

Log:
Only update ui in AWT thread

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java?view=diff&pathrev=17621&r1=17620&r2=17621
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLModelElementListModel.java	2009-12-10 03:33:07-0800
@@ -35,7 +35,10 @@
 import javax.swing.DefaultListModel;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
+import javax.swing.ListModel;
 import javax.swing.MenuElement;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ListDataListener;
 
 import org.apache.log4j.Logger;
 import org.argouml.model.AddAssociationEvent;
@@ -300,60 +303,74 @@
      * towards removing some of the overrriding methods used as workarounds for 
      * differences between NSUML and MDR - tfm - 20060302
      */
-    public void propertyChange(PropertyChangeEvent e) {
-        if (e instanceof AttributeChangeEvent) {
-            try {
-                if (isValidEvent(e)) {
-                    rebuildModelList();
-                }
-            } catch (InvalidElementException iee) {
-                return;
-            }
-        } else if (e instanceof AddAssociationEvent) {
-            if (isValidEvent(e)) {
-                Object o = getChangedElement(e);
-                if (o instanceof Collection) {
-                    ArrayList tempList = new ArrayList((Collection) o);
-                    Iterator it = tempList.iterator();
-                    while (it.hasNext()) {
-                        Object o2 = it.next();
-                        addElement(o2);
-                    }
-                } else {
-                    /* TODO: If this is an ordered list, then you have to 
-                        add in the right location! */
-                    addElement(o); 
-                }
-            }
-        } else if (e instanceof RemoveAssociationEvent) {
-            boolean valid = false;
-            if (!(getChangedElement(e) instanceof Collection)) {
-                valid = contains(getChangedElement(e));
-            } else {
-                Collection col = (Collection) getChangedElement(e);
-                Iterator it = col.iterator();
-                valid = true;
-                while (it.hasNext()) {
-                    Object o = it.next();
-                    if (!contains(o)) {
-                        valid = false;
-                        break;
+    public void propertyChange(final PropertyChangeEvent e) {
+        Runnable doWorkRunnable = new Runnable() {
+            public void run() {
+                try {
+                    if (e instanceof AttributeChangeEvent) {
+                        try {
+                            if (isValidEvent(e)) {
+                                rebuildModelList();
+                            }
+                        } catch (InvalidElementException iee) {
+                            return;
+                        }
+                    } else if (e instanceof AddAssociationEvent) {
+                        if (isValidEvent(e)) {
+                            Object o = getChangedElement(e);
+                            if (o instanceof Collection) {
+                                ArrayList tempList = new ArrayList((Collection) o);
+                                Iterator it = tempList.iterator();
+                                while (it.hasNext()) {
+                                    Object o2 = it.next();
+                                    addElement(o2);
+                                }
+                            } else {
+                                /* TODO: If this is an ordered list, then you have to 
+                                    add in the right location! */
+                                addElement(o); 
+                            }
+                        }
+                    } else if (e instanceof RemoveAssociationEvent) {
+                        boolean valid = false;
+                        if (!(getChangedElement(e) instanceof Collection)) {
+                            valid = contains(getChangedElement(e));
+                        } else {
+                            Collection col = (Collection) getChangedElement(e);
+                            Iterator it = col.iterator();
+                            valid = true;
+                            while (it.hasNext()) {
+                                Object o = it.next();
+                                if (!contains(o)) {
+                                    valid = false;
+                                    break;
+                                }
+                            }
+                        }
+                        if (valid) {
+                            Object o = getChangedElement(e);
+                            if (o instanceof Collection) {
+                                Iterator it = ((Collection) o).iterator();
+                                while (it.hasNext()) {
+                                    Object o3 = it.next();
+                                    removeElement(o3);
+                                }
+                            } else {
+                                removeElement(o);
+                            }
+                        }
                     }
-                }
-            }
-            if (valid) {
-                Object o = getChangedElement(e);
-                if (o instanceof Collection) {
-                    Iterator it = ((Collection) o).iterator();
-                    while (it.hasNext()) {
-                        Object o3 = it.next();
-                        removeElement(o3);
+                } catch (InvalidElementException e) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("updateLayout method accessed "
+                                + "deleted element ", e);
                     }
-                } else {
-                    removeElement(o);
                 }
-            }
-        }
+            }  
+        };
+        SwingUtilities.invokeLater(doWorkRunnable);
+        
+        
     }
 
     /**

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

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.