Author: sohil.shah(a)jboss.com
Date: 2008-01-23 23:51:25 -0500 (Wed, 23 Jan 2008)
New Revision: 9594
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/SessionConstants.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/AjaxModelListener.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/PresentationContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java
Log:
Ajax User Agent - first pass at the server side component of the agent based on
ModelListener approach
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIContext.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIContext.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -45,10 +45,11 @@
{
AjaxUIObject object = null;
+ //Perform a direct quick lookup
if(this.objectTree.containsKey(id))
{
object = (AjaxUIObject)this.objectTree.get(id);
- }
+ }
return object;
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIObject.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/model/AjaxUIObject.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.ajax.client.model;
import java.util.List;
+import java.util.ArrayList;
import com.google.gwt.user.client.rpc.IsSerializable;
@@ -108,6 +109,10 @@
*/
public List getChildren()
{
+ if(this.children == null)
+ {
+ this.children = new ArrayList();
+ }
return this.children;
}
@@ -116,7 +121,7 @@
* @param name
* @return
*/
- public AjaxUIObject getChild(String name)
+ public AjaxUIObject getChild(String id)
{
AjaxUIObject child = null;
@@ -125,7 +130,7 @@
for(int i=0; i<this.children.size(); i++)
{
AjaxUIObject cour = (AjaxUIObject)this.children.get(i);
- if(cour.getName().equals(name))
+ if(cour.id.equals(id))
{
child = cour;
break;
@@ -135,6 +140,40 @@
return child;
}
+
+ /**
+ *
+ * @param children
+ */
+ public void setChildren(List children)
+ {
+ this.children = children;
+ }
+
+ /**
+ *
+ * @param child
+ */
+ /*public void addChild(AjaxUIObject child)
+ {
+ AjaxUIObject find = null;
+ for(int i=0; i<this.getChildren().size(); i++)
+ {
+ AjaxUIObject cour = (AjaxUIObject)this.getChildren().get(i);
+ if(cour.id.equals(child.id))
+ {
+ find = cour;
+ }
+ }
+
+ if(find != null)
+ {
+ this.getChildren().remove(find);
+ }
+
+ this.getChildren().add(child);
+ }*/
+
public AjaxUIContext getContext()
{
@@ -146,15 +185,6 @@
this.context = context;
}
- /**
- *
- * @param children
- */
- public void setChildren(List children)
- {
- this.children = children;
- }
-
public void setId(String id)
{
this.id = id;
@@ -168,5 +198,5 @@
public void setStatus(int status)
{
this.status = status;
- }
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/PresentationContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/PresentationContext.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/PresentationContext.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.client;
import org.jboss.portal.presentation.protocol.ServerAction;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.server.ServerInvocation;
import org.jboss.portal.web.ServletContextDispatcher;
@@ -51,6 +52,13 @@
* @return the ui context
*/
UIContext getUIContext();
+
+ /**
+ * Provide the root UI context for the server side cache of the Ajax User Agent
+ *
+ * @return
+ */
+ public AjaxUIContext getAjaxUIContext();
/**
* Returns the servlet context dispatcher.
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/AjaxUIController.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -28,8 +28,6 @@
import org.jboss.portal.presentation.model.UIPage;
import org.jboss.portal.presentation.model.UIWindow;
import org.jboss.portal.presentation.model.content.WindowContent;
-import org.jboss.portal.presentation.protocol.GetActivation;
-import org.jboss.portal.presentation.protocol.PostActivation;
import org.jboss.portal.presentation.protocol.ServerAction;
import org.jboss.portal.presentation.protocol.ServerResponse;
import org.jboss.portal.presentation.protocol.ShowUIObjectResponse;
@@ -37,17 +35,15 @@
import org.jboss.portal.presentation.server.PresentationServer;
import org.jboss.portal.presentation.server.ProcessorRequest;
import org.jboss.portal.presentation.server.ProcessorResponse;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIWindow;
import org.jboss.portal.server.RequestController;
import org.jboss.portal.server.ServerException;
import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.ServerInvocationContext;
-import org.jboss.portal.server.impl.ServerInvocationContextImpl;
-import org.jboss.portal.web.WebRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.List;
-import java.util.ArrayList;
import java.util.Collection;
/**
@@ -84,9 +80,9 @@
/**
* TODO: decouple the implementation via factory pattern
- */
- PresentationContext presentationContext = new
PresentationContextImpl(this.presentationServer,
- invocation);
+ */
+ PresentationContext presentationContext = presentationContext = new
PresentationContextImpl(this.presentationServer,
+ invocation);
request.setAttribute("requestContext", presentationContext);
/**
@@ -139,55 +135,74 @@
private void render(ServerInvocation invocation,PresentationContext
presentationContext, String targetId)
{
UIObject uiObject = presentationContext.getUIContext().getObject(targetId);
-
+
//Display the page to the client
if(uiObject instanceof UIPage)
{
UIPage page = (UIPage)uiObject;
+ AjaxUIContext ajaxUiContext = presentationContext.getAjaxUIContext();
- org.jboss.portal.presentation.ajax.client.model.AjaxUIPage clientPage = new
org.jboss.portal.presentation.ajax.client.model.AjaxUIPage();
- clientPage.setId(page.getId());
- //TODO: set proper status
- //TODO: set proper parent reference
+ //Process the Page to be displayed
+ AjaxUIPage clientPage = (AjaxUIPage)ajaxUiContext.getObject(page.getId());
+ boolean pageJustCreated = false;
+ if(clientPage == null)
+ {
+ clientPage = new
org.jboss.portal.presentation.ajax.client.model.AjaxUIPage();
+ clientPage.setId(page.getId());
+ ajaxUiContext.addObject(clientPage);
+ pageJustCreated = true;
+ }
- Collection<? extends UIObject> windows = page.getChildren();
- List clientWindows = new ArrayList();
+ //Process the Windows belonging to this Page
+ Collection<? extends UIObject> windows = page.getChildren();
for(UIObject cour : windows)
{
if(cour instanceof UIWindow)
{
- UIWindow window = (UIWindow)cour;
- try
+ UIWindow window = (UIWindow)cour;
+
+ //Make sure this window properly belongs to the AjaxUIContext object tree
+ AjaxUIWindow clientWindow =
(AjaxUIWindow)clientPage.getChild(window.getId());
+ if(clientWindow == null)
{
- WindowContent windowContent =
this.presentationServer.render(presentationContext, window);
-
- org.jboss.portal.presentation.ajax.client.model.AjaxUIWindow
clientWindow = new org.jboss.portal.presentation.ajax.client.model.AjaxUIWindow();
-
- clientWindow.setId(window.getId());
- clientWindow.setParent(clientPage);
- //TODO: Set proper status
-
- clientWindow.setContent(windowContent.getMarkup());
- if(window.getMode() != null)
- {
- clientWindow.setMode(window.getMode().toString());
+ clientWindow = new
org.jboss.portal.presentation.ajax.client.model.AjaxUIWindow();
+ clientWindow.setId(window.getId());
+ clientPage.getChildren().add(clientWindow);
+ ajaxUiContext.addObject(clientWindow);
+ }
+
+ //Render this window only if this Page is being rendered for the first
time in this
+ //User Session or if the navigation state of this window has changed
during this interaction
+ //TODO: also add cache expiration as one of the conditions for this
action
+ if(pageJustCreated || clientWindow.getStatus() ==
AjaxUIWindow.STATUS_STALE)
+ {
+ try
+ {
+ WindowContent windowContent =
this.presentationServer.render(presentationContext, window);
+
+ clientWindow.setId(window.getId());
+ clientWindow.setParent(clientPage);
+
+ clientWindow.setContent(windowContent.getMarkup());
+ if(window.getMode() != null)
+ {
+ clientWindow.setMode(window.getMode().toString());
+ }
+ if(window.getWindowState() != null)
+ {
+ clientWindow.setState(window.getWindowState().toString());
+ }
+
+ //Restore the Status of the Window
+ clientWindow.setStatus(AjaxUIWindow.STATUS_VALID);
}
- if(window.getWindowState() != null)
+ catch (Exception e)
{
- clientWindow.setState(window.getWindowState().toString());
- }
-
- clientWindows.add(clientWindow);
+ e.printStackTrace();
+ }
}
- catch (Exception e)
- {
- e.printStackTrace();
- }
}
- }
-
- clientPage.setChildren(clientWindows);
-
+ }
invocation.getServerContext().getClientRequest().setAttribute("uiObject",
clientPage);
}
}
@@ -243,86 +258,7 @@
{
action = new ViewUIObjectAction("/default/default");
}
-
-
- return action;
- /*ServerInvocationContext invocationContext = invocation.getServerContext();
- String requestPath = invocation.getServerContext().getPortalRequestPath();
-
- //
- if (requestPath.startsWith("/invoke/"))
- {
- UIObject target = presentationContext.getUIContext();
-
- //
- int from = "/invoke/".length();
- while (true)
- {
- int pos = requestPath.indexOf('/', from);
- if (pos == -1)
- {
- String name = requestPath.substring(from);
- target = target.getChild(name);
- break;
- }
- else
- {
- String name = requestPath.substring(from, pos);
- target = target.getChild(name);
- }
- if (target == null)
- {
- break;
- }
- from = pos + 1;
- }
-
- // I know but it will go away later when we remove dependency on server module
- WebRequest webReq =
((ServerInvocationContextImpl)invocation.getContext()).getWebRequest();
-
- //
- if (target != null)
- {
- if ("GET".equals(webReq.getMethod()))
- {
- return new GetActivation(target.getId(), webReq.getQueryParameterMap());
- }
- else if ("POST".equals(webReq.getMethod()))
- {
- return new PostActivation(target.getId(), webReq.getQueryParameterMap(),
webReq.getBody());
- }
- }
- }
-
-
- if(targetPortalObject instanceof UIPage)
- {
- serverAction = new ViewUIObjectAction(targetPortalObject.getId());
- }
- else if(targetPortalObject instanceof UIWindow)
- {
- if(request.getMethod().equals("GET"))
- {
- GetActivation get = new GetActivation();
- get.setUrl(request.getRequestURL().toString());
- get.setContentType(invocationContext.getMediaType());
- get.setQueryParameters(invocationContext.getQueryParameterMap());
- get.setPortal(targetPortal);
- get.setTarget(targetPortalObject);
- serverAction = get;
- }
- else if(request.getMethod().equals("POST"))
- {
- PostActivation post = new PostActivation();
- post.setUrl(request.getRequestURL().toString());
- post.setContentType(invocationContext.getMediaType());
- post.setQueryParameters(invocationContext.getQueryParameterMap());
- post.setBodyParameters(invocationContext.getBodyParameterMap());
- post.setPortal(targetPortal);
- post.setTarget(targetPortalObject);
- serverAction = post;
- }
- }*/
- }
+ return action;
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -40,14 +40,12 @@
import org.jboss.portal.server.RequestController;
import org.jboss.portal.server.ServerException;
import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.ServerInvocationContext;
import org.jboss.portal.server.impl.ServerInvocationContextImpl;
import org.jboss.portal.web.WebRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
-import java.util.List;
import java.util.Collection;
import java.util.Map;
@@ -179,7 +177,6 @@
*/
private ServerAction getServerAction(PresentationContext presentationContext,
ServerInvocation invocation)
{
- ServerInvocationContext invocationContext = invocation.getServerContext();
String requestPath = invocation.getServerContext().getPortalRequestPath();
WebRequest webReq =
((ServerInvocationContextImpl)invocation.getContext()).getWebRequest();
Map queryParameters = webReq.getQueryParameterMap();
@@ -228,101 +225,8 @@
//Just use ViewUIObject command for now until URL interpretation/mapping
//to ServiceAction is implemented
- return new ViewUIObjectAction("/default/default");
-
- /*if(targetPortalObject instanceof UIPage)
- {
- serverAction = new ViewUIObjectAction(targetPortalObject.getId());
- }
- else if(targetPortalObject instanceof UIWindow)
- {
- if(request.getMethod().equals("GET"))
- {
- GetActivation get = new GetActivation();
- get.setUrl(request.getRequestURL().toString());
- get.setContentType(invocationContext.getMediaType());
- get.setQueryParameters(invocationContext.getQueryParameterMap());
- get.setPortal(targetPortal);
- get.setTarget(targetPortalObject);
- serverAction = get;
- }
- else if(request.getMethod().equals("POST"))
- {
- PostActivation post = new PostActivation();
- post.setUrl(request.getRequestURL().toString());
- post.setContentType(invocationContext.getMediaType());
- post.setQueryParameters(invocationContext.getQueryParameterMap());
- post.setBodyParameters(invocationContext.getBodyParameterMap());
- post.setPortal(targetPortal);
- post.setTarget(targetPortalObject);
- serverAction = post;
- }
- }*/
- }
-
- /**
- *
- * @param portalRequestPath
- * @return
- */
- /*private UIPortal getTargetPortal(RequestContext requestContext,String
portalRequestPath)
- {
- UIPortal targetPortal = null;
-
- //Parse the portalRequestPath and find the targetted Portal
- StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
- StringBuffer buffer = new StringBuffer("/");
- while(st.hasMoreTokens())
- {
- String token = st.nextToken();
- buffer.append(token);
- String id = buffer.toString();
- ObjectState objectState =
this.presentationServer.getStructuralStateManager().load(id);
- if(objectState != null && objectState.getType() == UIPortal.class)
- {
- targetPortal = (UIPortal)requestContext.getUIContext().getObject(id);
- break;
- }
- buffer.append("/");
- }
-
- return targetPortal;
- }*/
-
- /**
- *
- * @param portalRequestPath
- * @return
- */
- /*private UIObject getTargetPortalObject(RequestContext requestContext,String
portalRequestPath)
- {
- UIObject targetPortalObject = null;
-
- //Parse the portalRequestPath and find the targetted Portal Object (Page or Window)
- StringTokenizer st = new StringTokenizer(portalRequestPath, "/");
- StringBuffer buffer = new StringBuffer("/");
- while(st.hasMoreTokens())
- {
- String token = st.nextToken();
- buffer.append(token);
- String id = buffer.toString();
- ObjectState objectState =
this.presentationServer.getStructuralStateManager().load(id);
- if(objectState != null)
- {
- if(objectState.getType() == UIPage.class)
- {
- targetPortalObject = (UIPage)requestContext.getUIContext().getObject(id);
- }
- else if(objectState.getType() == UIWindow.class)
- {
- targetPortalObject =
(UIWindow)requestContext.getUIContext().getObject(id);
- }
- }
- buffer.append("/");
- }
-
- return targetPortalObject;
- }*/
+ return new ViewUIObjectAction("/default/default");
+ }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* TODO: this should be used only in classic UI case...eventually when Controller is
abstracted, this will be moved to
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2008-01-23
23:43:05 UTC (rev 9593)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/PresentationContextImpl.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -22,9 +22,11 @@
******************************************************************************/
package org.jboss.portal.presentation.impl;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
import org.jboss.portal.presentation.client.PresentationContext;
import org.jboss.portal.presentation.impl.model.container.UIObjectContainer;
import
org.jboss.portal.presentation.impl.model.state.navigational.NavigationalStateContextImpl;
+import org.jboss.portal.presentation.impl.model.AjaxModelListener;
import org.jboss.portal.presentation.model.UIContext;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
@@ -41,6 +43,7 @@
import org.jboss.portal.web.ServletContextDispatcher;
import org.jboss.portal.web.impl.DefaultServletContainerFactory;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
@@ -56,40 +59,67 @@
/** . */
private PresentationServer presentationServer = null;
- /** . */
- private UIObjectContainer container;
-
+ /**
+ *
+ * @param presentationServer
+ * @param invocation
+ */
public PresentationContextImpl(PresentationServer presentationServer, ServerInvocation
invocation)
{
this.invocation = invocation;
this.presentationServer = presentationServer;
}
+ /**
+ *
+ */
public UIContext getUIContext()
{
- if (container == null)
- {
- HttpSession session =
this.invocation.getServerContext().getClientRequest().getSession();
+ HttpSession session =
this.invocation.getServerContext().getClientRequest().getSession();
+
+ //Process the UIObjectContainer for this session
+ UIObjectContainer uiObjectContainer =
(UIObjectContainer)session.getAttribute(SessionConstants.serverModel);
+ if (uiObjectContainer == null)
+ {
+ NavigationalStateContext nsc = new NavigationalStateContextImpl();
//
- NavigationalStateContext nsc =
(NavigationalStateContext)session.getAttribute("nsc");
- if (nsc == null)
- {
- nsc = new NavigationalStateContextImpl();
- session.setAttribute("nsc", nsc);
- }
-
- //
- container = new
UIObjectContainer(presentationServer.getStructuralStateManager(), nsc);
+ uiObjectContainer = new
UIObjectContainer(presentationServer.getStructuralStateManager(), nsc);
+
+ session.setAttribute(SessionConstants.serverModel, uiObjectContainer);
}
//
- return container.getRoot();
+ return uiObjectContainer.getRoot();
}
/**
*
+ * @param request
+ * @return
*/
+ public AjaxUIContext getAjaxUIContext()
+ {
+ AjaxUIContext uiContext = null;
+
+ HttpServletRequest request =
this.invocation.getServerContext().getClientRequest();
+ uiContext =
(AjaxUIContext)request.getSession().getAttribute(SessionConstants.ajaxModel);
+ if(uiContext == null)
+ {
+ uiContext = new AjaxUIContext();
+ request.getSession().setAttribute(SessionConstants.ajaxModel, uiContext);
+
+ //Register a ModelListener to perform partial model updates based on receiving
events due to
+ //Model State changes
+ this.getUIContext().addModelListener(new
AjaxModelListener(this.getAjaxUIContext()));
+ }
+
+ return uiContext;
+ }
+
+ /**
+ *
+ */
public ServletContextDispatcher getDispatcher()
{
ServletContainer container =
DefaultServletContainerFactory.getInstance().getServletContainer();
@@ -141,6 +171,11 @@
}
}
+ /**
+ *
+ * @param object
+ * @param buffer
+ */
private static void createPath(UIObject object, StringBuffer buffer)
{
UIObject parent = object.getParent();
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/SessionConstants.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/SessionConstants.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/SessionConstants.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * 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.presentation.impl;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public interface SessionConstants
+{
+ /**
+ * Represents the session key for storing the server side UI model
+ */
+ public final String serverModel = "serverModel";
+
+ /**
+ * Represents the session key for storing the client side UI model for the Ajax User
Agent
+ */
+ public final String ajaxModel = "ajaxModel";
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/AjaxModelListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/AjaxModelListener.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/AjaxModelListener.java 2008-01-24
04:51:25 UTC (rev 9594)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * 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.presentation.impl.model;
+
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIObject;
+import org.jboss.portal.presentation.model.ModelEvent;
+import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateModification;
+import
org.jboss.portal.presentation.model.event.state.navigational.NavigationalStateModification;
+import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class AjaxModelListener implements ModelListener
+{
+ private AjaxUIContext ajaxUiContext = null;
+
+ /**
+ *
+ * @param uiContext
+ */
+ public AjaxModelListener(AjaxUIContext ajaxUiContext)
+ {
+ this.ajaxUiContext = ajaxUiContext;
+ }
+
+ /**
+ *
+ */
+ public void onEvent(ModelEvent event)
+ {
+ if(event instanceof StateChangeEvent)
+ {
+ StateChangeEvent stateChangeEvent = (StateChangeEvent)event;
+ StateChange stateChange = stateChangeEvent.getChange();
+ StateModification modification = stateChange.getModification();
+ if(modification instanceof NavigationalStateModification)
+ {
+ NavigationalStateModification navMod =
(NavigationalStateModification)modification;
+ if(this.ajaxUiContext != null)
+ {
+ AjaxUIObject ajaxUiObject =
this.ajaxUiContext.getObject(stateChange.getTargetId());
+ if(ajaxUiObject != null)
+ {
+ ajaxUiObject.setStatus(AjaxUIObject.STATUS_STALE);
+ }
+ }
+ }
+ else if(modification instanceof StructuralStateModification)
+ {
+ StructuralStateModification structMod =
(StructuralStateModification)modification;
+
+ /**
+ * TODO: Process Structural State Modifications
+ */
+ }
+ }
+ }
+}