Author: julien(a)jboss.com
Date: 2007-01-22 14:39:41 -0500 (Mon, 22 Jan 2007)
New Revision: 6067
Added:
trunk/api/src/main/org/jboss/portal/api/node/event/PageEvent.java
trunk/api/src/main/org/jboss/portal/api/node/event/PageRenderEvent.java
trunk/api/src/main/org/jboss/portal/spi/
trunk/api/src/main/org/jboss/portal/spi/NavigationalStateContext.java
trunk/core/src/main/org/jboss/portal/core/portlet/test/event/WindowConstraintEventListener.java
Removed:
trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java
Modified:
trunk/api/src/main/org/jboss/portal/api/node/PortalNode.java
trunk/api/src/main/org/jboss/portal/api/node/event/PortalNodeEventContext.java
trunk/api/src/main/org/jboss/portal/api/node/event/WindowEvent.java
trunk/api/src/main/org/jboss/portal/api/node/event/WindowRenderEvent.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalNodeInterceptor.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalObjectNode.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/core/src/resources/portal-samples-war/WEB-INF/default-object.xml
Log:
JBPORTAL-1213 : PageRenderEvent which signals when a portal page is rendered
Modified: trunk/api/src/main/org/jboss/portal/api/node/PortalNode.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/api/node/PortalNode.java 2007-01-22 16:24:53 UTC
(rev 6066)
+++ trunk/api/src/main/org/jboss/portal/api/node/PortalNode.java 2007-01-22 19:39:41 UTC
(rev 6067)
@@ -52,6 +52,13 @@
int getType();
/**
+ * The node id which identifies the node in the context of its root.
+ *
+ * @return the node id
+ */
+// String getId();
+
+ /**
* Return the root node of this node.
*
* @return the root node
@@ -66,7 +73,7 @@
PortalNode getParent();
/**
- * Return the node name relative to its parent.
+ * Return the node name which identifies the node in the context to its parent.
*
* @return the node name
*/
Added: trunk/api/src/main/org/jboss/portal/api/node/event/PageEvent.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/api/node/event/PageEvent.java
(rev 0)
+++ trunk/api/src/main/org/jboss/portal/api/node/event/PageEvent.java 2007-01-22 19:39:41
UTC (rev 6067)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.api.node.event;
+
+import org.jboss.portal.api.node.PortalNode;
+
+/**
+ * Base class for page events.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class PageEvent extends PortalNodeEvent
+{
+ protected PageEvent(PortalNode node)
+ {
+ super(node);
+ }
+}
Added: trunk/api/src/main/org/jboss/portal/api/node/event/PageRenderEvent.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/api/node/event/PageRenderEvent.java
(rev 0)
+++ trunk/api/src/main/org/jboss/portal/api/node/event/PageRenderEvent.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.api.node.event;
+
+import org.jboss.portal.api.node.PortalNode;
+
+/**
+ * This event is fired whenever a page is rendered.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PageRenderEvent extends PageEvent
+{
+ public PageRenderEvent(PortalNode node)
+ {
+ super(node);
+ }
+}
Modified: trunk/api/src/main/org/jboss/portal/api/node/event/PortalNodeEventContext.java
===================================================================
---
trunk/api/src/main/org/jboss/portal/api/node/event/PortalNodeEventContext.java 2007-01-22
16:24:53 UTC (rev 6066)
+++
trunk/api/src/main/org/jboss/portal/api/node/event/PortalNodeEventContext.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -23,6 +23,7 @@
package org.jboss.portal.api.node.event;
import org.jboss.portal.api.node.PortalNode;
+import org.jboss.portal.spi.NavigationalStateContext;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -43,4 +44,11 @@
* @return the current node.
*/
PortalNode getNode();
+
+ /**
+ * Returns the navigational state context.
+ *
+ * @return the navigational state context
+ */
+ NavigationalStateContext getNavigationalStateContext();
}
Modified: trunk/api/src/main/org/jboss/portal/api/node/event/WindowEvent.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/api/node/event/WindowEvent.java 2007-01-22
16:24:53 UTC (rev 6066)
+++ trunk/api/src/main/org/jboss/portal/api/node/event/WindowEvent.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -27,7 +27,7 @@
import org.jboss.portal.api.node.PortalNode;
/** @author <a href="mailto:julien@jboss.org">Julien Viet</a> */
-public class WindowEvent extends PortalNodeEvent
+public abstract class WindowEvent extends PortalNodeEvent
{
/** . */
Modified: trunk/api/src/main/org/jboss/portal/api/node/event/WindowRenderEvent.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/api/node/event/WindowRenderEvent.java 2007-01-22
16:24:53 UTC (rev 6066)
+++ trunk/api/src/main/org/jboss/portal/api/node/event/WindowRenderEvent.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -30,7 +30,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class WindowRenderEvent extends WindowEvent
+public class WindowRenderEvent extends WindowNavigationEvent
{
/** . */
Added: trunk/api/src/main/org/jboss/portal/spi/NavigationalStateContext.java
===================================================================
--- trunk/api/src/main/org/jboss/portal/spi/NavigationalStateContext.java
(rev 0)
+++ trunk/api/src/main/org/jboss/portal/spi/NavigationalStateContext.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.spi;
+
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.portal.api.node.PortalNode;
+
+/**
+ * Provide access to the navigational state.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface NavigationalStateContext
+{
+ /**
+ * Returns the window state of a window or null if it is not found.
+ *
+ * @param window the window from which the window state is returned
+ * @return the window state
+ * @throws IllegalArgumentException
+ */
+ WindowState getWindowState(PortalNode window) throws IllegalArgumentException;
+
+ /**
+ * Updates the window state of a window.
+ *
+ * @param window the window to update
+ * @param windowState the new window state value
+ * @throws IllegalArgumentException
+ */
+ void setWindowState(PortalNode window, WindowState windowState) throws
IllegalArgumentException;
+
+ /**
+ * Returns the mode of a window or null if it is not found.
+ *
+ * @param window the window from which the mode is returned
+ * @return the mode
+ * @throws IllegalArgumentException
+ */
+ Mode getMode(PortalNode window) throws IllegalArgumentException;
+
+ /**
+ * Updates the mode of a window.
+ *
+ * @param window the window to update
+ * @param mode the new mode value
+ * @throws IllegalArgumentException
+ */
+ void setMode(PortalNode window, Mode mode) throws IllegalArgumentException;
+}
Deleted: trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java 2007-01-22 16:24:53
UTC (rev 6066)
+++ trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java 2007-01-22 19:39:41
UTC (rev 6067)
@@ -1,183 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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.core;
-
-import org.jboss.portal.core.controller.ControllerInterceptor;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.model.portal.command.RenderPageCommand;
-import org.jboss.portal.core.model.portal.command.InvokePortletWindowRenderCommand;
-import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.theme.navigation.WindowNavigationalState;
-import org.jboss.portal.WindowState;
-
-import java.util.Iterator;
-import java.util.Collection;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class WindowInterceptor extends ControllerInterceptor
-{
- public Object invoke(ControllerCommand cmd) throws Exception, InvocationException
- {
- if (cmd instanceof InvokePortletWindowRenderCommand)
- {
- // Update state
- cmd.invokeNext();
-
- //
- InvokePortletWindowRenderCommand ipwrc = (InvokePortletWindowRenderCommand)cmd;
- Window targetWindow = ipwrc.getWindow();
- Collection windows =
targetWindow.getParent().getChildren(PortalObject.TYPE_WINDOW);
- WindowManipulator manipulator = new
WindowManipulator(cmd.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE),
windows);
- WindowState ws = ipwrc.getWindowState();
-
- //
- if (WindowState.NORMAL.equals(ws))
- {
- String regionName = manipulator.getRegionName(targetWindow);
- if (regionName != null)
- {
- for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
- {
- Window currentWindow = (Window)i.next();
- if (currentWindow.getId().equals(targetWindow.getId()))
- {
- // Do nothing
- }
- else
- {
- WindowNavigationalState wns =
manipulator.getNavigationalState(currentWindow);
- wns.setWindowState(WindowState.MINIMIZED);
- }
- }
- }
- }
- else if (WindowState.MINIMIZED.equals(ws))
- {
- String regionName = manipulator.getRegionName(targetWindow);
- if (regionName != null)
- {
- // Find the window following the minimized one
- Window nextWindow = null;
- for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
- {
- Window currentWindow = (Window)i.next();
-
- // Keep a ref on the first window for later use
- if (nextWindow == null)
- {
- nextWindow = currentWindow;
- }
-
- //
- if (currentWindow.getId().equals(targetWindow.getId()))
- {
- // Try to get the next window otherwise it means it's the last
window
- // and we'll use the window we saved at the first iteration
- if (i.hasNext())
- {
- nextWindow = (Window)i.next();
- }
-
- //
- break;
- }
- }
-
- // Normalize the next window
- if (nextWindow != null)
- {
- WindowNavigationalState wns =
manipulator.getNavigationalState(nextWindow);
- wns.setWindowState(WindowState.NORMAL);
- }
- }
- }
- }
- if (cmd instanceof RenderPageCommand)
- {
- RenderPageCommand rpc = (RenderPageCommand)cmd;
- WindowManipulator manipulator = new
WindowManipulator(cmd.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE),
rpc.getWindows());
-
- // Filter window state for normal and minimized
- for (Iterator i = manipulator.getRegionNames().iterator();i.hasNext();)
- {
- boolean foundNormal = false;
- Window firstWindow = null;
- String regionName = (String)i.next();
- for (Iterator j =
manipulator.getWindows(regionName).iterator();j.hasNext();)
- {
- Window window = (Window)j.next();
-
- // Keep a ref on first window which can be used later
- if (firstWindow == null)
- {
- firstWindow = window;
- }
-
- //
- WindowNavigationalState wns = manipulator.getNavigationalState(window);
- WindowState ws = wns.getWindowState();
- if (WindowState.NORMAL.equals(ws))
- {
- if (foundNormal)
- {
- wns.setWindowState(WindowState.MINIMIZED);
- }
- else
- {
- foundNormal = true;
- }
- }
- else if (WindowState.MINIMIZED.equals(ws))
- {
- //
- }
- else
- {
- ws = WindowState.MINIMIZED;
- wns.setWindowState(ws);
- }
- }
-
- //
- if (foundNormal == false && firstWindow != null)
- {
- WindowNavigationalState wns =
manipulator.getNavigationalState(firstWindow);
- wns.setWindowState(WindowState.NORMAL);
- }
- }
-
- //
- return cmd.invokeNext();
- }
- else
- {
- return cmd.invokeNext();
- }
- }
-}
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java 2007-01-22
16:24:53 UTC (rev 6066)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/EventBroadcasterInterceptor.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -25,13 +25,17 @@
import org.apache.log4j.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.theme.navigation.WindowNavigationalState;
+import org.jboss.portal.spi.NavigationalStateContext;
import org.jboss.portal.api.node.PortalNode;
import org.jboss.portal.api.node.event.PortalNodeEvent;
import org.jboss.portal.api.node.event.WindowActionEvent;
import org.jboss.portal.api.node.event.WindowEvent;
import org.jboss.portal.api.node.event.WindowNavigationEvent;
import org.jboss.portal.api.node.event.WindowRenderEvent;
+import org.jboss.portal.api.node.event.PageRenderEvent;
import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.common.invocation.AttributeResolver;
import org.jboss.portal.common.util.LazyMap;
import org.jboss.portal.core.controller.CommandRedirectionException;
import org.jboss.portal.core.controller.ControllerCommand;
@@ -39,6 +43,7 @@
import org.jboss.portal.core.model.portal.command.InvokePortletWindowActionCommand;
import org.jboss.portal.core.model.portal.command.InvokePortletWindowRenderCommand;
import org.jboss.portal.core.model.portal.command.WindowCommand;
+import org.jboss.portal.core.model.portal.command.RenderPageCommand;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.event.PortalEventListenerRegistry;
import org.jboss.portal.portlet.PortletParameters;
@@ -57,7 +62,6 @@
/** . */
private PortalEventListenerRegistry listenerRegistry;
-
public PortalEventListenerRegistry getListenerRegistry()
{
return listenerRegistry;
@@ -79,7 +83,8 @@
{
try
{
- nextEvent = node.fireEvent(listenerRegistry, event);
+ NavigationalStateContextImpl nsContext = new
NavigationalStateContextImpl(cmd.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE));
+ nextEvent = node.fireEvent(listenerRegistry, event, nsContext);
}
catch (Exception e)
{
@@ -263,6 +268,10 @@
}
}
}
+ else if (cmd instanceof RenderPageCommand)
+ {
+ return new PageRenderEvent(node);
+ }
return null;
}
@@ -318,4 +327,99 @@
return params;
}
}
+
+ private static class NavigationalStateContextImpl implements NavigationalStateContext
+ {
+
+ /** . */
+ private AttributeResolver navigationalStateResolver;
+
+ public NavigationalStateContextImpl(AttributeResolver navigationalStateResolver)
+ {
+ this.navigationalStateResolver = navigationalStateResolver;
+ }
+
+ private WindowNavigationalState getWNS(PortalNode window, boolean create)
+ {
+ PortalObjectNode pon = (PortalObjectNode)window;
+ String key = pon.getObjectId().toString() + "_window";
+ WindowNavigationalState wns =
(WindowNavigationalState)navigationalStateResolver.getAttribute(key);
+ if (wns == null && create)
+ {
+ wns = new WindowNavigationalState();
+ navigationalStateResolver.setAttribute(key, wns);
+ }
+ return wns;
+ }
+
+ public WindowState getWindowState(PortalNode window) throws
IllegalArgumentException
+ {
+ if (window == null)
+ {
+ throw new IllegalArgumentException("No null window can be
provided");
+ }
+
+ //
+ WindowNavigationalState wns = getWNS(window, false);
+ if (wns != null)
+ {
+ return wns.getWindowState();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void setWindowState(PortalNode window, WindowState windowState) throws
IllegalArgumentException
+ {
+ if (window == null)
+ {
+ throw new IllegalArgumentException("No null window can be
provided");
+ }
+ if (windowState == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ WindowNavigationalState wns = getWNS(window, true);
+ wns.setWindowState(windowState);
+ }
+
+ public Mode getMode(PortalNode window) throws IllegalArgumentException
+ {
+ if (window == null)
+ {
+ throw new IllegalArgumentException("No null window can be
provided");
+ }
+
+ //
+ WindowNavigationalState wns = getWNS(window, false);
+ if (wns != null)
+ {
+ return wns.getMode();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void setMode(PortalNode window, Mode mode) throws IllegalArgumentException
+ {
+ if (window == null)
+ {
+ throw new IllegalArgumentException("No null window can be
provided");
+ }
+ if (mode == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ WindowNavigationalState wns = getWNS(window, true);
+ wns.setMode(mode);
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalNodeInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalNodeInterceptor.java 2007-01-22
16:24:53 UTC (rev 6066)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalNodeInterceptor.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -37,8 +37,6 @@
public class PortalNodeInterceptor extends ControllerInterceptor
{
-// private static Logger log = Logger.getLogger(PortalNodeInterceptor.class);
-
public Object invoke(ControllerCommand cmd) throws Exception, InvocationException
{
// Get the next node
Modified:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalObjectNode.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalObjectNode.java 2007-01-22
16:24:53 UTC (rev 6066)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/node/PortalObjectNode.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -30,6 +30,7 @@
import org.jboss.portal.core.event.PortalEventListenerRegistry;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.spi.NavigationalStateContext;
import java.util.Collection;
import java.util.Collections;
@@ -188,9 +189,9 @@
return object.getId();
}
- public PortalNodeEvent fireEvent(PortalEventListenerRegistry registry, PortalNodeEvent
event)
+ public PortalNodeEvent fireEvent(PortalEventListenerRegistry registry, PortalNodeEvent
event, NavigationalStateContext nsContext)
{
- Bubbler bubbler = new Bubbler(registry, this, event);
+ Bubbler bubbler = new Bubbler(registry, this, event, nsContext);
return bubbler.dispatch();
}
@@ -223,13 +224,26 @@
/** . */
private PortalObjectNode node;
- public Bubbler(PortalEventListenerRegistry registry, PortalObjectNode node,
PortalNodeEvent event)
+ /** . */
+ private NavigationalStateContext nsContext;
+
+ public Bubbler(
+ PortalEventListenerRegistry registry,
+ PortalObjectNode node,
+ PortalNodeEvent event,
+ NavigationalStateContext nsContext)
{
this.registry = registry;
this.node = node;
this.event = event;
+ this.nsContext = nsContext;
}
+ public NavigationalStateContext getNavigationalStateContext()
+ {
+ return nsContext;
+ }
+
public PortalNodeEvent dispatch()
{
PortalNodeEventListener listener = null;
Added:
trunk/core/src/main/org/jboss/portal/core/portlet/test/event/WindowConstraintEventListener.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/test/event/WindowConstraintEventListener.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/test/event/WindowConstraintEventListener.java 2007-01-22
19:39:41 UTC (rev 6067)
@@ -0,0 +1,254 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.core.portlet.test.event;
+
+import org.jboss.portal.api.node.event.PortalNodeEventListener;
+import org.jboss.portal.api.node.event.PortalNodeEvent;
+import org.jboss.portal.api.node.event.PortalNodeEventContext;
+import org.jboss.portal.api.node.event.PageRenderEvent;
+import org.jboss.portal.api.node.event.WindowNavigationEvent;
+import org.jboss.portal.api.node.PortalNode;
+import org.jboss.portal.theme.ThemeConstants;
+import org.jboss.portal.spi.NavigationalStateContext;
+import org.jboss.portal.WindowState;
+
+import java.util.Map;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowConstraintEventListener implements PortalNodeEventListener
+{
+
+ public PortalNodeEvent onEvent(PortalNodeEventContext context, PortalNodeEvent event)
+ {
+ if (event instanceof PageRenderEvent)
+ {
+ PortalNode targetPage = event.getNode();
+ WindowManipulator manipulator = new
WindowManipulator(context.getNavigationalStateContext(), targetPage);
+
+ // Filter window state for normal and minimized
+ for (Iterator i = manipulator.getRegionNames().iterator();i.hasNext();)
+ {
+ boolean foundNormal = false;
+ PortalNode firstWindow = null;
+ String regionName = (String)i.next();
+ for (Iterator j =
manipulator.getWindows(regionName).iterator();j.hasNext();)
+ {
+ PortalNode window = (PortalNode)j.next();
+
+ // Keep a ref on first window which can be used later
+ if (firstWindow == null)
+ {
+ firstWindow = window;
+ }
+
+ //
+ WindowState ws = manipulator.getWindowState(window);
+ if (WindowState.NORMAL.equals(ws))
+ {
+ if (foundNormal)
+ {
+ manipulator.setWindowState(window, WindowState.MINIMIZED);
+ }
+ else
+ {
+ foundNormal = true;
+ }
+ }
+ else if (WindowState.MINIMIZED.equals(ws))
+ {
+ //
+ }
+ else
+ {
+ manipulator.setWindowState(window, WindowState.MINIMIZED);
+ }
+ }
+
+ //
+ if (foundNormal == false && firstWindow != null)
+ {
+ manipulator.setWindowState(firstWindow, WindowState.NORMAL);
+ }
+ }
+ }
+ else if (event instanceof WindowNavigationEvent)
+ {
+ WindowNavigationEvent wne = (WindowNavigationEvent)event;
+ PortalNode targetWindow = event.getNode();
+ WindowManipulator manipulator = new
WindowManipulator(context.getNavigationalStateContext(), targetWindow.getParent());
+
+ //
+ WindowState ws = wne.getWindowState();
+
+ //
+ if (WindowState.NORMAL.equals(ws))
+ {
+ String regionName = manipulator.getRegionName(targetWindow);
+ if (regionName != null)
+ {
+ for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
+ {
+ PortalNode currentWindow = (PortalNode)i.next();
+ if (currentWindow.equals(targetWindow))
+ {
+ // Do nothing
+ }
+ else
+ {
+ manipulator.setWindowState(currentWindow, WindowState.MINIMIZED);
+ }
+ }
+ }
+ }
+ else if (WindowState.MINIMIZED.equals(ws))
+ {
+ String regionName = manipulator.getRegionName(targetWindow);
+ if (regionName != null)
+ {
+ // Find the window following the minimized one
+ PortalNode nextWindow = null;
+ for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
+ {
+ PortalNode currentWindow = (PortalNode)i.next();
+
+ // Keep a ref on the first window for later use
+ if (nextWindow == null)
+ {
+ nextWindow = currentWindow;
+ }
+
+ //
+ if (currentWindow.equals(targetWindow))
+ {
+ // Try to get the next window otherwise it means it's the last
window
+ // and we'll use the window we saved at the first iteration
+ if (i.hasNext())
+ {
+ nextWindow = (PortalNode)i.next();
+ }
+
+ //
+ break;
+ }
+ }
+
+ // Normalize the next window
+ if (nextWindow != null)
+ {
+ manipulator.setWindowState(nextWindow, WindowState.NORMAL);
+ }
+ }
+ }
+ }
+ return context.dispatch();
+ }
+
+ public class WindowManipulator
+ {
+
+ /** . */
+ private Map regionMap;
+
+ /** . */
+ private NavigationalStateContext nsContext;
+
+ public WindowManipulator(NavigationalStateContext nsContext, PortalNode parent)
+ {
+ this.nsContext = nsContext;
+
+ // Build appropriate structure
+ regionMap = new HashMap();
+ for (Iterator i = parent.getChildren().iterator();i.hasNext();)
+ {
+ try
+ {
+ PortalNode object = (PortalNode)i.next();
+ if (object.getType() == PortalNode.TYPE_WINDOW)
+ {
+ String region =
(String)object.getProperties().get(ThemeConstants.PORTAL_PROP_REGION);
+ Integer order = new
Integer((String)object.getProperties().get(ThemeConstants.PORTAL_PROP_ORDER));
+
+ //
+ SortedMap windowMap = (SortedMap)regionMap.get(region);
+ if (windowMap == null)
+ {
+ windowMap = new TreeMap();
+ regionMap.put(region, windowMap);
+ }
+ windowMap.put(order, object);
+ }
+ }
+ catch (NumberFormatException ignore)
+ {
+ }
+ }
+ }
+
+ public String getRegionName(PortalNode window)
+ {
+ for (Iterator i = regionMap.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ SortedMap windows = (SortedMap)entry.getValue();
+ for (Iterator j = windows.values().iterator();j.hasNext();)
+ {
+ PortalNode window2 = (PortalNode)j.next();
+ if (window.equals(window2))
+ {
+ return (String)entry.getKey();
+ }
+ }
+ }
+ return null;
+ }
+
+ public Set getRegionNames()
+ {
+ return regionMap.keySet();
+ }
+
+ public Collection getWindows(String regionName)
+ {
+ return ((Map)regionMap.get(regionName)).values();
+ }
+
+ public WindowState getWindowState(PortalNode window)
+ {
+ return nsContext.getWindowState(window);
+ }
+
+ public void setWindowState(PortalNode window, WindowState windowState)
+ {
+ nsContext.setWindowState(window, windowState);
+ }
+ }
+}
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-22
16:24:53 UTC (rev 6066)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-22
19:39:41 UTC (rev 6067)
@@ -493,6 +493,18 @@
<attribute name="RegistryId">test_listener</attribute>
<attribute
name="ListenerClassName">org.jboss.portal.core.portlet.test.event.PortletB$Listener</attribute>
</mbean>
+ <mbean
+ code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
+ name="portal:service=ListenerService,type=window_listener"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="Registry"
+
proxy-type="attribute">portal:service=ListenerRegistry</depends>
+ <attribute
name="RegistryId">window_event_listener</attribute>
+ <attribute
name="ListenerClassName">org.jboss.portal.core.portlet.test.event.WindowConstraintEventListener</attribute>
+ </mbean>
<!-- The different containers -->
<mbean
Modified: trunk/core/src/resources/portal-samples-war/WEB-INF/default-object.xml
===================================================================
--- trunk/core/src/resources/portal-samples-war/WEB-INF/default-object.xml 2007-01-22
16:24:53 UTC (rev 6066)
+++ trunk/core/src/resources/portal-samples-war/WEB-INF/default-object.xml 2007-01-22
19:39:41 UTC (rev 6067)
@@ -28,7 +28,6 @@
<if-exists>keep</if-exists>
<page>
<page-name>Test</page-name>
- <listener>test_listener</listener>
<properties>
<property>
<name>theme.ajax.object_disabled</name>
@@ -53,6 +52,7 @@
</window>
<page>
<page-name>event test</page-name>
+ <listener>event_listener</listener>
<window>
<window-name>CatalogPortletWindow</window-name>
<instance-ref>CatalogPortletInstance</instance-ref>
@@ -73,6 +73,46 @@
</window>
</page>
<page>
+ <page-name>page event test</page-name>
+ <listener>window_event_listener</listener>
+ <window>
+ <window-name>CatalogPortletWindow1</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>left</region>
+ <height>0</height>
+ </window>
+ <window>
+ <window-name>CatalogPortletWindow2</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>left</region>
+ <height>1</height>
+ </window>
+ <window>
+ <window-name>CatalogPortletWindow3</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>left</region>
+ <height>2</height>
+ </window>
+ <window>
+ <window-name>CatalogPortletWindow4</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>center</region>
+ <height>0</height>
+ </window>
+ <window>
+ <window-name>CatalogPortletWindow5</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>center</region>
+ <height>1</height>
+ </window>
+ <window>
+ <window-name>CatalogPortletWindow6</window-name>
+ <instance-ref>CatalogPortletInstance</instance-ref>
+ <region>center</region>
+ <height>2</height>
+ </window>
+ </page>
+ <page>
<page-name>secure test</page-name>
<window>
<window-name>CatalogPortletWindow</window-name>