WebApplication app = (WebApplication) def;
if (app.getDefinedInModule() == codeGenModule){
application = app;
// We create an internal run context item for the generated PlaceHistoryMapper
RunContextItem rci = new RunContextItem();
rci.setAutoCreated(true);
RunContextItemCollection rcic = contexts.get(rci.getContextImpl());
rci.setItemName("historyMapper");
rci.setDescription("This is the auto generated run context item that provides a handle to the application specific PlaceHistoryMapper for a web application.");
rci.setItemOrder(7);
rci.setUseClass(codeGenModule.getGenPackage() + ".generated.mvw.places." + app.getAppName() + "PlaceHistoryMapper");
rci.setConstruction("GWT.create(" + app.getAppName() + "PlaceHistoryMapper.class)");
rci.addImportThis("com.google.gwt.core.client.GWT");
rci.setDefinedInModule(app.getDefinedInModule());
if (rcic == null){
rcic = new RunContextItemCollection(rci.getContextImpl());
contexts.put(rci.getContextImpl(), rcic);
}
rcic.addItem(rci);
// Add the item to its module
rci.getDefinedInModule().addRunContextItem(rci);
}
}
else if (def instanceof Controller){
Controller controller = (Controller) def;
// controller.getDMO().addUsesRunContextItem("eventBus");
controllers.put(def.getCamelCaseName(), controller);
components.put(def.getCamelCaseName(), controller);
RunContextItem controllerRCI = null;
if (controller.isAddedToRunContext()){
// All Controllers run for the life of the application and so, are added to the run context
// so that they are created on start up
controllerRCI = new RunContextItem();
controllerRCI.setAutoCreated(true);
RunContextItemCollection rcic = contexts.get(controllerRCI.getContextImpl());
controllerRCI.setItemName(controller.getControllerName().getNameString() + "RCI");
controllerRCI.setDescription("The auto generated run context item for the " + controller.getControllerName());
if (controller.getSubpackage() == null)
controllerRCI.setUseClass(currentModule.getGenPackage() + ".extended." + controller.getControllerName());
else
controllerRCI.setUseClass(currentModule.getGenPackage() + ".extended." + controller.getSubpackage() + "." + controller.getControllerName());
if (controller.usesRunContext())
controllerRCI.setConstruction("new " + controller.getControllerName() + "(this)");
else
controllerRCI.setConstruction("new " + controller.getControllerName() + "()");
controllerRCI.setDefinedInModule(controller.getDefinedInModule());
if (controller.getItemOrder() != null)
controllerRCI.setItemOrder(controller.getItemOrder());
if (rcic == null){
rcic = new RunContextItemCollection(controllerRCI.getContextImpl());
contexts.put(controllerRCI.getContextImpl(), rcic);
}
rcic.addItem(controllerRCI);
// Add the item to its module
controllerRCI.getDefinedInModule().addRunContextItem(controllerRCI);
//DebugInfo.debug("\n" + rci.toOIF());
// Tell the controller its item
controller.setRunContextItem(controllerRCI);
// Add to all definitions so that references can be resolved
controllerRCI.setCamelCaseName(controllerRCI.getObjectName());
checkAndAdd(controllerRCI,allDefs);
}
if (controller.isCentralRPCErrorHandler()){
if (centralRpcErrorHandler != null){
ResultException ex = new ResultException();
ex.addError("Multiple controllers are specified as the central RPC error handler.");
ex.result.lastResult().moreMessages(centralRpcErrorHandler.getControllerName() + " in " + centralRpcErrorHandler.getDefinedInModule().getFile() + " at line " + centralRpcErrorHandler.getDefinedInModule().getLineNumber());
ex.result.lastResult().moreMessages(controller.getControllerName() + " in " + controller.getDefinedInModule().getFile() + " at line " + controller.getDefinedInModule().getLineNumber());
throw(ex);
}
centralRpcErrorHandler = controller;
}
if (controller.isCentralDMPErrorHandler()){
if (centralDmpErrorHandler != null){
ResultException ex = new ResultException();
ex.addError("Multiple controllers are specified as the central DMP error handler.");
ex.result.lastResult().moreMessages(centralDmpErrorHandler.getControllerName() + " in " + centralDmpErrorHandler.getDefinedInModule().getFile() + " at line " + centralDmpErrorHandler.getDefinedInModule().getLineNumber());
ex.result.lastResult().moreMessages(controller.getControllerName() + " in " + controller.getDefinedInModule().getFile() + " at line " + controller.getDefinedInModule().getLineNumber());
throw(ex);
}
centralDmpErrorHandler = controller;
}
if (controller.isCentralAsyncErrorHandler()){
if (centralAsyncErrorHandler != null){
ResultException ex = new ResultException();
ex.addError("Multiple controllers are specified as the central asynchronous code loading error handler.");
ex.result.lastResult().moreMessages(centralAsyncErrorHandler.getControllerName() + " in " + centralAsyncErrorHandler.getDefinedInModule().getFile() + " at line " + centralDmpErrorHandler.getDefinedInModule().getLineNumber());
ex.result.lastResult().moreMessages(controller.getControllerName() + " in " + controller.getDefinedInModule().getFile() + " at line " + controller.getDefinedInModule().getLineNumber());
throw(ex);
}
centralAsyncErrorHandler = controller;
centralAsyncErrorHandlerRCI = controllerRCI;
//
// // We will fill in the details of the predefined place holder context item - defined in the mvw module
// RunContextItemCollection rcic = contexts.get(controllerRCI.getContextImpl());
// RunContextItem rci = rcic.getItem("centralAsyncErrorHandler");
//
// // The construction is just the assignment of the controller to this item
// rci.setConstruction(controllerRCI.getItemName());
//
// int order = controllerRCI.getItemOrder() + 1;
// rci.setItemOrder(order);
}
}
else if (def instanceof Presenter){
Presenter presenter = (Presenter) def;
// presenter.getDMO().addUsesRunContextItem("eventBus");
presenters.put(def.getCamelCaseName(), presenter);
components.put(def.getCamelCaseName(), presenter);
// All Presenters are available for access from the run context. They are created on demand.
RunContextItem rci = new RunContextItem();
rci.setAutoCreated(true);
RunContextItemCollection rcic = contexts.get(rci.getContextImpl());
rci.setItemName(presenter.getPresenterName().getNameString() + "RCI");
rci.setDescription("The auto generated run context item for the " + presenter.getPresenterName());
if (presenter.getSubpackage() == null)
rci.setUseClass(currentModule.getGenPackage() + ".extended." + presenter.getPresenterName());
else
rci.setUseClass(currentModule.getGenPackage() + ".extended." + presenter.getSubpackage() + "." + presenter.getPresenterName());
if (presenter.usesRunContext()){
if (presenter.isCodeSplit())
rci.setConstruction("new " + presenter.getPresenterName() + "(thisContext)");
else
rci.setConstruction("new " + presenter.getPresenterName() + "(this)");
}
else
rci.setConstruction("new " + presenter.getPresenterName() + "()");
rci.setDefinedInModule(presenter.getDefinedInModule());
rci.setPresenter(presenter);
if (rcic == null){
rcic = new RunContextItemCollection(rci.getContextImpl());
contexts.put(rci.getContextImpl(), rcic);
}
rcic.addItem(rci);
// Add the item to its module
rci.getDefinedInModule().addRunContextItem(rci);
// We make it so that the presenter instance is created as required
rci.setCreateOnDemand(true);
rci.setSingleton(presenter.isSingleton());
// Tell the presenter its item
presenter.setRunContextItem(rci);
// Also add to our full set of definitions
allDefs.put(rci.getItemName(), rci);
}
else if (def instanceof Activity){
Activity activity = (Activity) def;
// if (activity.getHandlesEventHasValue())
// activity.getDMO().addUsesRunContextItem("eventBus");
// if (activity.getFiresEventHasValue())
// activity.getDMO().addUsesRunContextItem("eventBus");
activities.put(def.getCamelCaseName(), activity);
components.put(def.getCamelCaseName(), activity);
}
else if (def instanceof View){
View view = (View) def;
views.put(def.getCamelCaseName(), view);
if (view.requiresEventBus()){
view.getDMO().addUsesRunContextItem("eventBus");
}
// All Views are available for access from the run context. They are created on demand.
RunContextItem rci = new RunContextItem();
rci.setAutoCreated(true);
RunContextItemCollection rcic = contexts.get(rci.getContextImpl());
rci.setItemName(view.getViewName().getNameString() + "RCI");
rci.setDescription("The auto generated run context item for the " + view.getViewName());
if (view.getSubpackage() == null)
rci.setUseClass(currentModule.getGenPackage() + ".extended." + view.getViewName());
else
rci.setUseClass(currentModule.getGenPackage() + ".extended." + view.getSubpackage() + "." + view.getViewName());
if (view.getUsesRunContextItemHasValue()){
if (view.isCodeSplit())
rci.setConstruction("new " + view.getViewName() + "(presenter, thisContext)");
else
rci.setConstruction("new " + view.getViewName() + "(presenter, this)");
}
else
rci.setConstruction("new " + view.getViewName() + "(presenter)");
// // BIG NOTE: we don't specify the arguments to the constructor, this will depend on figuring
// // out if the component needs run context items. We determine this in the RunContextItem.
// rci.setConstruction("new " + view.getViewName());
// NOTE: in addition to setting the construction mechanism, we also set the view
// on the context item so that it knows how to create the on demand method that takes
// the View's presenter.
rci.setView(view);
rci.setDefinedInModule(view.getDefinedInModule());
if (rcic == null){
rcic = new RunContextItemCollection(rci.getContextImpl());
contexts.put(rci.getContextImpl(), rcic);
}
rcic.addItem(rci);
// Add the item to its module
rci.getDefinedInModule().addRunContextItem(rci);
// We make it so that the view instance is created as required
rci.setCreateOnDemand(true);
// rci.setTheOne(view.isTheOne());
// Tell the view its item
view.setRunContextItem(rci);
}
else if (def instanceof Event){
events.put(def.getCamelCaseName(), (Event) def);
}
else if (def instanceof Place){
places.put(def.getCamelCaseName(), (Place) def);
}
else if (def instanceof SubPlace){
subPlaces.put(def.getCamelCaseName(), (SubPlace) def);
}
else if (def instanceof EnumMappingGenerator){
enumGenerators.put(def.getCamelCaseName(), (EnumMappingGenerator) def);
}
else if (def instanceof RunContextItem){
RunContextItem rci = (RunContextItem) def;
RunContextItemCollection rcic = contexts.get(rci.getContextImpl());
if (rcic == null){
rcic = new RunContextItemCollection(rci.getContextImpl());
contexts.put(rci.getContextImpl(), rcic);
}
rcic.addItem(rci);
// Add the item to its module
rci.getDefinedInModule().addRunContextItem(rci);
}
else if (def instanceof I18NConfig){
I18NConfig i18n = (I18NConfig) def;
RunContextItemCollection rcic = contexts.get(i18n.getContextImpl());
if (rcic == null){
rcic = new RunContextItemCollection(i18n.getContextImpl());
contexts.put(i18n.getContextImpl(), rcic);
}
rcic.addItem(i18n);
// Add the item to its module
i18n.getDefinedInModule().addRunContextItem(i18n);
}
else if (def instanceof MenuBar){
MenuBar menu = (MenuBar) def;
menuBars.put(menu.getCamelCaseName(), menu);
menuElements.put(menu.getCamelCaseName(), menu);
}
else if (def instanceof SubMenu){
SubMenu menu = (SubMenu) def;
subMenus.put(menu.getCamelCaseName(), menu);
menuElements.put(menu.getCamelCaseName(), menu);
}
else if (def instanceof MenuItem){
MenuItem item = (MenuItem) def;
menuItems.put(item.getCamelCaseName(), item);
menuElements.put(item.getCamelCaseName(), item);
}
else if (def instanceof Separator){
Separator sep = (Separator) def;
separators.put(sep.getCamelCaseName(), sep);
menuElements.put(sep.getCamelCaseName(), sep);
}
else if (def instanceof ActionBinding){
ActionBinding action = (ActionBinding) def;
actions.put(action.getCamelCaseName(), action);
}
else if (def instanceof MenuImplementationConfig){
if (menuImplementation == null){
menuImplementation = (MenuImplementationConfig) def;
// The menu factory specified by the menu implementation is added
// as a run context item.
RunContextItem rci = new RunContextItem();
rci.setAutoCreated(true);
RunContextItemCollection rcic = contexts.get(rci.getContextImpl());
rci.setItemName("menuFactory");
rci.setDescription("The auto generated run context item for the generic menuFactory; this was created because a MenuImplementationConfig was provided by the " + menuImplementation.getDefinedInModule().getModuleName() + " module");
rci.setUseClass("org.dmd.mvw.client.mvwmenus.base.MvwMenuFactory");
rci.setItemOrder(16);
// We use the class specified in the menu implementation config to
// create the construction call.
rci.setConstruction("new " + menuImplementation.getUseClass() + "()");
rci.setDefinedInModule(menuImplementation.getDefinedInModule());
if (rcic == null){
rcic = new RunContextItemCollection(rci.getContextImpl());
contexts.put(rci.getContextImpl(), rcic);
}
rcic.addItem(rci);
// Add the item to its module
rci.getDefinedInModule().addRunContextItem(rci);
menuFactoryRCI = rci;
}
else{
MenuImplementationConfig config = (MenuImplementationConfig) def;