Author: julien(a)jboss.com
Date: 2007-03-06 11:26:19 -0500 (Tue, 06 Mar 2007)
New Revision: 6552
Added:
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletHandler.java
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFPortalContext.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletActionEvent.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletRenderEvent.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portal.taglib.xml
Log:
added support for window state / mode / supported window states / supported modes in the
jsf protlet stuff
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-06
14:51:39 UTC (rev 6551)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -100,7 +100,7 @@
this.uiportlet = uiportlet;
//
- this.portalContext = new JSFPortalContext(faces);
+ this.portalContext = new JSFPortalContext(faces, uiportlet);
this.requestContext = new AbstractRequestContext(clientRequest, clientResponse);
this.securityContext = new JSFSecurityContext(faces);
this.userContext = new JSFUserContext(faces);
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFPortalContext.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFPortalContext.java 2007-03-06
14:51:39 UTC (rev 6551)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFPortalContext.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -31,6 +31,8 @@
import java.util.Set;
import java.util.Map;
import java.util.Collections;
+import java.util.Iterator;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -40,26 +42,72 @@
{
/** . */
- private static final Set modes = Collections.unmodifiableSet(Tools.toSet(new
Mode[]{Mode.VIEW,Mode.EDIT,Mode.HELP}));
+ private static final Set defaultModes = Collections.unmodifiableSet(Tools.toSet(new
Mode[]{Mode.VIEW,Mode.EDIT,Mode.HELP}));
/** . */
- private static final Set windowStates = Collections.unmodifiableSet(Tools.toSet(new
WindowState[]{WindowState.NORMAL,WindowState.MINIMIZED,WindowState.MAXIMIZED}));
+ private static final Set defaultWindowStates =
Collections.unmodifiableSet(Tools.toSet(new
WindowState[]{WindowState.NORMAL,WindowState.MINIMIZED,WindowState.MAXIMIZED}));
/** . */
private final FacesContext faces;
- public JSFPortalContext(FacesContext faces)
+ /** . */
+ private final UIPortlet portlet;
+
+ /** . */
+ private Set modes;
+
+ /** . */
+ private Set windowStates;
+
+ public JSFPortalContext(FacesContext faces, UIPortlet portlet)
{
this.faces = faces;
+ this.portlet = portlet;
}
public Set getWindowStates()
{
+ if (windowStates == null)
+ {
+ Set tmp = portlet.getSupportedWindowStates();
+ if (tmp != null)
+ {
+ windowStates = new HashSet(tmp.size());
+ for (Iterator i = tmp.iterator();i.hasNext();)
+ {
+ String windowStateName = (String)i.next();
+ WindowState windowState = WindowState.create(windowStateName);
+ windowStates.add(windowState);
+ }
+ }
+ else
+ {
+ windowStates = defaultWindowStates;
+ }
+ }
return windowStates;
}
public Set getModes()
{
+ if (modes == null)
+ {
+ Set tmp = portlet.getSupportedModes();
+ if (tmp != null)
+ {
+ modes = new HashSet(tmp.size());
+ for (Iterator i = tmp.iterator();i.hasNext();)
+ {
+ String modeName = (String)i.next();
+ Mode windowState = Mode.create(modeName);
+ modes.add(windowState);
+ }
+ }
+ else
+ {
+ modes = defaultModes;
+ }
+ }
return modes;
}
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletActionEvent.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletActionEvent.java 2007-03-06
14:51:39 UTC (rev 6551)
+++
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletActionEvent.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -46,12 +46,30 @@
/** . */
private final PortletParameters interactionState;
- public PortletActionEvent(UIComponent uiComponent, PortletParameters
interactionState)
+ /** . */
+ private Mode mode;
+
+ /** . */
+ private WindowState windowState;
+
+ PortletActionEvent(UIComponent uiComponent, PortletParameters interactionState, Mode
mode, WindowState windowState)
{
super(uiComponent);
//
+ if (mode == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (windowState == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
this.interactionState = interactionState;
+ this.mode = mode;
+ this.windowState = windowState;
}
public Map getParameterMap()
@@ -59,6 +77,34 @@
return interactionState;
}
+ public String getMode()
+ {
+ return mode.toString();
+ }
+
+ public void setMode(String mode)
+ {
+ if (mode == null)
+ {
+ throw new IllegalArgumentException("No mode provided");
+ }
+ this.mode = Mode.create(mode);
+ }
+
+ public String getWindowState()
+ {
+ return windowState.toString();
+ }
+
+ public void setWindowState(String windowState)
+ {
+ if (mode == null)
+ {
+ throw new IllegalArgumentException("No window state provided");
+ }
+ this.windowState = WindowState.create(windowState);
+ }
+
void execute(FacesContext faces)
{
UIPortlet uiportlet = (UIPortlet)getComponent();
@@ -74,11 +120,25 @@
//
try
{
- PortletInvocationResponse pir = invocation.action(instance, Mode.VIEW,
WindowState.NORMAL, new PortletParametersStateString(interactionState));
+ PortletInvocationResponse pir = invocation.action(instance, mode, windowState,
new PortletParametersStateString(interactionState));
if (pir instanceof RenderResponse)
{
RenderResponse render = (RenderResponse)pir;
-
uiportlet.setNavState(((PortletParametersStateString)render.getNavigationalState()).getParameters());
+
+ //
+
uiportlet.setInternalNavState(((PortletParametersStateString)render.getNavigationalState()).getParameters());
+
+ //
+ if (render.getWindowState() != null)
+ {
+ uiportlet.setInternalWindowState(render.getWindowState());
+ }
+
+ //
+ if (render.getMode() != null)
+ {
+ uiportlet.setInternalMode(render.getMode());
+ }
}
}
catch (PortletInvokerException e)
Added: trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletHandler.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletHandler.java
(rev 0)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletHandler.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * 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.faces;
+
+import com.sun.facelets.tag.jsf.ComponentHandler;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.FaceletContext;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+
+import org.jboss.portal.common.util.Tools;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletHandler extends ComponentHandler
+{
+ public PortletHandler(ComponentConfig config)
+ {
+ super(config);
+ }
+
+
+ protected MetaRuleset createMetaRuleset(Class type)
+ {
+ MetaRuleset mr = super.createMetaRuleset(type);
+
+ //
+ mr.addRule(new MetaRule()
+ {
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta)
+ {
+ if ("supportedModes".equals(name))
+ {
+ if (attribute.isLiteral())
+ {
+ String s = attribute.getValue();
+ PropertyEditor editor =
PropertyEditorManager.findEditor(String[].class);
+ editor.setAsText(s);
+ String[] values = (String[])editor.getValue();
+ final Set set = Tools.toSet(values);
+ return new Metadata()
+ {
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ UIPortlet portlet = (UIPortlet)instance;
+ portlet.setSupportedModes(set);
+ }
+ };
+ }
+ }
+ if ("supportedWindowStates".equals(name))
+ {
+ if (attribute.isLiteral())
+ {
+ String s = attribute.getValue();
+ PropertyEditor editor =
PropertyEditorManager.findEditor(String[].class);
+ editor.setAsText(s);
+ String[] values = (String[])editor.getValue();
+ final Set set = Tools.toSet(values);
+ return new Metadata()
+ {
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ UIPortlet portlet = (UIPortlet)instance;
+ portlet.setSupportedWindowStates(set);
+ }
+ };
+ }
+ }
+ return null;
+ }
+ });
+
+ return mr;
+ }
+}
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletRenderEvent.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletRenderEvent.java 2007-03-06
14:51:39 UTC (rev 6551)
+++
trunk/core-admin/src/main/org/jboss/portal/core/faces/PortletRenderEvent.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -23,6 +23,8 @@
package org.jboss.portal.core.faces;
import org.jboss.portal.portlet.PortletParameters;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -38,12 +40,20 @@
/** . */
private final PortletParameters navState;
- public PortletRenderEvent(UIComponent uiComponent, PortletParameters navState)
+ /** . */
+ private Mode mode;
+
+ /** . */
+ private WindowState windowState;
+
+ public PortletRenderEvent(UIComponent uiComponent, PortletParameters navState, Mode
mode, WindowState windowState)
{
super(uiComponent);
//
this.navState = navState;
+ this.mode = mode;
+ this.windowState = windowState;
}
public Map getParameterMap()
@@ -51,9 +61,42 @@
return navState;
}
+ public String getMode()
+ {
+ return mode != null ? mode.toString() : null;
+ }
+
+ public void setMode(String mode)
+ {
+ this.mode = mode != null ? Mode.create(mode) : null;
+ }
+
+ public String getWindowState()
+ {
+ return windowState != null ? windowState.toString() : null;
+ }
+
+ public void setWindowState(String windowState)
+ {
+ this.windowState = windowState != null ? WindowState.create(windowState) : null;
+ }
+
void execute(FacesContext faces)
{
UIPortlet uiportlet = (UIPortlet)getComponent();
- uiportlet.setNavState(navState);
+ uiportlet.setInternalNavState(navState);
+
+ //
+ if (windowState != null)
+ {
+
+ uiportlet.setInternalWindowState(windowState);
+ }
+
+ //
+ if (mode != null)
+ {
+ uiportlet.setInternalMode(mode);
+ }
}
}
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-06
14:51:39 UTC (rev 6551)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-06
16:26:19 UTC (rev 6552)
@@ -46,6 +46,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -58,11 +59,29 @@
private String instanceId;
/** . */
- private MethodBinding portletListener = null;
+ private MethodBinding portletListener;
/** . */
- private PortletParameters navState;
+ private Set supportedWindowStates;
+ /** . */
+ private Set supportedModes;
+
+ /** . */
+ private String initialWindowState;
+
+ /** . */
+ private String initialMode;
+
+ /** . */
+ private PortletParameters internalNavState;
+
+ /** . */
+ private WindowState internalWindowState;
+
+ /** . */
+ private Mode internalMode;
+
public String getInstanceId()
{
if (instanceId != null)
@@ -86,8 +105,148 @@
this.instanceId = instanceId;
}
- void setNavState(PortletParameters navState)
+ public Set getSupportedModes()
{
+ if (supportedModes != null)
+ {
+ return supportedModes;
+ }
+
+ //
+ ValueBinding vb = getValueBinding("supportedModes");
+ if (vb != null)
+ {
+ return (Set)vb.getValue(getFacesContext());
+ }
+
+ //
+ return null;
+ }
+
+ public void setSupportedModes(Set supportedModes)
+ {
+ this.supportedModes = supportedModes;
+ }
+
+ public Set getSupportedWindowStates()
+ {
+ if (supportedWindowStates != null)
+ {
+ return supportedWindowStates;
+ }
+
+ //
+ ValueBinding vb = getValueBinding("supportedWindowStates");
+ if (vb != null)
+ {
+ return (Set)vb.getValue(getFacesContext());
+ }
+
+ //
+ return null;
+ }
+
+ public void setSupportedWindowStates(Set supportedWindowStates)
+ {
+ this.supportedWindowStates = supportedWindowStates;
+ }
+
+ public String getInitialWindowState()
+ {
+ if (initialWindowState != null)
+ {
+ return initialWindowState;
+ }
+
+ //
+ ValueBinding vb = getValueBinding("initialWindowState");
+ if (vb != null)
+ {
+ return (String)vb.getValue(getFacesContext());
+ }
+
+ //
+ return null;
+ }
+
+ public void setInitialWindowState(String initialWindowState)
+ {
+ this.initialWindowState = initialWindowState;
+ }
+
+ public String getInitialMode()
+ {
+ if (initialMode != null)
+ {
+ return initialMode;
+ }
+
+ //
+ ValueBinding vb = getValueBinding("initialMode");
+ if (vb != null)
+ {
+ return (String)vb.getValue(getFacesContext());
+ }
+
+ //
+ return null;
+ }
+
+ public void setInitialMode(String initialMode)
+ {
+ this.initialMode = initialMode;
+ }
+
+ WindowState getInternalWindowState()
+ {
+ if (internalWindowState == null)
+ {
+ if (initialWindowState != null)
+ {
+ return WindowState.create(initialWindowState);
+ }
+ else
+ {
+ return WindowState.NORMAL;
+ }
+ }
+ else
+ {
+ return internalWindowState;
+ }
+ }
+
+ void setInternalWindowState(WindowState windowState)
+ {
+ this.internalWindowState = windowState;
+ }
+
+ Mode getInternalMode()
+ {
+ if (internalMode == null)
+ {
+ if (initialMode != null)
+ {
+ return Mode.create(initialMode);
+ }
+ else
+ {
+ return Mode.VIEW;
+ }
+ }
+ else
+ {
+ return internalMode;
+ }
+ }
+
+ void setInternalMode(Mode mode)
+ {
+ this.internalMode = mode;
+ }
+
+ void setInternalNavState(PortletParameters navState)
+ {
ValueBinding vb = getValueBinding("renderParameters");
if (vb != null)
{
@@ -97,11 +256,11 @@
}
else
{
- this.navState = navState;
+ this.internalNavState = navState;
}
}
- PortletParameters getNavState()
+ PortletParameters getInternalNavState()
{
ValueBinding vb = getValueBinding("renderParameters");
if (vb != null)
@@ -111,7 +270,7 @@
}
else
{
- return navState;
+ return internalNavState;
}
}
@@ -161,17 +320,18 @@
public Object saveState(FacesContext faces)
{
String opaqueValue = null;
- if (navState != null)
+ if (internalNavState != null)
{
- opaqueValue = new PortletParametersStateString(navState).getStringValue();
+ opaqueValue = new
PortletParametersStateString(internalNavState).getStringValue();
}
//
- Object values[] = new Object[4];
+ Object values[] = new Object[5];
values[0] = super.saveState(faces);
values[1] = instanceId;
values[2] = opaqueValue;
values[3] = saveAttachedState(faces, portletListener);
+ values[4] = supportedModes;
return values;
}
@@ -183,8 +343,9 @@
//
instanceId = (String)values[1];
- navState = serializedNavState != null ? new
PortletParametersStateString(serializedNavState).getParameters() : null;
+ internalNavState = serializedNavState != null ? new
PortletParametersStateString(serializedNavState).getParameters() : null;
portletListener = (MethodBinding)restoreAttachedState(faces, values[3]);
+ supportedModes = (Set)values[4];
}
public void decode(FacesContext faces)
@@ -215,17 +376,35 @@
// Decode the request
PortletRequestDecoder decoder = new PortletRequestDecoder();
decoder.decode(portletParams, null);
+ Mode mode = decoder.getMode();
+ WindowState windowState = decoder.getWindowState();
//
switch (decoder.getType())
{
case PortletRequestDecoder.RENDER_TYPE:
- PortletRenderEvent prevent = new PortletRenderEvent(this,
((PortletParametersStateString)decoder.getNavigationalState()).getParameters());
+ PortletRenderEvent prevent = new PortletRenderEvent(
+ this,
+
((PortletParametersStateString)decoder.getNavigationalState()).getParameters(),
+ mode,
+ windowState);
prevent.setPhaseId(PhaseId.INVOKE_APPLICATION);
queueEvent(prevent);
break;
case PortletRequestDecoder.ACTION_TYPE:
- PortletActionEvent paevent = new PortletActionEvent(this,
((PortletParametersStateString)decoder.getInteractionState()).getParameters());
+ if (mode == null)
+ {
+ mode = getInternalMode();
+ }
+ if (windowState == null)
+ {
+ windowState = getInternalWindowState();
+ }
+ PortletActionEvent paevent = new PortletActionEvent(
+ this,
+
((PortletParametersStateString)decoder.getInteractionState()).getParameters(),
+ mode,
+ windowState);
paevent.setPhaseId(PhaseId.INVOKE_APPLICATION);
queueEvent(paevent);
break;
@@ -257,14 +436,11 @@
//
try
{
- PortletParameters navState = getNavState();
-
- //
PortletInvocationResponse pir = invocation.render(
instance,
- Mode.VIEW,
- WindowState.NORMAL,
- navState);
+ getInternalMode(),
+ getInternalWindowState(),
+ getInternalNavState());
//
if (pir instanceof FragmentResponse)
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-06
14:51:39 UTC (rev 6551)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-06
16:26:19 UTC (rev 6552)
@@ -102,7 +102,11 @@
<div>
<jbp:portlet
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
- actionListener="#{portalobjectmgr.processEvent}"/>
+ actionListener="#{portalobjectmgr.processEvent}"
+ supportedModes="view"
+ supportedWindowStates="normal"
+ initialMode="view"
+ initialWindowState="normal"/>
</div>
</ui:define>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portal.taglib.xml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portal.taglib.xml 2007-03-06
14:51:39 UTC (rev 6551)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/portal.taglib.xml 2007-03-06
16:26:19 UTC (rev 6552)
@@ -14,6 +14,7 @@
<component>
<component-type>org.jboss.portal.core.Portlet</component-type>
<renderer-type>default</renderer-type>
+
<handler-class>org.jboss.portal.core.faces.PortletHandler</handler-class>
</component>
</tag>
</facelet-taglib>
\ No newline at end of file