package votorola.a.web.gwt; // Copyright 2012-2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import com.google.gwt.core.client.*; import java.util.*; /** A modified entry point for modules whose execution depends on other application * modules. It need only be implemented by modules that require the deferred {@linkplain * #execute execute}() method. For this method to work, one of the top level modules of * the application (on which no other module depends) must call EntryPointS.U.{@linkplain * EntryPointS.U#execute() execute}() at the end of its own {@linkplain #onModuleLoad() * onModuleLoad}(). */ public interface EntryPointS extends EntryPoint, Scheduler.ScheduledCommand { // - E n t r y - P o i n t ------------------------------------------------------------ /** Called first during the load of any module M that declares an * entry-point in its declaration file M.gwt.xml, this * method (a) finalizes the {@linkplain GWTConfigCallback configuration} of any other modules * on which this one depends, and (b) ensures that any views are solidly placed that * might affect the position or size of already placed views, such as those of an * embedding page or those previously attached by other modules. This is to ensure * that the page content does not jitter from late attachments. Otherwise this * method depends as little as possible on other {@linkplain votorola.a application} * modules, as they might not be fully functional yet. * *

This method may also (c) {@linkplain EntryPointS.U#schedule(EntryPointS) * schedule} the invocation of the {@linkplain #execute() execute method}.

*/ public void onModuleLoad(); // - S c h e d u l e r . S c h e d u l e d - C o m m a n d ---------------------------- /** Called after all modules are loaded provided the call was previously {@linkplain * EntryPointS.U#schedule(EntryPointS) scheduled}. * * @see #onModuleLoad() */ public void execute(); // ==================================================================================== /** EntryPointS utilities. */ public static final class U { private U() {} private static ArrayList entryPointList = // nulled after execution new ArrayList( /*initial capacity*/8 ); // -------------------------------------------------------------------------------- /** Triggers execution of all modules that were previously {@linkplain * #schedule(EntryPointS) scheduled}. Actual execution is not necessarily * immediate, but may be further delayed. Call this method exactly once from the * top level module of the application (the module on which no other module * depends) at the end of its {@linkplain EntryPointS#onModuleLoad() * onModuleLoad}(). */ public static void execute() { if( entryPointList == null ) throw new IllegalStateException( "called twice" ); final ArrayList pList = entryPointList; entryPointList = null; // all modules executed, free the memory for( EntryPointS p: pList ) p.execute(); // immediately, no need for async execution yet } /** Schedules p.{@linkplain EntryPointS#execute() execute}() to be called after * all modules are loaded. */ public static void schedule( final EntryPointS p ) { assert entryPointList != null: "called before modules executed"; entryPointList.add( p ); } } }