Author: woonsan
Date: Wed Dec  9 19:03:21 2009
New Revision: 888925

URL: http://svn.apache.org/viewvc?rev=888925&view=rev
Log:
JS2-1057: Fixing layout/theme selection.

Modified:
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/JetspeedToolbox.java
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
    
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp

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=888925&r1=888924&r2=888925&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
 Wed Dec  9 19:03:21 2009
@@ -34,16 +34,13 @@
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.JetspeedActions;
-import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.decoration.DecorationFactory;
+import org.apache.jetspeed.layout.PageLayoutComponent;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.portlet.HeaderPhaseSupportConstants;
-import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.search.SearchEngine;
-import org.apache.jetspeed.security.SecurityAccessController;
 import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,11 +56,8 @@
 {
     static Logger log = LoggerFactory.getLogger(JetspeedToolbox.class);
     
-    protected PortletRegistry registry;
-    protected SearchEngine searchEngine;
-    protected Profiler profiler;
-    protected SecurityAccessController securityAccessController;
-    protected DecorationFactory decorationFactory;    
+    protected PageLayoutComponent pageLayoutComponent;
+    protected DecorationFactory decorationFactory;
     protected String yuiScriptPath = "/javascript/yui/build/yui/yui-min.js";
     
     public void init(PortletConfig config) throws PortletException
@@ -72,28 +66,16 @@
         
         PortletContext context = getPortletContext();
         
-        registry = 
(PortletRegistry)context.getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
-        if (null == registry)
-        {
-            throw new PortletException("Failed to find the Portlet Registry on 
portlet initialization");
-        }        
-        searchEngine = 
(SearchEngine)context.getAttribute(CommonPortletServices.CPS_SEARCH_COMPONENT);
-        if (null == searchEngine)
-        {
-            throw new PortletException("Failed to find the Search Engine on 
portlet initialization");
-        }
-        securityAccessController = 
(SecurityAccessController)context.getAttribute(CommonPortletServices.CPS_SECURITY_ACCESS_CONTROLLER);
-        if (null == securityAccessController)
-        {
-            throw new PortletException("Failed to find the Security Access 
Controller on portlet initialization");
-        }
-        profiler = 
(Profiler)context.getAttribute(CommonPortletServices.CPS_PROFILER_COMPONENT);
-        if (null == profiler)
+        pageLayoutComponent = (PageLayoutComponent) 
context.getAttribute(CommonPortletServices.CPS_PAGE_LAYOUT_COMPONENT);
+        
+        if (pageLayoutComponent == null)
         {
-            throw new PortletException("Failed to find the Profiler on portlet 
initialization");
+            throw new PortletException("Failed to find the Page Layout 
Component on portlet initialization");
         }        
+        
         decorationFactory = 
(DecorationFactory)context.getAttribute(CommonPortletServices.CPS_DECORATION_FACTORY);
-        if (null == decorationFactory)
+        
+        if (decorationFactory == null)
         {
             throw new PortletException("Failed to find the Decoration Factory 
on portlet initialization");
         }        
@@ -131,7 +113,8 @@
         try
         {
             RequestContext requestContext = (RequestContext) 
request.getAttribute(RequestContext.REQUEST_PORTALENV);
-            requestContext.getPage().checkAccess(JetspeedActions.EDIT);
+            ContentPage contentPage = requestContext.getPage();
+            contentPage.checkAccess(JetspeedActions.EDIT);
             hasEditAccess = true;
         }
         catch(Exception ignore)
@@ -153,12 +136,11 @@
         
         if (theme != null)
         {
-            ContentPage page = requestContext.getPage();
-            
             try
             {
-                page.updateDefaultDecorator(theme, ContentFragment.LAYOUT);
-                page.updateDefaultDecorator(theme, ContentFragment.PORTLET);
+                ContentPage page = requestContext.getPage();
+                pageLayoutComponent.updateDefaultDecorator(page, theme, 
ContentFragment.LAYOUT);
+                pageLayoutComponent.updateDefaultDecorator(page, theme, 
ContentFragment.LAYOUT);
                 actionRequest.getPortletSession().removeAttribute("themes");
             }
             catch (Exception e)
@@ -169,12 +151,10 @@
         
         if (layout != null)
         {
-            ContentPage page = requestContext.getPage();
-            ContentFragment layoutFragment = page.getRootFragment();
-            
             try
             {
-                layoutFragment.updateName(layout);
+                ContentFragment layoutFragment = 
pageLayoutComponent.getUnlockedRootFragment(requestContext.getPage());
+                pageLayoutComponent.updateName(layoutFragment, layout);
                 actionRequest.getPortletSession().removeAttribute("layouts");
             }
             catch (Exception e)
@@ -182,23 +162,6 @@
                 log.error("Page has not been updated.", e);
             }            
         }
-        
-        String portletAdd = actionRequest.getParameter("portletAdd");
-        
-        if (portletAdd != null)
-        {
-            // BOZO: this should be done via AJAX API
-            ContentPage page = requestContext.getPage();
-            
-            try
-            {                
-                addPortletToLeastUsedColumn(page, portletAdd); 
-            }
-            catch (Exception e)
-            {
-                log.error("Unable to add portlet to page: " + e, e);
-            }
-        }
     }    
     
     @SuppressWarnings("unchecked")

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java?rev=888925&r1=888924&r2=888925&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
 Wed Dec  9 19:03:21 2009
@@ -23,6 +23,8 @@
 import javax.portlet.PortletRequest;
 
 import org.apache.jetspeed.decoration.DecorationFactory;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
 
 public class LayoutBean implements Serializable
@@ -103,24 +105,28 @@
         RequestContext rc = (RequestContext) 
request.getAttribute(RequestContext.REQUEST_PORTALENV);
         // BOZO: support 4 for now, need to localize, formalize etc
         LayoutBean single = new LayoutBean("OneColumn", "One Column", 
"OneColumn.jpg", "jetspeed-layouts::VelocityOneColumn");
-        addLayout(single, rc, layouts);
+        layouts.add(single);
         LayoutBean twoColumns = new LayoutBean("TwoColumn", "Two Columns", 
"TwoColumns.jpg", "jetspeed-layouts::VelocityTwoColumns");
-        addLayout(twoColumns, rc, layouts);
+        layouts.add(twoColumns);
         LayoutBean threeColumns = new LayoutBean("ThreeColumn", "Three 
Columns", "ThreeColumns.jpg", "jetspeed-layouts::VelocityThreeColumns");
-        addLayout(threeColumns, rc, layouts);
+        layouts.add(threeColumns);
         LayoutBean fourColumns = new LayoutBean("FourColumn", "Four Columns", 
"FourColumns.jpg", "jetspeed-layouts::VelocityFourColumns");
-        addLayout(fourColumns, rc, layouts);       
-        request.getPortletSession().setAttribute("layouts", layouts);
-        return layouts;
-    }
- 
-    private static void addLayout(LayoutBean bean, RequestContext rc, 
List<LayoutBean> layouts)
-    {
-        if 
(rc.getPage().getRootFragment().getName().equals(bean.getLayoutPortlet()))
+        layouts.add(fourColumns);
+        
+        ContentPage page = rc.getPage();
+        ContentFragment layoutFragment = 
page.getPageLayoutComponent().getUnlockedRootFragment(page);
+        String currentLayoutName = layoutFragment.getName();
+        
+        for (LayoutBean layout : layouts)
         {
-            bean.setSelected(true);
+            if (layout.getLayoutPortlet().equals(currentLayoutName))
+            {
+                layout.setSelected(true);
+            }
         }
-         layouts.add(bean);        
+        
+        request.getPortletSession().setAttribute("layouts", layouts);
+        return layouts;
     }
 }
 

Modified: 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp?rev=888925&r1=888924&r2=888925&view=diff
==============================================================================
--- 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
 (original)
+++ 
portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/toolbox/toolbox.jsp
 Wed Dec  9 19:03:21 2009
@@ -290,8 +290,8 @@
     };
 
     var onAddPortletComplete = function(id, o, args) {
-        if (o.status == 200 && o.readyState == 4) {
-            location.reload();
+        if (o.status == 200) {
+            location.href = location.href;
         }
     };
     



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

Reply via email to