org.cloud4gl.client.Cloud4gl.java Source code

Java tutorial

Introduction

Here is the source code for org.cloud4gl.client.Cloud4gl.java

Source

/*
 * Better places framework for  Gwt.
 *
 * Copyright (c) 2014, Rony George
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package org.cloud4gl.client;

import org.cloud4gl.client.event.MenuSelectionEventHandler;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TabBar;
import com.google.gwt.resources.client.TextResource;
import com.google.web.bindery.autobean.shared.AutoBean;
import com.google.web.bindery.autobean.shared.AutoBeanCodex;

/**
 * 
 * Entry point classes define <code>onModuleLoad()</code>.
 * 
 * @author georon
 * 
 */
public class Cloud4gl implements EntryPoint {

    private final AppConf appConf = initAppConf();

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        //create AppController passing in parameter AppConf
        AppController appController = new AppController(appConf);
        RootPanel.get("titlecell").getElement().setInnerText(appConf.getName());
        // Create a tab bar for the main menu which is integrated with the places framework
        final TabBar tbar = appController.getTabMenu();
        RootPanel.get("tabmenu").add(tbar);
        tbar.addSelectionHandler(new MenuSelectionEventHandler(appController));
        RootPanel.get("appmessage").setVisible(false);
        SimplePanel sPanel = new SimplePanel();
        RootPanel.get("maincontent").add(sPanel);
        appController.setContainer(sPanel);
        tbar.selectTab(0);

        appController.getHistoryHandler().handleCurrentHistory();

    }

    /**
     * Using the Autobean library of GWT, loads the application configuration
     * from a  json file into Autobeans.
     * 
     * The AppConf structure created has the application level 
     * configuration settings such as the default Place and app wide parameters,
     *  as well as a list of place configuration objects.
     * 
     * Each place gets a tab in the main tab bar, which acts as the main menu.
     * 
     * Each PlaceConf bean contains a list of activities and the default activity.
     * Optionally the list of activities can be mapped to a sub-menu on the
     * left navigation side bar.
     * 
     * @return AppConf
     */
    private AppConf initAppConf() {
        TextResource appconfigRes = Cloud4glResources.INSTANCE.getAppConfig();
        String appconfig = appconfigRes.getText();
        AppBeanFactory factory = GWT.create(AppBeanFactory.class);
        AutoBean<AppConf> bean = AutoBeanCodex.decode(factory, AppConf.class, appconfig);
        return bean.as();
    }

}