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.provider.forkawesome;
020
021import freemarker.core.ParseException;
022import freemarker.template.MalformedTemplateNameException;
023import freemarker.template.TemplateNotFoundException;
024import java.io.IOException;
025import org.jgrapes.core.Channel;
026import org.jgrapes.core.Event;
027import org.jgrapes.core.Manager;
028import org.jgrapes.core.annotation.Handler;
029import org.jgrapes.webconsole.base.ConsoleConnection;
030import org.jgrapes.webconsole.base.PageResourceProvider;
031import org.jgrapes.webconsole.base.events.AddPageResources;
032import org.jgrapes.webconsole.base.events.ConsoleReady;
033
034/**
035 * Provider for [Fork Awesome](https://github.com/ForkAwesome/Fork-Awesome).
036 */
037public class ForkAwesomeProvider extends PageResourceProvider {
038
039    /**
040     * Creates a new component with its channel set to the given 
041     * channel.
042     * 
043     * @param componentChannel the channel that the component's 
044     * handlers listen on by default and that 
045     * {@link Manager#fire(Event, Channel...)} sends the event to 
046     */
047    public ForkAwesomeProvider(Channel componentChannel) {
048        super(componentChannel);
049    }
050
051    /**
052     * On {@link ConsoleReady}, fire the appropriate {@link AddPageResources}.
053     *
054     * @param event the event
055     * @param connection the web console connection
056     * @throws TemplateNotFoundException the template not found exception
057     * @throws MalformedTemplateNameException the malformed template name exception
058     * @throws ParseException the parse exception
059     * @throws IOException Signals that an I/O exception has occurred.
060     */
061    @Handler(priority = 100)
062    public void onConsoleReady(ConsoleReady event, ConsoleConnection connection)
063            throws TemplateNotFoundException, MalformedTemplateNameException,
064            ParseException, IOException {
065        String minExt = event.renderSupport()
066            .useMinifiedResources() ? ".min" : "";
067        connection.respond(new AddPageResources()
068            .addCss(event.renderSupport().pageResource(
069                "fork-awesome/css/fork-awesome" + minExt + ".css")));
070    }
071}