1

With GWTP/Gin, is it possible to optionally install a module during compile? We have a case where we would like to have a presenter and view only available in the application when running in "development" mode, where that mode is determined by a flag in the .gwt.xml file (set by the build).

Previously, we were running GXT with an MVC architecture and would do the following in our module:

  <replace-with class="com.mypackage.DevEditController" >
    <all>
        <when-property-is name="isDevelopment" value="true" />
        <when-type-is class="com.mypackage.EditController" />
    </all>
  </replace-with>
  <replace-with class="com.mypackage.StubEditController" >
    <all>
        <when-property-is name="isDevelopment" value="false" />
        <when-type-is class="com.mypackage.EditController" />
    </all>
  </replace-with>

And would create the controller with the following:

(EditController)GWT.create(EditController.class);

I would like to do something similar with GWTP, where the non-development compile of the application wouldn't know anything about this presenter. Essentially, doing something along the lines of this in our module file:

<set-configuration-property name="gin.ginjector.modules" 
                              value="com.mypackage.gin.SharedModule"/>

if this is development mode:
<set-configuration-property name="gin.ginjector.module.desktop"
                              value="com.mypackage.gin.DevDesktopModule"/>
else:
<set-configuration-property name="gin.ginjector.module.desktop"
                              value="com.mypackage.gin.DesktopModule"/>

Where DesktopModule and DevModule would do the same things, but DevDesktopModule would load an additional module (TestModule) containing the presenter/view binding.

Is this doable from a configuration perspective? I thought I could do this with two .gwt.xml files switched out by the build process, but the build process always sees the TestModule file, regardless of whether or not it's being installed (apparently because of the Inject). This is the error message we get when the module is present in the source tree but never installed (this is from a build where we don't want it installed)

[ERROR] Error injecting com.blah.test.TestPresenter$MyView: Unable to create or inherit binding: No @Inject or default constructor found for com.blah.test.TestPresenter$MyView
Path to required node:

com.google.gwt.inject.client.AsyncProvider<com.blah.test.TestPresenter> [com.gwtplatform.mvp.client.ClientGinjector#getcomblahtestTestPresenter()]
-> com.blah.test.TestPresenter [Implicit injection of com.google.gwt.inject.client.AsyncProvider<com.blah.test.TestPresenter>]
-> com.blah.test.TestPresenter$MyView [@Inject constructor of com.blah.test.TestPresenter]

[ERROR] Errors in 'gen/com/gwtplatform/mvp/client/DesktopGinjectorProvider.java'
[ERROR] Line 8: Failed to resolve 'com.gwtplatform.mvp.client.DesktopGinjector' via deferred binding
[WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)

[WARN] com.gwtplatform.mvp.client.com_gwtplatform_mvp_client_DesktopGinjectorImpl

I appreciate any insight into the issue, or alternative solutions for having a "conditionally included" module in our application.

tstewart
  • 11
  • 2

2 Answers2

0

I don't use GWTP, but just Activity/Place architecture. I've found the following solution is suitable in my case.

Configuration parameter in *.gwt.xml* is set by build script and later is parsed in EntryPoint.

<define-configuration-property name="demoMode" is-multi-valued="true" />
<extend-configuration-property name="demoMode" value="false" />

A have view/presenter configuration based on this parameter and correct view is initialized in GIN module.

@Provides @Singleton
public LoginView getLoginView() {
  if (SharedState.IS_DEMO_MODE) {
    return new LoginViewMobileDemo();
  } else {
    return new LoginViewMobile();
  }
}
xRomZak
  • 176
  • 3
  • 10
0

In case anyone else runs into a similar situation...what I ended up doing was moving the optional module code into a standalone GWT module, removing it from the main application source tree. That module is then optionally inherited in our application .gwt.xml file (by the build process).

Even after setting this up, I was still getting Gin warnings about being unable to create or inherit bindings. I tracked that down to an issue in the specified order in the application .gwt.xml file. I was doing the inherit before setting up "gin.ginjector.modules"; once I changed the order, everything worked as expected.

<set-configuration-property name="gin.ginjector.modules" value="com.test.app.SharedModule"/>

<inherits name="com.test.optional.OptionalModule" />
tstewart
  • 11
  • 2