portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r887431 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
Date Fri, 04 Dec 2009 23:04:52 GMT
Author: taylor
Date: Fri Dec  4 23:04:51 2009
New Revision: 887431

URL: http://svn.apache.org/viewvc?rev=887431&view=rev
Log:
JS2-1087: Adding portlets bug fix

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java?rev=887431&r1=887430&r2=887431&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
Fri Dec  4 23:04:51 2009
@@ -553,37 +553,58 @@
         
     }   
 
+    protected ContentFragment findFirstUnlockedFragment(ContentFragment fragment)
+    {
+        if (fragment.isLocked())
+        {
+            List<ContentFragment> fragments = (List<ContentFragment>)fragment.getFragments();
+            for (ContentFragment f : fragments)
+            {
+                if (f.getType().equals(Fragment.LAYOUT))
+                {
+                    fragment = findFirstUnlockedFragment(f);
+                    if (fragment != null)
+                        return fragment;
+                }
+            }       
+            return null;
+        }
+        return fragment;
+    }
+    
     // BOZO: this only works with flat collections of 1,2,3,4 column layouts. Not meant to
work with nested layouts
     // TODO: move code to an AJAX API
     protected void addPortletToLeastUsedColumn(ContentPage page, String portletName)
     {
-        ContentFragment layoutFragment = page.getRootFragment();
-        String layoutType = layoutFragment.getName();
-        List<ContentFragment> fragments = (List<ContentFragment>)layoutFragment.getFragments();
-        int columnCounts[] = new int[getLayoutSize(layoutType)];
-        for (ContentFragment fragment : fragments)
+        ContentFragment layoutFragment = findFirstUnlockedFragment(page.getRootFragment());
+        if (layoutFragment != null)
         {
-            int column = fragment.getLayoutColumn();
-            int row = fragment.getLayoutRow();
-            if (column == -1)
-                column = min(columnCounts);
-            if (row == -1)
-                row = columnCounts[column];            
-            if (column > fragments.size() -1)
+            String layoutType = layoutFragment.getName();
+            List<ContentFragment> fragments = (List<ContentFragment>)layoutFragment.getFragments();
+            int columnCounts[] = new int[getLayoutSize(layoutType)];
+            for (ContentFragment fragment : fragments)
             {
-                fragment.updateRowColumn(-1, 0);
-                column = 0;
+                int column = fragment.getLayoutColumn();
+                int row = fragment.getLayoutRow();
+                if (column == -1)
+                    column = min(columnCounts);
+                if (row == -1)
+                    row = columnCounts[column];            
+                if (column > fragments.size() -1)
+                {
+                    fragment.updateRowColumn(-1, 0);
+                    column = 0;
+                }
+                columnCounts[column]++;
             }
-            columnCounts[column]++;
-        }
-        int placedColumn = 0;
-        for (int ix = 1; ix < columnCounts.length; ix++)
-        {
-            if (columnCounts[ix] < columnCounts[placedColumn])
-                placedColumn = ix;
+            int placedColumn = 0;
+            for (int ix = 1; ix < columnCounts.length; ix++)
+            {
+                if (columnCounts[ix] < columnCounts[placedColumn])
+                    placedColumn = ix;
+            }
+            layoutFragment.addPortlet(ContentFragment.PORTLET, portletName, columnCounts[placedColumn],
placedColumn);
         }
-        System.out.println("adding portlet at row = " + columnCounts[placedColumn] + ", col
= " + placedColumn);
-        layoutFragment.addPortlet(ContentFragment.PORTLET, portletName, columnCounts[placedColumn],
placedColumn);
     }
     
     public static int min(int[] numbers)



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message