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 044import elemental2.dom.DomGlobal; 045import jsinterop.base.JsPropertyMap; 046 047/** 048 * Handles exception handling and more for entry points.<p> 049 * 050 * @since 8.0.0 051 * 052 * @see org.opencms.gwt.CmsLogService 053 * @see org.opencms.gwt.shared.rpc.I_CmsLogService 054 * @see org.opencms.gwt.shared.rpc.I_CmsLogServiceAsync 055 */ 056public abstract class A_CmsEntryPoint implements EntryPoint { 057 058 /** Flag which indicates whether initClasses() has already been called. */ 059 private static boolean initializedClasses; 060 061 /** 062 * Default constructor.<p> 063 */ 064 protected A_CmsEntryPoint() { 065 066 // just for subclassing 067 } 068 069 /** 070 * @see com.google.gwt.core.client.EntryPoint#onModuleLoad() 071 */ 072 public void onModuleLoad() { 073 074 enableRemoteExceptionHandler(); 075 CmsMediaQueryRuleManager.initialize(); 076 I_CmsLayoutBundle bundle = I_CmsLayoutBundle.INSTANCE; 077 bundle.toolbarCss().ensureInjected(); 078 bundle.buttonCss().ensureInjected(); 079 bundle.contentEditorCss().ensureInjected(); 080 bundle.contextmenuCss().ensureInjected(); 081 bundle.dialogCss().ensureInjected(); 082 bundle.errorDialogCss().ensureInjected(); 083 bundle.notificationCss().ensureInjected(); 084 bundle.dragdropCss().ensureInjected(); 085 bundle.floatDecoratedPanelCss().ensureInjected(); 086 bundle.generalCss().ensureInjected(); 087 bundle.highlightCss().ensureInjected(); 088 bundle.linkWarningCss().ensureInjected(); 089 bundle.listItemWidgetCss().ensureInjected(); 090 bundle.listTreeCss().ensureInjected(); 091 bundle.stateCss().ensureInjected(); 092 bundle.tabbedPanelCss().ensureInjected(); 093 bundle.availabilityCss().ensureInjected(); 094 bundle.fieldsetCss().ensureInjected(); 095 bundle.resourceStateCss().ensureInjected(); 096 bundle.dateBoxCss().ensureInjected(); 097 bundle.selectAreaCss().ensureInjected(); 098 bundle.singleLineItemCss().ensureInjected(); 099 bundle.menuButtonCss().ensureInjected(); 100 bundle.progressBarCss().ensureInjected(); 101 bundle.propertiesCss().ensureInjected(); 102 bundle.globalWidgetCss().ensureInjected(); 103 bundle.categoryDialogCss().ensureInjected(); 104 bundle.colorSelectorCss().ensureInjected(); 105 bundle.filterSelectCss().ensureInjected(); 106 ExporterUtil.exportAll(); 107 108 I_CmsInputLayoutBundle.INSTANCE.inputCss().ensureInjected(); 109 110 I_CmsToolbarButtonLayoutBundle.INSTANCE.toolbarButtonCss().ensureInjected(); 111 I_CmsCellTableResources.INSTANCE.cellTableStyle().ensureInjected(); 112 ((JsPropertyMap<Object>)DomGlobal.window).set("cmsJsFunctions", CmsJsFunctions.INSTANCE); 113 initClasses(); 114 } 115 116 /** 117 * Enables client exception logging on the server.<p> 118 */ 119 protected void enableRemoteExceptionHandler() { 120 121 if (GWT.isScript()) { 122 // In hosted mode, uncaught exceptions are easier to debug 123 return; 124 } 125 126 GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { 127 128 /** 129 * @see com.google.gwt.core.client.GWT.UncaughtExceptionHandler#onUncaughtException(java.lang.Throwable) 130 */ 131 public void onUncaughtException(Throwable t) { 132 133 if (t instanceof UmbrellaException) { 134 t = ((UmbrellaException)t).getCauses().iterator().next(); 135 } 136 String message = CmsClientStringUtil.getMessage(t); 137 CmsNotification.get().send(CmsNotification.Type.WARNING, message); 138 CmsLog.log(message + "\n" + CmsClientStringUtil.getStackTrace(t, "\n")); 139 } 140 }); 141 } 142 143 /** 144 * Helper method for initializing the classes implementing {@link I_CmsHasInit}.<p> 145 * 146 * Calling this method more than once will have no effect.<p> 147 */ 148 private void initClasses() { 149 150 if (!initializedClasses) { 151 I_CmsClassInitializer initializer = GWT.create(I_CmsClassInitializer.class); 152 initializer.initClasses(); 153 initializedClasses = true; 154 } 155 } 156}