}
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;
ResultException ex = new ResultException();
ex.addError("Multiple menu implementations are specified as part of your loaded modules; only one menu implementation can be used.");
ex.result.lastResult().moreMessages("Menus from " + menuImplementation.getConfigName() + " defined in module " + menuImplementation.getDefinedInModule().getModuleName());
ex.result.lastResult().moreMessages("Menus from " + config.getConfigName() + " defined in module " + config.getDefinedInModule().getModuleName());
throw(ex);
}
}