portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r831206 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
Date Fri, 30 Oct 2009 05:52:01 GMT
Author: taylor
Date: Fri Oct 30 05:52:00 2009
New Revision: 831206

URL: http://svn.apache.org/viewvc?rev=831206&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-1057
wrote a crude portlet placement algorithm, figures out best column to place a Added Portlet.
Candidate for jetspeed-page-layout component api

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=831206&r1=831205&r2=831206&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 Oct 30 05:52:00 2009
@@ -222,13 +222,15 @@
         String portletAdd = actionRequest.getParameter("portletAdd");
         if (portletAdd != null)
         {
+            // BOZO: this should be done via AJAX API
             Page page = requestContext.getPage();            
             Fragment fragment = pageManager.newFragment();
             fragment.setType( Fragment.PORTLET );
             fragment.setName(portletAdd);            
-            page.getRootFragment().getFragments().add(fragment);
             try
             {
+                // TODO: move this operation into Randy's new jetspeed-page-layout component
+                addPortletToLeastUsedColumn(page.getRootFragment().getFragments(), fragment,
page.getRootFragment().getName()); 
                 pageManager.updatePage(page);
             }
             catch (PageNotUpdatedException e)
@@ -553,4 +555,62 @@
         
     }   
 
+    // 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(List untypedList, Fragment portlet, String
layoutType)
+    {
+        List<Fragment> fragments = (List<Fragment>)untypedList;
+        int columnCounts[] = new int[getLayoutSize(layoutType)];
+        for (Fragment fragment : fragments)
+        {
+            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.setLayoutColumn(0);
+                column = 0;
+            }
+            columnCounts[column]++;
+        }
+        int placedColumn = 0;
+        for (int ix = 1; ix < columnCounts.length; ix++)
+        {
+            if (columnCounts[ix] < columnCounts[placedColumn])
+                placedColumn = ix;
+            
+        }
+        System.out.println("adding portlet at row = " + columnCounts[placedColumn] + ", col
= " + placedColumn);
+        portlet.setLayoutColumn(placedColumn);
+        portlet.setLayoutRow(columnCounts[placedColumn] );
+        fragments.add(portlet);
+    }
+    
+    public static int min(int[] numbers)
+    {
+        int minValue = numbers[0];
+        for (int i = 1; i < numbers.length; i++)
+        {
+            if (numbers[i] < minValue)
+            {
+                minValue = numbers[i];
+            }
+        }
+        return minValue;
+    }
+    
+    public static int getLayoutSize(String layoutType)
+    {
+        if (layoutType.indexOf("TwoColumns") > -1)
+            return 2;
+        if (layoutType.indexOf("ThreeColumns") > -1)
+            return 3;
+        if (layoutType.indexOf("FourColumns") > -1)
+            return 4;
+        else
+            return 1;
+    }
 }
\ No newline at end of file



---------------------------------------------------------------------
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