svn commit: r15566 - trunk/src/argouml-app/src/org/argouml/uml/ui: . foundation/core

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: tfmorris
Date: 2008-08-14 12:15:16-0700
New Revision: 15566

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java
   trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java

Log:
Issue 5299: Sort namespace combobox items.  Log debugging info at proper level.  Clarify workaround for Java bug.

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java?view=diff&rev=15566&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java&r1=15565&r2=15566
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/UMLComboBoxModel2.java	2008-08-14 12:15:16-0700
@@ -83,7 +83,7 @@
      * Flag to indicate if the user may select the empty string ("") as value in
      * the combobox. If true the attribute that is shown by this combobox may be
      * set to null. Makes sure that there is always a "" in the list with
-     * objects so the user has the oportunity to select this to clear the
+     * objects so the user has the opportunity to select this to clear the
      * attribute.
      */
     private boolean isClearable = false;
@@ -105,9 +105,10 @@
     protected boolean buildingModel = false;
     
     /**
-     * Flag needed to prevent a loop during popup notification
+     * Flag needed to prevent infinite recursion during processing of
+     * popup visibility notification event.
      */
-    private boolean willBecomeVisible = false;
+    private boolean processingWillBecomeVisible = false;
 
 
     /**
@@ -143,7 +144,8 @@
      * model, this method will make sure that the changes will be 
      * done in the combobox-model equally. <p>
      * TODO: This function is not yet completely written!
-     *
+     * 
+     * {@inheritDoc}
      * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
      */
     public void propertyChange(PropertyChangeEvent evt) {
@@ -217,7 +219,7 @@
      * selected item if there is one. Called from targetChanged every time the
      * target of the proppanel is changed.
      */
-    abstract protected void buildModelList();
+    protected abstract void buildModelList();
 
     /**
      * @param obj an UML object
@@ -320,7 +322,8 @@
         }
         fireListEvents = true;
         if (objects.size() != oldSize) {
-            fireIntervalAdded(this, oldSize - 1, objects.size() - 1);
+            fireIntervalAdded(this, oldSize == 0 ? 0 : oldSize - 1, 
+                    objects.size() - 1);
         }
     }
 
@@ -384,7 +387,7 @@
                 
                 buildingModel = true;
                 try {
-                    LOG.info("Building the combo box model for " + this);
+                    LOG.debug("Building the combo box model for " + this);
                     buildMinimalModelList();
                     // Do not set buildingModel = false here, 
                     // otherwise the action for selection is performed.
@@ -405,7 +408,7 @@
                 diagram.addPropertyChangeListener(
                         ArgoDiagram.NAMESPACE_KEY, this);
                 buildingModel = true;
-                LOG.info("Building the combo box model for " + this);
+                LOG.debug("Building the combo box model for " + this);
                 buildModelList();
                 setSelectedItem(getSelectedModelElement());
                 buildingModel = false;
@@ -653,7 +656,7 @@
      * @see TargetListener#targetRemoved(TargetEvent)
      */
     public void targetRemoved(TargetEvent e) {
-        LOG.info("targetRemoved targetevent :  " + e);
+        LOG.debug("targetRemoved targetevent :  " + e);
         Object currentTarget = comboBoxTarget;
         Object oldTarget =
 	    e.getOldTargets().length > 0
@@ -709,7 +712,7 @@
         this.fireListEvents = events;
     }
     
-    boolean isLazy() {
+    protected boolean isLazy() {
         return false;
     }
     
@@ -720,16 +723,18 @@
     }
 
     public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
-        if (isLazy() && !willBecomeVisible) {
-            JComboBox list = (JComboBox) ev.getSource();
-
+        if (isLazy() && !processingWillBecomeVisible) {
             buildModelList();
-
-            willBecomeVisible = true; // the flag is needed to prevent a loop
+            // We should be able to just do the above, but Swing has already
+            // computed the size of the popup menu.  The rest of this is
+            // a workaround for Swing bug 
+            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743225
+            JComboBox list = (JComboBox) ev.getSource();
+            processingWillBecomeVisible = true;
             try {
                 list.getUI().setPopupVisible( list, true );
             } finally {
-                willBecomeVisible = false;
+                processingWillBecomeVisible = false;
             }
         }
     }

Modified: trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java?view=diff&rev=15566&p1=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java&p2=trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java&r1=15565&r2=15566
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/ui/foundation/core/UMLModelElementNamespaceComboBoxModel.java	2008-08-14 12:15:16-0700
@@ -27,11 +27,15 @@
 import java.beans.PropertyChangeEvent;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
+import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.uml.ui.UMLComboBoxModel2;
+import org.argouml.uml.util.PathComparator;
 
 /**
  * A model for a namespace combo box.
@@ -72,6 +76,7 @@
     /*
      * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
      */
+    @Override
     protected void buildMinimalModelList() {
         Object target = getTarget();
         Collection c = new ArrayList(1);
@@ -89,11 +94,13 @@
      * @see org.argouml.uml.ui.UMLComboBoxModel2#buildModelList()
      */
     protected void buildModelList() {
+        Set<Object> elements = new TreeSet<Object>(new PathComparator());
+        
         Object model =
             ProjectManager.getManager().getCurrentProject().getRoot();
         Object target = getTarget();
-        Collection c = 
-            Model.getCoreHelper().getAllPossibleNamespaces(target, model);
+        elements.addAll(
+            Model.getCoreHelper().getAllPossibleNamespaces(target, model));
 
         /* These next lines for the case that the current namespace
          * is not a valid one... Which of course should not happen,
@@ -104,12 +111,17 @@
          */
         if (target != null) {
             Object namespace = Model.getFacade().getNamespace(target);
-            if (namespace != null && !c.contains(namespace)) {
-                c.add(namespace);
+            if (namespace != null && !elements.contains(namespace)) {
+                elements.add(namespace);
                 LOG.warn("The current namespace is not a valid one!");
             }
         }
-        setElements(c);
+
+        // Our comparator will throw an InvalidElementException if the old
+        // list contains deleted elements (eg after a new project is loaded)
+        // so remove all the old contents first
+        removeAllElements();
+        addAll(elements);
     }
 
     /*
@@ -125,6 +137,7 @@
     /*
     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
     */
+    @Override
     public void propertyChange(PropertyChangeEvent evt) {
         /*
          * Rebuild the list from scratch to be sure it's correct.
@@ -142,7 +155,8 @@
         }
     }
     
-    boolean isLazy() {
+    @Override
+    protected boolean isLazy() {
         return true;
     }
 }
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.