com.ephesoft.dcma.gwt.core.client.DCMAEntryPoint.java Source code

Java tutorial

Introduction

Here is the source code for com.ephesoft.dcma.gwt.core.client.DCMAEntryPoint.java

Source

/********************************************************************************* 
* Ephesoft is a Intelligent Document Capture and Mailroom Automation program 
* developed by Ephesoft, Inc. Copyright (C) 2010-2012 Ephesoft Inc. 
* 
* This program is free software; you can redistribute it and/or modify it under 
* the terms of the GNU Affero General Public License version 3 as published by the 
* Free Software Foundation with the addition of the following permission added 
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 
* IN WHICH THE COPYRIGHT IS OWNED BY EPHESOFT, EPHESOFT DISCLAIMS THE WARRANTY 
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 
* 
* This program 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 Affero General Public License for more 
* details. 
* 
* You should have received a copy of the GNU Affero General Public License along with 
* this program; if not, see http://www.gnu.org/licenses or write to the Free 
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
* 02110-1301 USA. 
* 
* You can contact Ephesoft, Inc. headquarters at 111 Academy Way, 
* Irvine, CA 92617, USA. or at email address info@ephesoft.com. 
* 
* The interactive user interfaces in modified source and object code versions 
* of this program must display Appropriate Legal Notices, as required under 
* Section 5 of the GNU Affero General Public License version 3. 
* 
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, 
* these Appropriate Legal Notices must retain the display of the "Ephesoft" logo. 
* If the display of the logo is not reasonably feasible for 
* technical reasons, the Appropriate Legal Notices must display the words 
* "Powered by Ephesoft". 
********************************************************************************/

package com.ephesoft.dcma.gwt.core.client;

import com.ephesoft.dcma.gwt.core.client.event.HelpClickEvent;
import com.ephesoft.dcma.gwt.core.client.event.HelpClickEventHandler;
import com.ephesoft.dcma.gwt.core.client.event.SignoutEvent;
import com.ephesoft.dcma.gwt.core.client.event.SignoutEventHandler;
import com.ephesoft.dcma.gwt.core.client.i18n.LocaleCommonConstants;
import com.ephesoft.dcma.gwt.core.client.i18n.LocaleDictionary;
import com.ephesoft.dcma.gwt.core.client.i18n.LocaleInfo;
import com.ephesoft.dcma.gwt.core.shared.ConfirmationDialogUtil;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.CssResource.NotStrict;
import com.google.gwt.user.client.Window;

public abstract class DCMAEntryPoint<R extends DCMARemoteServiceAsync> implements EntryPoint {

    interface GlobalResources extends ClientBundle {

        @NotStrict
        @Source("global.css")
        CssResource css();
    }

    protected R rpcService;

    protected HandlerManager eventBus;

    @Override
    public void onModuleLoad() {
        GWT.<GlobalResources>create(GlobalResources.class).css().ensureInjected();

        this.eventBus = new HandlerManager(null);
        this.rpcService = createRpcService();

        eventBus.addHandler(SignoutEvent.type, new SignoutEventHandler() {

            @Override
            public void onSignout(SignoutEvent event) {
                rpcService.logout(Window.getTitle(), new EphesoftAsyncCallback<Void>() {

                    @Override
                    public void onSuccess(Void voids) {
                        Window.Location.assign(GWT.getHostPageBaseURL() + getHomePage());
                    }

                    @Override
                    public void customFailure(Throwable arg0) {
                        /*
                         * On Failure
                         */
                    }
                });
            }
        });

        eventBus.addHandler(HelpClickEvent.type, new HelpClickEventHandler() {

            @Override
            public void onHelpClicked(HelpClickEvent event) {
                rpcService.getHelpUrl(new EphesoftAsyncCallback<String>() {

                    @Override
                    public void onSuccess(String url) {
                        // opening the help url in new tab
                        Window.open(url, "_blank", null);
                    }

                    @Override
                    public void customFailure(Throwable arg0) {
                        ConfirmationDialogUtil.showConfirmationDialog(
                                LocaleDictionary.get()
                                        .getConstantValue(LocaleCommonConstants.HELP_URK_ERROR_MESSAGE),
                                LocaleDictionary.get().getConstantValue(LocaleCommonConstants.ERROR_TITLE), true);

                    }
                });
            }
        });

        preprocess();
    }

    private void initialize(String locale) {
        LocaleDictionary.create(createLocaleInfo(locale));
        this.rpcService.initRemoteService(new EphesoftAsyncCallback<Void>() {

            @Override
            public void customFailure(Throwable throwable) {
                ConfirmationDialogUtil.showConfirmationDialogError(
                        LocaleDictionary.get().getConstantValue(throwable.getMessage().replace('.', '_')));
            }

            @Override
            public void onSuccess(Void arg0) {
                // defineBridgeMethod();
                onLoad();
            }
        });
    }

    private void preprocess() {
        this.rpcService.getUserName(new EphesoftAsyncCallback<String>() {

            @Override
            public void customFailure(Throwable arg0) {
                // On Failure
            }

            @Override
            public void onSuccess(String userName) {

                rpcService.getLocale(new EphesoftAsyncCallback<String>() {

                    @Override
                    public void customFailure(Throwable throwable) {
                        initialize("");
                    }

                    @Override
                    public void onSuccess(String locale) {
                        initialize(locale);
                    }
                });
            }
        });
    }

    public HandlerManager getEventBus() {
        return eventBus;
    }

    public R getRpcService() {
        return rpcService;
    }

    public void onCloseWindow() {
        // Empty Method
        /*
         * rpcService.cleanup(new AsyncCallback<Void>() {
         * 
         * @Override public void onFailure(Throwable caught) {
         * 
         * On Failure
         * 
         * }
         * 
         * @Override public void onSuccess(Void arg0) {
         * 
         * On Success
         * 
         * } });
         */
    }

    public native void defineBridgeMethod() /*-{
                                            var _this = this;
                                            $wnd.onCloseWindow = function() {
                                            return _this.@com.ephesoft.dcma.gwt.core.client.DCMAEntryPoint::onCloseWindow()();
                                            }
                                            }-*/;

    public abstract void onLoad();

    public abstract R createRpcService();

    public abstract String getHomePage();

    public abstract LocaleInfo createLocaleInfo(String locale);

}