svn commit: r17707 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-12-23 09:16:07-0800
New Revision: 17707

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

Log:
Handle addition of a model element to the list by listening to the model

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java?view=diff&pathrev=17707&r1=17706&r2=17707
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SimpleListModel.java	2009-12-23 09:16:07-0800
@@ -16,14 +16,18 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.util.Collection;
+import java.util.List;
+
 import javax.swing.DefaultListModel;
 import javax.swing.SwingUtilities;
 
 import org.apache.log4j.Logger;
 import org.argouml.core.propertypanels.model.GetterSetterManager;
+import org.argouml.model.AddAssociationEvent;
 import org.argouml.model.InvalidElementException;
 import org.argouml.model.Model;
 import org.argouml.model.RemoveAssociationEvent;
+import org.argouml.util.CollectionUtil;
 
 /**
  * The simplest model for a list of UML elements
@@ -82,6 +86,21 @@
                     if (e instanceof RemoveAssociationEvent) {
                         removeElement(
                                 ((RemoveAssociationEvent) e).getChangedValue());
+                    } else if (e instanceof AddAssociationEvent) {
+                        Object newElement = ((AddAssociationEvent) e).getChangedValue();
+                        
+                        if (Model.getUmlHelper().isMovable(getMetaType())) {
+                            final Collection c =
+                                (Collection) getterSetterManager.getOptions( 
+                                    umlElement, 
+                                    propertyName, 
+                                    type);
+                            final int index =
+                                CollectionUtil.indexOf(c, newElement);
+                            add(index, newElement);
+                        } else {
+                            addElement(newElement);
+                        }
                     }
                 } catch (InvalidElementException e) {
                     LOG.debug("propertyChange accessed a deleted element ", e);

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

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.