If you want to specify a groupName in constructors of TestPresenter why you might need to use is assisted injection".
Then you would probably end up with something like this (I have not tested the code):
public interface TestPresenterFactory {
TestPresenter create(String groupName);
}
and in your Gin Module:
@Override
protected void configure() {
...
install(new GinFactoryModuleBuilder().build(TestPresenterFactory.class));
}
Then instead of:
@Inject TestPresenter testPresenter1 ("group1");
@Inject TestPresenter testPresenter2 ("group2");
@Inject TestPresenter testPresenter3 ("group3");
@Inject TestPresenter testPresenter4 ("group4");
...
you would inject the TestPresenterFactory in the constructor of ParentPresenter to create all TestPresenters:
private TestPresenter testPresenter1;
private TestPresenter testPresenter2;
private TestPresenter testPresenter3;
private TestPresenter testPresenter4;
@Inject
public ParentPresenter(final EventBus eventBus, final ParentView view, final ParentProxy proxy, final TestPresenterFactory factory)
{
...
testPresenter1 = factory.create("group1");
testPresenter2 = factory.create("group2");
testPresenter3 = factory.create("group3");
testPresenter4 = factory.create("group4");
}
And the @Assisted annotation in the TestPresenter.java:
public interface MyView extends View {
...
public void setRadioButtonsGroupName(String groupName);
}
@Inject
public TestPresenter(final EventBus eventBus, final MyView view, @Assisted String groupName)
{
...
view.setRadioButtonsGroupName(groupName);
}
And TestView.java:
public class TestView extends ViewImpl implements TestPresenter.MyView {
private final Widget widget;
@UiField RadioButton firstRadioButton;
@UiField RadioButton secondRadioButton;
@UiField RadioButton bothRadioButton;
...
public void setRadioButtonsGroupName(String groupName) {
firstRadioButton.setName(groupName);
secondRadioButton.setName(groupName);
bothRadioButton.setName(groupName);
}
}
But do you really need your TestPresenters to be aware of the groupName used by the RadioButtons in their views ?