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 05:25:23 UTC

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

Author: taylor
Date: Thu Oct 29 04:25:23 2009
New Revision: 830841

URL: http://svn.apache.org/viewvc?rev=830841&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-1057
Implement 'One Click Theme Selection' from Toolbox and Spaces Manager
Added support to decorators for localized decorator names (layouts) and icon properties for UI tooling

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java   (with props)
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java
    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/webapp/WEB-INF/view/spaces/spaces-manager.jsp
    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/spaces/SpacesManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java?rev=830841&r1=830840&r2=830841&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpacesManager.java Thu Oct 29 04:25:23 2009
@@ -31,11 +31,13 @@
 
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.administration.PortalAdministration;
+import org.apache.jetspeed.decoration.DecorationFactory;
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.om.portlet.GenericMetadata;
 import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.portlets.toolbox.ThemeBean;
 import org.apache.jetspeed.spaces.Spaces;
 import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.apache.portals.messaging.PortletMessaging;
@@ -52,6 +54,7 @@
     private PortalAdministration admin;    
     
     private Spaces spacesService;
+    protected DecorationFactory decorationFactory;    
     
     public void init(PortletConfig config) throws PortletException
     {
@@ -74,6 +77,11 @@
         if (null == pageManager)
         {
             throw new PortletException("Failed to find the Page Manager on portlet initialization");
+        }
+        decorationFactory = (DecorationFactory)context.getAttribute(CommonPortletServices.CPS_DECORATION_FACTORY);
+        if (null == decorationFactory)
+        {
+            throw new PortletException("Failed to find the Decoration Factory on portlet initialization");
         }                
     }
 
@@ -88,6 +96,7 @@
             request.getPortletSession().setAttribute("tab", tab, PortletSession.PORTLET_SCOPE);
         }
         request.setAttribute("tab", tab);
+        request.setAttribute("themes", ThemeBean.retrieveThemes(request, decorationFactory));
         super.doView(request, response);        
     }
     

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=830841&r1=830840&r2=830841&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 04:25:23 2009
@@ -27,6 +27,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Random;
+import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import javax.portlet.ActionRequest;
@@ -43,6 +45,9 @@
 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.decoration.LayoutDecoration;
+import org.apache.jetspeed.decoration.Theme;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.om.portlet.InitParam;
@@ -77,6 +82,7 @@
     protected PageManager pageManager;
     protected Profiler profiler;
     protected SecurityAccessController securityAccessController;
+    protected DecorationFactory decorationFactory;    
     protected Random rand;
     
     public final String[] DEFAULT_IMAGES = new String[]
@@ -118,6 +124,11 @@
         {
             throw new PortletException("Failed to find the Profiler on portlet initialization");
         }        
+        decorationFactory = (DecorationFactory)context.getAttribute(CommonPortletServices.CPS_DECORATION_FACTORY);
+        if (null == decorationFactory)
+        {
+            throw new PortletException("Failed to find the Decoration Factory on portlet initialization");
+        }        
         rand = new Random( 19580427 );
     }
 
@@ -129,11 +140,20 @@
         String filter = request.getParameter("filter");
         if (filter == null ||  filter.equals("")) filter = null;       
         if (category == null || category.equals("")) category = "All";
-
+        RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);            
         List<PortletInfo> portlets = retrievePortlets(request, null);
         request.setAttribute("portlets", portlets);
         request.setAttribute("categories", retrieveCategories(request));
-        
+        request.setAttribute("themes", ThemeBean.retrieveThemes(request, decorationFactory));
+        boolean hasEditAccess = false;
+        try
+        {
+            requestContext.getPage().checkAccess(JetspeedActions.EDIT);
+            hasEditAccess = true;
+        }
+        catch(Exception e)
+        {}
+        request.setAttribute("editAccess", new Boolean(hasEditAccess));
         super.doView(request, response);        
     }
     
@@ -142,6 +162,7 @@
     {
         String category = null;
         String filter = actionRequest.getParameter("filter");
+        String theme =  actionRequest.getParameter("theme");
         if (filter != null)
         {
             if (filter.trim().equals(""))
@@ -160,7 +181,26 @@
                 actionRequest.getPortletSession().removeAttribute("categories");
             }
         }
