ca.qc.cegepoutaouais.tge.pige.client.ClientApp.java Source code

Java tutorial

Introduction

Here is the source code for ca.qc.cegepoutaouais.tge.pige.client.ClientApp.java

Source

/*
 * Copyright 2010, 2011 Renaud Brub
 *
 * This file is part of PIGE.
 *
 * PIGE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PIGE 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PIGE.  If not, see <http://www.gnu.org/licenses/>.
 */
package ca.qc.cegepoutaouais.tge.pige.client;

import ca.qc.cegepoutaouais.tge.pige.client.ui.AppEvents;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.HelpController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.UserManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.CreateLoanController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.ViewMyLoansController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.MessagesController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.NewLoanController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.RoleManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.LoanManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.AppController;
import ca.qc.cegepoutaouais.tge.pige.client.services.LoginService;
import ca.qc.cegepoutaouais.tge.pige.client.services.LoginServiceAsync;
import ca.qc.cegepoutaouais.tge.pige.client.services.ManagementService;
import ca.qc.cegepoutaouais.tge.pige.client.services.ManagementServiceAsync;
import ca.qc.cegepoutaouais.tge.pige.client.services.UserService;
import ca.qc.cegepoutaouais.tge.pige.client.services.UserServiceAsync;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.CategoryManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.InventoryManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.MaintenanceManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.ManagementController;
import ca.qc.cegepoutaouais.tge.pige.client.ui.controller.MessageManagementController;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.util.Theme;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Cookies;

/**
 * Point d'entr du module client de Google Web Toolkit pour PIGE.
 * Ce module est excut  chaque nouveau chargement et  chaque rafrachissement
 * du site Web de PIGE.
 *
 * @author Renaud Brub
 */
public class ClientApp implements EntryPoint {

    /** Contient la rfrence sur l'instance unique de l'application. */
    private static ClientApp app = null;

    /**
     * Mthode statique qui retourne la rfrence sur l'instance unique de
     * l'application.
     *
     * @return rfrence sur l'instance de l'application.
     */
    public static ClientApp getApp() {
        if (app == null) {
            throw new RuntimeException("L'application n'est pas charge! " + "(app == null)");
        }
        return ClientApp.app;
    }

    /**
     * Constructeur.
     */
    @SuppressWarnings("LeakingThisInConstructor")
    public ClientApp() {
        ClientApp.app = this;
    }

    /**
     * Point d'entr du module.
     */
    @Override
    public void onModuleLoad() {

        GXT.setDefaultTheme(Theme.BLUE, true);

        // Crer et enregistrer les services RPC.
        LoginServiceAsync loginService = (LoginServiceAsync) GWT.create(LoginService.class);
        UserServiceAsync userService = (UserServiceAsync) GWT.create(UserService.class);
        ManagementServiceAsync managementService = (ManagementServiceAsync) GWT.create(ManagementService.class);
        Registry.register(PIGE.LOGIN_SERVICE, loginService);
        Registry.register(PIGE.USER_SERVICE, userService);
        Registry.register(PIGE.MANAGEMENT_SERVICE, managementService);

        String jSessionId = Cookies.getCookie(PIGE.SESSION_COOKIE);
        Registry.register(PIGE.SESSION_COOKIE, jSessionId);

        initializeApp();
    }

    private void initializeApp() {

        /**
         * Instancier les contrleurs de l'application et gnrer l'vnement
         * amenant  la bote d'authentification.
         */
        Dispatcher dispatcher = Dispatcher.get();
        dispatcher.addController(new AppController());
        dispatcher.addController(new MessagesController());
        dispatcher.addController(new HelpController());
        dispatcher.addController(new MessageManagementController());
        dispatcher.addController(new RoleManagementController());
        dispatcher.addController(new UserManagementController());
        dispatcher.addController(new NewLoanController());
        dispatcher.addController(new ViewMyLoansController());
        dispatcher.addController(new LoanManagementController());
        dispatcher.addController(new CreateLoanController());
        dispatcher.addController(new ManagementController());
        dispatcher.addController(new InventoryManagementController());
        dispatcher.addController(new CategoryManagementController());
        dispatcher.addController(new MaintenanceManagementController());
        dispatcher.dispatch(AppEvents.LOGIN_VIEW_EVENT);

    }
}