001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client;
029
030import org.opencms.gwt.client.rpc.CmsLog;
031import org.opencms.gwt.client.ui.CmsNotification;
032import org.opencms.gwt.client.ui.css.I_CmsCellTableResources;
033import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
034import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
035import org.opencms.gwt.client.ui.css.I_CmsToolbarButtonLayoutBundle;
036import org.opencms.gwt.client.util.CmsClientStringUtil;
037
038import org.timepedia.exporter.client.ExporterUtil;
039
040import com.google.gwt.core.client.EntryPoint;
041import com.google.gwt.core.client.GWT;
042import com.google.gwt.event.shared.UmbrellaException;
043
044/**
045 * Handles exception handling and more for entry points.<p>
046 *
047 * @since 8.0.0
048 *
049 * @see org.opencms.gwt.CmsLogService
050 * @see org.opencms.gwt.shared.rpc.I_CmsLogService
051 * @see org.opencms.gwt.shared.rpc.I_CmsLogServiceAsync
052 */
053public abstract class A_CmsEntryPoint implements EntryPoint {
054
055    /** Flag which indicates whether initClasses() has already been called. */
056    private static boolean initializedClasses;
057
058    /**
059     * Default constructor.<p>
060     */
061    protected A_CmsEntryPoint() {
062
063        // just for subclassing
064    }
065
066    /**
067     * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
068     */
069    public void onModuleLoad() {
070
071        enableRemoteExceptionHandler();
072        CmsMediaQueryRuleManager.initialize();
073        I_CmsLayoutBundle bundle = I_CmsLayoutBundle.INSTANCE;
074        bundle.toolbarCss().ensureInjected();
075        bundle.buttonCss().ensureInjected();
076        bundle.contentEditorCss().ensureInjected();
077        bundle.contextmenuCss().ensureInjected();
078        bundle.dialogCss().ensureInjected();
079        bundle.errorDialogCss().ensureInjected();
080        bundle.notificationCss().ensureInjected();
081        bundle.dragdropCss().ensureInjected();
082        bundle.floatDecoratedPanelCss().ensureInjected();
083        bundle.generalCss().ensureInjected();
084        bundle.highlightCss().ensureInjected();
085        bundle.linkWarningCss().ensureInjected();
086        bundle.listItemWidgetCss().ensureInjected();
087        bundle.listTreeCss().ensureInjected();
088        bundle.stateCss().ensureInjected();
089        bundle.tabbedPanelCss().ensureInjected();
090        bundle.availabilityCss().ensureInjected();
091        bundle.fieldsetCss().ensureInjected();
092        bundle.resourceStateCss().ensureInjected();
093        bundle.dateBoxCss().ensureInjected();
094        bundle.selectAreaCss().ensureInjected();
095        bundle.singleLineItemCss().ensureInjected();
096        bundle.menuButtonCss().ensureInjected();
097        bundle.progressBarCss().ensureInjected();
098        bundle.propertiesCss().ensureInjected();
099        bundle.globalWidgetCss().ensureInjected();
100        bundle.categoryDialogCss().ensureInjected();
101        bundle.colorSelectorCss().ensureInjected();
102        bundle.filterSelectCss().ensureInjected();
103        ExporterUtil.exportAll();
104
105        I_CmsInputLayoutBundle.INSTANCE.inputCss().ensureInjected();
106
107        I_CmsToolbarButtonLayoutBundle.INSTANCE.toolbarButtonCss().ensureInjected();
108        I_CmsCellTableResources.INSTANCE.cellTableStyle().ensureInjected();
109        initClasses();
110    }
111
112    /**
113     * Enables client exception logging on the server.<p>
114     */
115    protected void enableRemoteExceptionHandler() {
116
117        if (GWT.isScript()) {
118            // In hosted mode, uncaught exceptions are easier to debug
119            return;
120        }
121
122        GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
123
124            /**
125             * @see com.google.gwt.core.client.GWT.UncaughtExceptionHandler#onUncaughtException(java.lang.Throwable)
126             */
127            public void onUncaughtException(Throwable t) {
128
129                if (t instanceof UmbrellaException) {
130                    t = ((UmbrellaException)t).getCauses().iterator().next();
131                }
132                String message = CmsClientStringUtil.getMessage(t);
133                CmsNotification.get().send(CmsNotification.Type.WARNING, message);
134                CmsLog.log(message + "\n" + CmsClientStringUtil.getStackTrace(t, "\n"));
135            }
136        });
137    }
138
139    /**
140     * Helper method for initializing the classes implementing {@link I_CmsHasInit}.<p>
141     *
142     * Calling this method more than once will have no effect.<p>
143     */
144    private void initClasses() {
145
146        if (!initializedClasses) {
147            I_CmsClassInitializer initializer = GWT.create(I_CmsClassInitializer.class);
148            initializer.initClasses();
149            initializedClasses = true;
150        }
151    }
152}