svn commit: r17625 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui

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

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

Log:
Do not rebuild the entire JList when items are added or removed

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java?view=diff&pathrev=17625&r1=17624&r2=17625
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/RowSelector.java	2009-12-10 10:26:52-0800
@@ -29,8 +29,6 @@
 import java.awt.Dimension;
 import java.awt.KeyboardFocusManager;
 import java.awt.event.ActionEvent;
-import java.awt.event.ContainerEvent;
-import java.awt.event.ContainerListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.util.ArrayList;
@@ -46,6 +44,7 @@
 import javax.swing.JToolBar;
 import javax.swing.JTree;
 import javax.swing.ListModel;
+import javax.swing.SwingUtilities;
 import javax.swing.event.ListDataEvent;
 import javax.swing.event.ListDataListener;
 import javax.swing.event.ListSelectionEvent;
@@ -462,11 +461,22 @@
     @Override
     public void intervalAdded(ListDataEvent e) {
         if (e.getIndex0() == e.getIndex1()
-                && getModel().getElementAt(e.getIndex0()) == movedModelElement) {
-            getList().setSelectedValue(movedModelElement, true);
-            movedModelElement = null;
+                && getModel().getElementAt(e.getIndex0()) == movedModelElement.getElement()) {
+            LOG.info("Setting attribute to selected");
+            final Object element = movedModelElement.getElement();
+            movedModelElement.setElement(null);
+            getList().setSelectedValue(element, true);
+            // Pushing this to the end of the AWT thread seems to be the only
+            // way to get this to update correctly
+            Runnable doWorkRunnable = new Runnable() {
+                public void run() {
+                    getList().setSelectedValue(element, true);
+                }
+            };
+            SwingUtilities.invokeLater(doWorkRunnable);
         }
     }
+    
     @Override
     public void intervalRemoved(ListDataEvent e) {
     }

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=17625&r1=17624&r2=17625
==============================================================================
--- 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 10:26:52-0800
@@ -35,10 +35,8 @@
 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;
@@ -50,8 +48,6 @@
 import org.argouml.uml.ui.AbstractActionAddModelElement2;
 import org.argouml.uml.ui.AbstractActionNewModelElement;
 import org.argouml.uml.ui.AbstractActionRemoveElement;
-import org.tigris.gef.base.Diagram;
-import org.tigris.gef.presentation.Fig;
 import org.tigris.toolbar.ToolBar;
 
 /**
@@ -310,16 +306,20 @@
         Runnable doWorkRunnable = new Runnable() {
             public void run() {
                 try {
-                    if (e instanceof AttributeChangeEvent) {
-                        try {
-                            if (isValidEvent(e)) {
-                                LOG.info("Rebuilding model");
-                                rebuildModelList();
-                            }
-                        } catch (InvalidElementException iee) {
-                            return;
-                        }
-                    } else
+// The original controls on property panels regularly rebuild themselves
+// from scratch rather than add and remove elements
+// For now we just try and add/remove but we can reinstate this if required.
+//                    
+//                    if (e instanceof AttributeChangeEvent) {
+//                        try {
+//                            if (isValidEvent(e)) {
+//                                LOG.info("Rebuilding model");
+//                                rebuildModelList();
+//                            }
+//                        } catch (InvalidElementException iee) {
+//                            return;
+//                        }
+//                    } else
                     if (e instanceof AddAssociationEvent) {
                         if (isValidEvent(e)) {
                             Object o = getChangedElement(e);
@@ -334,22 +334,25 @@
                             } else {
                                 /* TODO: If this is an ordered list, then you have to 
                                     add in the right location! */
-                                if (!lm.contains(o)) {
+                                if (!contains(o)) {
                                     if (lm instanceof Ordered) {
                                         Ordered ordered = (Ordered) lm;
                                         Collection elements = ordered.getModelElements();
                                         if (elements instanceof List) {
-                                            LOG.info("Element inserted " + instance + " " + o);
                                             final int posn = ((List) elements).indexOf(o);
+                                            // We tested this above - do we need to test again?
                                             add(posn, o);
                                         } else {
-                                            LOG.info("Element addedx" + instance);
-                                            addElement(o);
+                                            int posn = 0;
+                                            for (Object element : elements) {
+                                                if (element == o) {
+                                                    break;
+                                                }
+                                                posn++;
+                                            }
+                                            add(posn, o);
                                         }
-                                        int posn = 1;
-                                        add(posn, o);
                                     } else {
-                                        LOG.info("Element addedy " + o);
                                         addElement(o);
                                     }
                                 }
@@ -372,7 +375,6 @@
                             }
                         }
                         if (valid) {
-                            LOG.info("Remove is valid" + instance);
                             Object o = getChangedElement(e);
                             if (o instanceof Collection) {
                                 Iterator it = ((Collection) o).iterator();
@@ -381,11 +383,8 @@
                                     removeElement(o3);
                                 }
                             } else {
-                                LOG.info("Removing" + instance + " " + o);
                                 removeElement(o);
                             }
-                        } else {
-                            LOG.info("Remove is not valid for " + instance + " " + getChangedElement(e));
                         }
                     }
                 } catch (InvalidElementException e) {
@@ -643,7 +642,7 @@
      * @see javax.swing.AbstractListModel#fireContentsChanged(
      *          Object, int, int)
      */
-    protected void fireContentsChanged(Object source, int index0, int index1) {
+    protected final void fireContentsChanged(Object source, int index0, int index1) {
         if (fireListEvents && !buildingModel)
             super.fireContentsChanged(source, index0, index1);
     }
@@ -652,7 +651,7 @@
      * @see javax.swing.AbstractListModel#fireIntervalAdded(
      *          Object, int, int)
      */
-    protected void fireIntervalAdded(Object source, int index0, int index1) {
+    protected final void fireIntervalAdded(Object source, int index0, int index1) {
         if (fireListEvents && !buildingModel)
             super.fireIntervalAdded(source, index0, index1);
     }
@@ -661,7 +660,7 @@
      * @see javax.swing.AbstractListModel#fireIntervalRemoved(
      *          Object, int, int)
      */
-    protected void fireIntervalRemoved(Object source, int index0, int index1) {
+    protected final void fireIntervalRemoved(Object source, int index0, int index1) {
         if (fireListEvents && !buildingModel)
             super.fireIntervalRemoved(source, index0, index1);
     }

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

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.