-        
+        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);            
+            page.setDefaultDecorator(theme, Fragment.LAYOUT);
+            page.setDefaultDecorator(theme, Fragment.PORTLET);
+            try
+            {                
+                pageManager.updatePage(page);
+                actionRequest.getPortletSession().removeAttribute("themes");
+            }
+            catch (Exception e)
+            {
+                log.error("Page has not been updated.", e);
+                page.setDefaultDecorator(oldLayout, Fragment.LAYOUT);
+                page.setDefaultDecorator(oldPortlet, Fragment.PORTLET);                
+            }            
+        }
         String portletAdd = actionRequest.getParameter("portletAdd");
         if (portletAdd != null)
         {
@@ -494,6 +534,6 @@
             return portlets;
         }
         
-    }
-    
+    }   
+
 }
\ No newline at end of file

Added: 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=830841&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/toolbox/ThemeBean.java Thu Oct 29 04:25:23 2009
@@ -0,0 +1,117 @@
+package org.apache.jetspeed.portlets.toolbox;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.portlet.PortletRequest;
+
+import org.apache.jetspeed.decoration.DecorationFactory;
+import org.apache.jetspeed.decoration.LayoutDecoration;
+import org.apache.jetspeed.decoration.Theme;
+import org.apache.jetspeed.request.RequestContext;
+
+public class ThemeBean implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private String name;
+
+    private String title;
+
+    private String image;
+
+    private boolean selected;
+
+    public ThemeBean(String name, String title, String image)
+    {
+        this.setName(name);
+        this.setTitle(title);
+        this.setImage(image);
+    }
+
+    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 static List<ThemeBean> retrieveThemes(PortletRequest request, DecorationFactory decorationFactory)
+    {
+        List<ThemeBean> themes = (List<ThemeBean>)request.getPortletSession().getAttribute("themes");
+        if (themes != null)
+        {
+            return themes;
+        }
+        themes = new ArrayList<ThemeBean>();
+        RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);            
+        Set<String> decorators = (Set<String>)decorationFactory.getPageDecorations(rc);
+        for (String name : decorators)
+        {
+            LayoutDecoration decor = decorationFactory.getLayoutDecoration(name, rc);
+            String compatibility = decor.getProperty("compatibility");
+            if (compatibility != null && compatibility.compareTo("2.2.1") >= 0)
+            {
+                ResourceBundle rb = decor.getResourceBundle(rc.getLocale(), rc);
+                String title = null;
+                try
+                {
+                    title = rb.getString("title");
+                }
+                catch(Exception e)
+                {}
+                if (title == null)
+                    title = decor.getName();
+                String icon = decor.getProperty("icon");
+                if (icon == null)
+                {
+                    icon = "";
+                }
+                ThemeBean theme = new ThemeBean(decor.getName(), title, icon);
+                Theme pageTheme = (Theme)rc.getRequest().getAttribute("org.apache.jetspeed.theme");
+                if (pageTheme.getPageLayoutDecoration().getName().equals(decor.getName()))
+                    theme.setSelected(true);
+                themes.add(theme);
+            }
+        }
+        request.getPortletSession().setAttribute("themes", themes);
+        return themes;
+    }
+     
+}

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

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

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp?rev=830841&r1=830840&r2=830841&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/spaces-manager.jsp Thu Oct 29 04:25:23 2009
@@ -64,25 +64,15 @@
 	<td class="portlet-section-subheader"></td>
 	</tr>
 	<tr>
+
 	<td colspan='2'>	
 		<table>
+		    <c:forEach var="theme" items="${themes}">	
 			<tr>
