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 java.util.List;
022
023import org.jgrapes.portal.base.Portlet.RenderMode;
024import org.jgrapes.portal.base.RenderSupport;
025
026/**
027 * Sent to the portal (server) if an existing portlet instance 
028 * should be updated. The portal server usually responds with 
029 * a {@link RenderPortlet} event that has as payload the
030 * HTML that displays the portlet on the portal page.
031 * 
032 * ![Event Sequence](RenderPortletRequestSeq.svg)
033 * 
034 * The event's result must be set to `true` by the rendering portlet.
035 * 
036 * @startuml RenderPortletRequestSeq.svg
037 * hide footbox
038 * 
039 * Browser -> Portal: "renderPortletRequest"
040 * activate Portal
041 * Portal -> Portlet: RenderPortletRequest
042 * deactivate Portal
043 * activate Portlet
044 * Portlet -> Portal: RenderPortlet
045 * deactivate Portlet
046 * activate Portal
047 * Portal -> Browser: "renderPortlet"
048 * deactivate Portal
049 * 
050 * @enduml
051 */
052public class RenderPortletRequest extends RenderPortletRequestBase<Boolean> {
053
054    private final String portletId;
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 renderModes the render options
062     */
063    public RenderPortletRequest(RenderSupport renderSupport,
064            String portletId, List<RenderMode> renderModes) {
065        super(renderSupport, renderModes);
066        this.portletId = portletId;
067    }
068
069    /**
070     * Returns the portlet id.
071     * 
072     * @return the portlet id
073     */
074    public String portletId() {
075        return portletId;
076    }
077
078    @Override
079    public boolean isForeground() {
080        return renderModes().contains(RenderMode.Foreground);
081    }
082
083    /**
084     * Checks if the portlet has been rendered (i.e. the event has been
085     * handled).
086     *
087     * @return true, if successful
088     */
089    public boolean hasBeenRendered() {
090        return !currentResults().isEmpty() && currentResults().get(0);
091    }
092}