001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2017-2018 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.portal.base.events;
020
021import static org.jgrapes.portal.base.Portlet.RenderMode;
022
023import org.jgrapes.portal.base.RenderSupport;
024
025/**
026 * Sent to the portal (server) if an existing portlet instance 
027 * should be updated. The portal server usually responds with 
028 * a {@link RenderPortlet} event that has as payload the
029 * HTML that displays the portlet on the portal page.
030 * 
031 * ![Event Sequence](RenderPortletRequestSeq.svg)
032 * 
033 * The event's result must be set to `true` by the rendering portlet.
034 * 
035 * @startuml RenderPortletRequestSeq.svg
036 * hide footbox
037 * 
038 * Browser -> Portal: "renderPortletRequest"
039 * activate Portal
040 * Portal -> Portlet: RenderPortletRequest
041 * deactivate Portal
042 * activate Portlet
043 * Portlet -> Portal: RenderPortlet
044 * deactivate Portlet
045 * activate Portal
046 * Portal -> Browser: "renderPortlet"
047 * deactivate Portal
048 * 
049 * @enduml
050 */
051public class RenderPortletRequest extends RenderPortletRequestBase<Boolean> {
052
053    private final String portletId;
054    private final boolean foreground;
055
056    /**
057     * Creates a new request.
058     * 
059     * @param renderSupport the render support for generating the response
060     * @param portletId the portlet to be updated
061     * @param renderMode the requested mode
062     */
063    public RenderPortletRequest(RenderSupport renderSupport,
064            String portletId, RenderMode renderMode, boolean foreground) {
065        super(renderSupport, renderMode);
066        this.portletId = portletId;
067        this.foreground = foreground;
068    }
069
070    /**
071     * Returns the portlet id.
072     * 
073     * @return the portlet id
074     */
075    public String portletId() {
076        return portletId;
077    }
078
079    @Override
080    public boolean isForeground() {
081        return foreground;
082    }
083
084    /**
085     * Checks if the portlet has been rendered (i.e. the event has been
086     * handled).
087     *
088     * @return true, if successful
089     */
090    public boolean hasBeenRendered() {
091        return !currentResults().isEmpty() && currentResults().get(0);
092    }
093}