You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2009/10/29 06:43:25 UTC

svn commit: r830847 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/toolbox/ webapp/WEB-INF/view/toolbox/

Author: taylor
Date: Thu Oct 29 05:43:24 2009
New Revision: 830847

URL: http://svn.apache.org/viewvc?rev=830847&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-1057
Implement 'One Click Layout Selection' from Toolbox - will need to revisit this in next iteration, decide on better infrastructure for themes, nested themes

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java   (with props)
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/ThemeBean.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=830847&r1=830846&r2=830847&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 Thu Oct 29 05:43:24 2009
@@ -144,6 +144,7 @@
         List<PortletInfo> portlets = retrievePortlets(request, null);
         request.setAttribute("portlets", portlets);
         request.setAttribute("categories", retrieveCategories(request));
+        request.setAttribute("layouts", LayoutBean.retrieveLayouts(request, decorationFactory));
         request.setAttribute("themes", ThemeBean.retrieveThemes(request, decorationFactory));
         boolean hasEditAccess = false;
         try
@@ -163,6 +164,8 @@
         String category = null;
         String filter = actionRequest.getParameter("filter");
         String theme =  actionRequest.getParameter("theme");
+        String layout =  actionRequest.getParameter("layout");
+        RequestContext requestContext = (RequestContext) actionRequest.getAttribute(RequestContext.REQUEST_PORTALENV);                    
         if (filter != null)
         {
             if (filter.trim().equals(""))
@@ -183,7 +186,6 @@
         }
         if (theme != null)
         {
-            RequestContext requestContext = (RequestContext) actionRequest.getAttribute(RequestContext.REQUEST_PORTALENV);            
             Page page = requestContext.getPage();
             String oldLayout = page.getDefaultDecorator(Fragment.LAYOUT);
             String oldPortlet = page.getDefaultDecorator(Fragment.PORTLET);            
@@ -201,10 +203,25 @@
                 page.setDefaultDecorator(oldPortlet, Fragment.PORTLET);                
             }            
         }
+        if (layout != null)
+        {
+            Page page = requestContext.getPage();
+            String oldLayout = page.getRootFragment().getName();
+            try
+            {                
+                page.getRootFragment().setName(layout);
+                pageManager.updatePage(page);
+                actionRequest.getPortletSession().removeAttribute("layouts");
+            }
+            catch (Exception e)
+            {
+                log.error("Page has not been updated.", e);
+                page.getRootFragment().setName(oldLayout);                
+            }            
+        }
         String portletAdd = actionRequest.getParameter("portletAdd");
         if (portletAdd != null)
         {
-            RequestContext requestContext = (RequestContext) actionRequest.getAttribute(RequestContext.REQUEST_PORTALENV);            
             Page page = requestContext.getPage();            
             Fragment fragment = pageManager.newFragment();
             fragment.setType( Fragment.PORTLET );

Added: 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=830847&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java Thu Oct 29 05:43:24 2009
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.toolbox;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.portlet.PortletRequest;
+
+import org.apache.jetspeed.decoration.DecorationFactory;
+import org.apache.jetspeed.request.RequestContext;
+
+public class LayoutBean implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+    private String name;
+    private String title;
+    private String image;
+    private boolean selected;
+    private String layoutPortlet; 
+    
+    public LayoutBean(String name, String title, String image, String layoutPortlet)
+    {
+        this.setName(name);
+        this.setTitle(title);
+        this.setImage(image);
+        this.setLayoutPortlet(layoutPortlet);
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public String getTitle()
+    {
+        return title;
+    }
+
+    public void setTitle(String title)
+    {
+        this.title = title;
+    }
+
+    public String getImage()
+    {
+        return image;
+    }
+
+    public void setImage(String image)
+    {
+        this.image = image;
+    }
+
+    public boolean isSelected()
+    {
+        return selected;
+    }
+
+    public void setSelected(boolean selected)
+    {
+        this.selected = selected;
+    }
+
+    public String getLayoutPortlet()
+    {
+        return layoutPortlet;
+    }
+    
+    public void setLayoutPortlet(String layoutPortlet)
+    {
+        this.layoutPortlet = layoutPortlet;
+    }
+    
+    public static List<LayoutBean> retrieveLayouts(PortletRequest request, DecorationFactory decorationFactory)
+    {
+        List<LayoutBean> layouts = (List<LayoutBean>)request.getPortletSession().getAttribute("layouts");
+        if (layouts != null)
+        {
+            return layouts;
+        }
+        layouts = new ArrayList<LayoutBean>();
+        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);
+        LayoutBean twoColumns = new LayoutBean("TwoColumn", "Two Columns", "TwoColumns.jpg", "jetspeed-layouts::VelocityTwoColumns");
+        addLayout(twoColumns, rc, layouts);
+        LayoutBean threeColumns = new LayoutBean("ThreeColumn", "Three Columns", "ThreeColumns.jpg", "jetspeed-layouts::VelocityThreeColumns");
+        addLayout(threeColumns, rc, layouts);
+        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)
+    {
+        System.out.println("bean = " + bean.getLayoutPortlet());
+        System.out.println("root = " + rc.getPage().getRootFragment().getName());
+        if (rc.getPage().getRootFragment().getName().equals(bean.getLayoutPortlet()))
+        {
+            bean.setSelected(true);
+        }
+         layouts.add(bean);        
+    }
+}
+
+ 
\ No newline at end of file

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/LayoutBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java?rev=830847&r1=830846&r2=830847&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java Thu Oct 29 05:43:24 2009
@@ -34,12 +34,9 @@
     private static final long serialVersionUID = 1L;
 
     private String name;
-
     private String title;
-
     private String image;
-
-    private boolean selected;
+    private boolean selected = false;
 
     public ThemeBean(String name, String title, String image)
     {

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=830847&r1=830846&r2=830847&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 Thu Oct 29 05:43:24 2009
@@ -181,14 +181,26 @@
 
 <table id="<portlet:namespace/>layoutsTab" style="display: none; border-collapse: collapse;  width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
     <tr>
-        <th class="portlet-section-header" colspan="1">Layout</th>
+        <th class="portlet-section-header" colspan="2">Layouts</th>
     </tr>
-    <tr><td><img width="62" height="539" src='<c:url context="${portalContextPath}" value="/images/page-layouts.png"/>'/></td></tr>
+    <c:forEach var="layout" items="${layouts}">	
+	<tr>		
+		<c:choose><c:when test="${editAccess}">
+         <td><a href='<portlet:actionURL><portlet:param name='layout' value="${layout.layoutPortlet}"/></portlet:actionURL>'><img <c:if test="${!layout.selected}"> style='border-style: none' </c:if> src='<c:url context="${portalContextPath}" value="/layouts/${layout.image}"/>'></a></td>
+		</c:when>
+		<c:otherwise>
+         <td><img <c:if test="${layout.selected}"> style='border-style: solid' </c:if> src='<c:url context="${portalContextPath}" value="/layouts/${layout.image}"/>'></td>
+		</c:otherwise>
+		</c:choose>
+		 <td style="vertical-align: middle">${layout.title}</td>
+	</tr>
+	</c:forEach>
     <tr>
-        <th class="portlet-section-header" colspan="1"></th>
+        <th class="portlet-section-header" colspan="2"></th>
     </tr>
 </table>
 
+
 <table id="<portlet:namespace/>themesTab" style="display: none; border-collapse: collapse;  width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
     <tr>
         <th class="portlet-section-header" colspan="2">Themes</th>



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