From: <jbo...@li...> - 2006-04-21 16:05:10
|
Author: adamw Date: 2006-04-21 12:04:43 -0400 (Fri, 21 Apr 2006) New Revision: 3888 Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java Modified: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml Log: http://jira.jboss.com/jira/browse/JBLAB-656 Administration fix Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/layout/portal-strategies.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<portal-strategies> + <set name="jbfStrategy"> + <strategy content-type="text/html"> + <implementation>org.jboss.portal.theme.impl.strategy.JBFStrategyImpl</implementation> + </strategy> + </set> +</portal-strategies> Modified: labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/jbossForgeLayout.war/WEB-INF/portal-layouts.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -2,5 +2,13 @@ <layout> <name>JBossForge</name> <uri>/layouts/jbossForge.jsp</uri> + <uri state="maximized">/layouts/jbossForge.jsp</uri> + <regions> + <region name="left"/> + <region name="center"/> + <region name="right"/> + <region name="innerleft"/> + <region name="innerright"/> + </regions> </layout> </layouts> \ No newline at end of file Added: labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/forge-theme/src/java/org/jboss/portal/core/theme/render/impl/JBFStrategyImpl.java 2006-04-21 16:04:43 UTC (rev 3888) @@ -0,0 +1,173 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portal.theme.impl.strategy; + +import org.apache.log4j.Logger; +import org.jboss.portal.WindowState; +import org.jboss.portal.common.MediaType; +import org.jboss.portal.theme.ThemeException; +import org.jboss.portal.theme.page.PortletContext; +import org.jboss.portal.theme.strategy.AbstractLayoutStrategy; +import org.jboss.portal.theme.strategy.StrategyContext; +import org.jboss.portal.theme.strategy.StrategyException; +import org.jboss.portal.theme.strategy.StrategyResponse; + +import java.util.ArrayList; +import java.util.Iterator; + +/* + * + * @author <a href="mailto:mho...@no...">Martin Holzner</a> + * @version $Revision: 1.2.4.1 $ +*/ +public class JBFStrategyImpl extends AbstractLayoutStrategy +{ + private static Logger log = Logger.getLogger(JBFStrategyImpl.class); + + public JBFStrategyImpl() + { + setMediaType(MediaType.HTML); + } + + /** + * Evaluate the strategy and return a strategy response, containing the desired changes. + * + * @param context a context containing the portal's current information about portlets, states and the layout + * @return a strategy response with the desired changes + * @throws org.jboss.portal.theme.strategy.StrategyException + * if the strategy is missconfigured, or can't deal with the provided information + */ + public StrategyResponse evaluate(StrategyContext context) throws StrategyException + { + if (context == null) + { + throw new NullPointerException("strategy context is null"); + } + + if (context.getLayout() == null) + { + throw new IllegalArgumentException("Strategy can only be evaluated with a valid layout provided."); + } + + log.debug("evaluating strategy for: " + context.getLayout().getName()); + + StrategyResponse response = context.createResponse(); + + ArrayList maximizedPortlets = new ArrayList(); + + // get the list of portlets and their window state, and check if one of the + // portlets is maximized + for (Iterator i = context.getPortletContexts().iterator(); i.hasNext();) + { + PortletContext portlet = (PortletContext)i.next(); + log.debug("evaluating portlet: " + portlet.getWindowID()); + try + { + if (WindowState.MAXIMIZED.equals(portlet.getWindowState())) + { + log.debug("found maximized portlet: " + portlet); + maximizedPortlets.add(portlet); + } + else + { + // exclude all, but the maximized portlet, from the render process +// response.addNoRender(portlet); + // exclude all but the maximized portlet, and those in the left/right regions + if ((!"left".equalsIgnoreCase(portlet.getRegionName())) && +(!"right".equalsIgnoreCase(portlet.getRegionName())) && +(!"innerleft".equalsIgnoreCase(portlet.getRegionName())) && +(!"innerright".equalsIgnoreCase(portlet.getRegionName()))) + { + response.addNoRender(portlet); + } + } + } + catch (ThemeException e) + { + // window state not known + log.warn(e); + response.addNoRender(portlet); + } + } + // if there is at least one portlet with maximized window state, then + // switch the layout to the maximized layout, and + // flag all portlets that are not part of the header region (except the maximized one) as 'do-not-render' + // Note: it's better to flag them as do not render than to set their window states to minimized, since that + // could be interpreted differently on the layout / theme + // if one of the portlets is in maximized mode, then use the maximized layout + if (maximizedPortlets.size() > 0) + { + PortletContext targetPortlet = context.getTargetPortlet(); + // there can only be one maximized portlet! when in doubt, the targeted portlet wins + if (targetPortlet != null && maximizedPortlets.size() > 1) + { + try + { + if (maximizedPortlets.contains(targetPortlet) && + WindowState.MAXIMIZED.equals(targetPortlet.getWindowState())) + { + for (Iterator i = maximizedPortlets.iterator(); i.hasNext();) + { + PortletContext portlet = (PortletContext)i.next(); + if (!portlet.equals(targetPortlet)) + { + log.debug("resetting maximized portlet to normal (there can only be one): " + portlet + " " + + targetPortlet + " will be maximized"); + // change the window state back to normal, and make sure the + // portlet is not rendered + response.addWindowStateChange(portlet, WindowState.NORMAL); + response.addNoRender(portlet); + } + else + { + // move the maximized portlet to the maximized region + portlet.setRegionName(WindowState.MAXIMIZED.toString()); + } + } + } + } + catch (ThemeException e) + { + // the target portlet's state isn't known (portlet was deregistered?) , so exclude it + response.addNoRender(targetPortlet); + } + } + else + { + // move the maximized portlet to the maximized region + //PortletContext portlet = (PortletContext)maximizedPortlets.get(0); + //portlet.setRegionName(WindowState.MAXIMIZED.toString()); + } + + // set the layout state so that the interceptor can check if there is another uri specified in the layout for this state + response.setLayoutState(WindowState.MAXIMIZED.toString()); + maximizedPortlets.clear(); + } + else + { + // if there is no maximized portlet, then clean up (forget about the norender list) + response.reset(); + } + + return response; + } +} Modified: labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml 2006-04-21 15:01:45 UTC (rev 3887) +++ labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml 2006-04-21 16:04:43 UTC (rev 3888) @@ -24,7 +24,7 @@ <!-- Set the default strategy name (used by the strategy interceptor), see also portal-strategies.xml --> <property> <name>layout.strategyId</name> - <value>maximizedRegion</value> + <value>jbfStrategy</value> </property> <!-- The default page name, if the property is not explicited then the default page name is "default" --> <property> |