-                <td><img src='<c:url context="${portalContextPath}" value="/images/themes/style-icon-jetspeed-1.png"/>'></td>
-	 			<td style="vertical-align: middle"><input type="radio" checked name="theme" value="jetspeed" /> Jetspeed Professional</td>
-			</tr>
-			<tr>
-                <td><img src='<c:url context="${portalContextPath}" value="/images/themes/style-icon-jetspeed-2.png"/>'/></td>
-	 			<td style="vertical-align: middle"><input type="radio" name="theme" value="turbo" /> Jetspeed Turbo</td>
-			</tr>
-			<tr>
-                <td><img src='<c:url context="${portalContextPath}" value="/images/themes/style-icon-greenearth.png"/>'/></td>
-	 			<td style="vertical-align: middle"><input type="radio" name="theme" value="greenearth" /> Green Earth</td>
-			</tr>
-			<tr>
-                <td><img src='<c:url context="${portalContextPath}" value="/images/themes/style-icon-planet.png"/>'/></td>
-	 			<td style="vertical-align: middle"><input type="radio" name="theme" value="purpleplanet" />  Purple Planet</td>
+		         <td><img src='<c:url context="${portalContextPath}" value="/decorations/layout/${theme.name}/${theme.image}"/>'></td>
+				 <td style="vertical-align: middle"><input type="radio" <c:if test="${theme.selected}"> checked </c:if> name="theme" value="${theme.name}" /> ${theme.title}</td>
 			</tr>
-
+			</c:forEach>
 		</table>
    </td>
 	</tr>

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=830841&r1=830840&r2=830841&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 04:25:23 2009
@@ -44,6 +44,7 @@
         <portlet:namespace/>tabs['portletsTab'] = document.getElementById('<portlet:namespace/>portletsTab');
         <portlet:namespace/>tabs['layoutsTab'] = document.getElementById('<portlet:namespace/>layoutsTab');
         <portlet:namespace/>tabs['themesTab'] = document.getElementById('<portlet:namespace/>themesTab');
+        <portlet:namespace/>tabs['widgetsTab'] = document.getElementById('<portlet:namespace/>widgetsTab');
     }
     for (var key in <portlet:namespace/>tabs) {
         if (key == tabId) {
@@ -70,6 +71,8 @@
         <a href="javascript:<portlet:namespace/>showTab('layoutsTab');">Layout</a>
         |
         <a href="javascript:<portlet:namespace/>showTab('themesTab');">Theme</a>
+        |
+        <a href="javascript:<portlet:namespace/>showTab('widgetsTab');">Widgets</a>
     </td>
     </tr>
 </table>
@@ -113,7 +116,7 @@
 	                                <tr>
 	                                   <td class="portlet-section-body">
 	                                       <a href="<portlet:actionURL><portlet:param name='portletPreview' value='${portletInfo.name}'/></portlet:actionURL>">Preview</a>
-	                                       <c:if test="${not empty renderRequest.userPrincipal}">
+											<c:if test="${editAccess}">
     	                                       <a href="<portlet:actionURL><portlet:param name='portletAdd' value='${portletInfo.name}'/></portlet:actionURL>">Add</a>
     	                                   </c:if>
 	                                   </td>
@@ -188,9 +191,29 @@
 
 <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="1">Themes</th>
+        <th class="portlet-section-header" colspan="2">Themes</th>
+    </tr>
+    <c:forEach var="theme" items="${themes}">	
+	<tr>		
+		<c:choose><c:when test="${editAccess}">
+         <td><a href='<portlet:actionURL><portlet:param name='theme' value="${theme.name}"/></portlet:actionURL>'><img <c:if test="${!theme.selected}"> style='border-style: none' </c:if> src='<c:url context="${portalContextPath}" value="/decorations/layout/${theme.name}/${theme.image}"/>'></a></td>
+		</c:when>
+		<c:otherwise>
+         <td><img <c:if test="${theme.selected}"> style='border-style: solid' </c:if> src='<c:url context="${portalContextPath}" value="/decorations/layout/${theme.name}/${theme.image}"/>'></td>
+		</c:otherwise>
+		</c:choose>
+		 <td style="vertical-align: middle">${theme.title}</td>
+	</tr>
+	</c:forEach>
+    <tr>
+        <th class="portlet-section-header" colspan="2"></th>
+    </tr>
+</table>
+
+<table id="<portlet:namespace/>widgetsTab" style="display: none; border-collapse: collapse;  width: 100%; margin-top: 0px; margin-bottom: 0px; float: left;">
+    <tr>
+        <th class="portlet-section-header" colspan="1">Widgets</th>
     </tr>
-    <tr><td><img width="43" height="505" src='<c:url context="${portalContextPath}" value="/images/page-themes.png"/>'/></td></tr>
     <tr>
         <th class="portlet-section-header" colspan="1"></th>
     </tr>



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