incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r496917 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml: SelectManyShuttleRenderer.java SimpleSelectManyRenderer.java
Date Wed, 17 Jan 2007 02:11:30 GMT
Author: awiner
Date: Tue Jan 16 18:11:29 2007
New Revision: 496917

URL: http://svn.apache.org/viewvc?view=rev&rev=496917
Log:
ADFFACES-353 - selectOrderShuttle problems

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectManyShuttleRenderer.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectManyRenderer.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectManyShuttleRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectManyShuttleRenderer.java?view=diff&rev=496917&r1=496916&r2=496917
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectManyShuttleRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SelectManyShuttleRenderer.java
Tue Jan 16 18:11:29 2007
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -117,10 +118,6 @@
     return list.toArray(new String[list.size()]);
   }
 
-  protected boolean isReorderable()
-  {
-    return false;
-  }
 
   protected Integer getSize(FacesBean bean)
   {
@@ -237,14 +234,41 @@
     if (!valuePassThru)
       _convertSelectItemListToIndices(selectItems);
 
+    // Start the leading list off with everything, and the trailing list
+    // off with nothing
     List<SelectItem> leadingSelectItems = new ArrayList<SelectItem>(selectItems);
   
     List<SelectItem> trailingSelectItems =
        new ArrayList<SelectItem>(selectedIndices.length);
-    for (int i = selectedIndices.length - 1; i >=0; i--)
+
+    // Now, for every selected index, add an item over
+    for (int i = 0; i < selectedIndices.length; i++)
+    {
+      int selectedIndex = selectedIndices[i];
+      // -1 means a value couldn't be matched up to
+      // a SelectItem.  That's programmer error, but we've
+      // already logged a warning
+      if (selectedIndex < 0)
+        continue;
+
+      trailingSelectItems.add(selectItems.get(selectedIndex));
+    }
+
+    // Now, sort the list
+    Arrays.sort(selectedIndices);
+    // And, in reverse order, remove those indices (reverse order
+    // so we don't affect the indices of the items at the end)
+    for (int i = selectedIndices.length - 1; i >= 0; i--)
     {
-      trailingSelectItems.add(0,
-                              leadingSelectItems.remove(selectedIndices[i]));
+      int selectedIndex = selectedIndices[i];
+      // -1 means a value couldn't be matched up to
+      // a SelectItem.  That's programmer error, but we've
+      // already logged a warning
+      if (selectedIndex < 0)
+        break;
+
+      leadingSelectItems.remove(selectedIndex);
     }
+
     
     // Initialize global info
     ShuttleInfo info = _createAndSetShuttleInfo(rc,

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectManyRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectManyRenderer.java?view=diff&rev=496917&r1=496916&r2=496917
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectManyRenderer.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleSelectManyRenderer.java
Tue Jan 16 18:11:29 2007
@@ -468,8 +468,16 @@
 
 
   /**
+   * Returns true if the renderer cares about order.
+   */
+  protected boolean isReorderable()
+  {
+    return false;
+  }
+
+  /**
    * Return all the selected indices, in sorted order.  (There
-   * may be trailing -1's in case of an error)
+   * may be included -1's in case of an error)
    */
   @SuppressWarnings("unchecked")
   protected int[] getSelectedIndices(
@@ -494,8 +502,9 @@
         indices[i] = SimpleSelectOneRenderer.__getIndex(values[i], selectItems);
       }
 
-      // And sort it to make sure.
-      Arrays.sort(indices);
+      // And sort it, but only if it's not reorderable
+      if (!isReorderable())
+        Arrays.sort(indices);
       return indices;
     }
 
@@ -555,10 +564,18 @@
     }
 
     // Now figure out what's selected or not
-    int[] indices = new int[valueList.size()];
+    int valueListSize = valueList.size();
+    int[] indices = new int[valueListSize];
+    // Pre-mark each item as -1 to indicate it as
+    // not-found
+    for (int i = 0; i < valueListSize; i++)
+    {
+      indices[i] = -1;
+    }
+
     int itemCount = selectItems.size();
+    int foundCount = 0;
 
-    int lastEntry = 0;
     for (int i = 0; i < itemCount; i++)
     {
       SelectItem item = selectItems.get(i);
@@ -571,11 +588,13 @@
       {
         // Remove it from the valueList so that if the same
         // value appears multiple times, that'll (more-or-less)
-        // work
-        valueList.remove(index);
+        // work - but remove it by replacing it with an object
+        // that won't be .equals() anything else, so the
+        // indices all match up
+        valueList.set(index, _ALREADY_FOUND);
         // Remember that this item is selected
-        indices[lastEntry] = i;
-        lastEntry++;
+        indices[index] = i;
+        foundCount++;
       }
     }
 
@@ -585,13 +604,8 @@
     // appear anywhere among our selectItems, so clear
     // out the remainder of the indices (which otherwise would
     // be zero) and log a warning
-    if (!valueList.isEmpty())
+    if (foundCount < valueListSize)
     {
-      for (; lastEntry < indices.length; lastEntry++)
-      {
-        indices[lastEntry] = -1;
-      }
-
       if (_LOG.isWarning())
       {
         _LOG.warning(
@@ -600,6 +614,10 @@
       }
     }
 
+    Integer[] indicesObj = new Integer[indices.length];
+    for (int foo = 0; foo < indices.length; foo++)
+      indicesObj[foo] = indices[foo];
+
     return indices;
   }
 
@@ -629,7 +647,7 @@
 
   static private final int[] _EMPTY_INT_ARRAY = new int[0];
   static private final String[] _EMPTY_ARRAY = new String[0];
-
+  static private final Object _ALREADY_FOUND = new Object();
   static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
     EditableValueRenderer.class);
 }



Mime
View raw message