001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.faces.component.portlet;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.WindowState;
026: import org.jboss.portal.portlet.Portlet;
027: import org.jboss.portal.portlet.PortletInvokerException;
028: import org.jboss.portal.portlet.PortletParameters;
029: import org.jboss.portal.portlet.PortletParametersStateString;
030: import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
031: import org.jboss.portal.portlet.invocation.response.RenderResponse;
032:
033: import javax.faces.component.UIComponent;
034: import javax.faces.context.FacesContext;
035: import java.util.Map;
036:
037: /**
038: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
039: * @version $Revision: 8784 $
040: */
041: public class PortletActionEvent extends PortletEvent {
042:
043: /** . */
044: private final PortletParameters interactionState;
045:
046: /** . */
047: private Mode mode;
048:
049: /** . */
050: private WindowState windowState;
051:
052: PortletActionEvent(UIComponent uiComponent,
053: PortletParameters interactionState, Mode mode,
054: WindowState windowState) {
055: super (uiComponent);
056:
057: //
058: if (mode == null) {
059: throw new IllegalArgumentException();
060: }
061: if (windowState == null) {
062: throw new IllegalArgumentException();
063: }
064:
065: //
066: this .interactionState = interactionState;
067: this .mode = mode;
068: this .windowState = windowState;
069: }
070:
071: public Map getParameterMap() {
072: return interactionState;
073: }
074:
075: public String getMode() {
076: return mode.toString();
077: }
078:
079: public void setMode(String mode) {
080: if (mode == null) {
081: throw new IllegalArgumentException("No mode provided");
082: }
083: this .mode = Mode.create(mode);
084: }
085:
086: public String getWindowState() {
087: return windowState.toString();
088: }
089:
090: public void setWindowState(String windowState) {
091: if (mode == null) {
092: throw new IllegalArgumentException(
093: "No window state provided");
094: }
095: this .windowState = WindowState.create(windowState);
096: }
097:
098: void execute(FacesContext faces) {
099: UIPortlet uiportlet = (UIPortlet) getComponent();
100:
101: // Get portlet
102: Portlet portlet = uiportlet.getPortlet();
103:
104: //
105: JSFInvocation invocation = new JSFInvocation(faces, uiportlet);
106:
107: //
108: try {
109: PortletInvocationResponse pir = invocation.action(portlet,
110: mode, windowState,
111: new PortletParametersStateString(interactionState));
112: if (pir instanceof RenderResponse) {
113: RenderResponse render = (RenderResponse) pir;
114:
115: //
116: uiportlet
117: .setInternalNavState(((PortletParametersStateString) render
118: .getNavigationalState())
119: .getParameters());
120:
121: //
122: if (render.getWindowState() != null) {
123: uiportlet.setInternalWindowState(render
124: .getWindowState());
125: }
126:
127: //
128: if (render.getMode() != null) {
129: uiportlet.setInternalMode(render.getMode());
130: }
131: }
132: } catch (PortletInvokerException e) {
133: e.printStackTrace();
134: }
135: }
136: }
|