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.webconsole.base.events;
020
021import java.util.Set;
022import org.jgrapes.webconsole.base.AbstractConlet;
023import org.jgrapes.webconsole.base.Conlet.RenderMode;
024import org.jgrapes.webconsole.base.RenderSupport;
025
026/**
027 * Sent to the web console (server) if an existing web console component 
028 * instance should be updated. The web console server usually responds with 
029 * a {@link RenderConlet} event that has as payload the
030 * HTML that displays the web console component on the web console page.
031 * 
032 * ![Event Sequence](RenderConletRequestSeq.svg)
033 * 
034 * The event's result must be set to `true` by the rendering 
035 * web console component.
036 * 
037 * @startuml RenderConletRequestSeq.svg
038 * hide footbox
039 * 
040 * Browser -> WebConsole: "renderConletRequest"
041 * activate WebConsole
042 * WebConsole -> Conlet: RenderConletRequest
043 * deactivate WebConsole
044 * activate Conlet
045 * Conlet -> WebConsole: RenderConlet
046 * deactivate Conlet
047 * activate WebConsole
048 * WebConsole -> Browser: "renderConlet"
049 * deactivate WebConsole
050 * 
051 * @enduml
052 */
053public class RenderConletRequest
054        extends RenderConletRequestBase<Boolean> {
055
056    private final String conletId;
057
058    /**
059     * Creates a new request.
060     *
061     * @param renderSupport the render support for generating the response
062     * @param conletId the web console component to be updated
063     * @param renderModes the render options
064     */
065    public RenderConletRequest(RenderSupport renderSupport,
066            String conletId, Set<RenderMode> renderModes) {
067        super(renderSupport, renderModes);
068        this.conletId = conletId;
069    }
070
071    /**
072     * Return the web console component type.
073     * 
074     * @return the web console component type
075     */
076    public String conletType() {
077        return AbstractConlet.typeFromId(conletId);
078    }
079
080    /**
081     * Returns the web console component id.
082     * 
083     * @return the web console component id
084     */
085    public String conletId() {
086        return conletId;
087    }
088
089    /**
090     * Checks if the web console component has been rendered (i.e. the 
091     * event has been handled).
092     *
093     * @return true, if successful
094     */
095    public boolean hasBeenRendered() {
096        return !currentResults().isEmpty() && currentResults().get(0);
097    }
098}