i have a problem with gin library. I don't understand how to include it in project. The project is very simple.(I made it for understanding gin, but still don't get it. This project should use gin library)
We have first page with button and checkbox. If value of checkbox - true we can push our button, that allows add new buttons on second page. Can you guys help me complete this example? I add a root package which contains RootView, IRootView and RootPresenter. RootView have to contains Page1 and Page2. What should i add in RootPresenter? Which widget should contains both pages in RootView? How i will inject Page1 and Page2 into RootView ?
Can anyone help me with any suggestion? Better if you'll help with some code, that will help me alot with understanding gin.
interface of Page1
public interface IPage1View extends IsWidget {
public Button getAddButton();
public CheckBox getCheckBox();
public interface IPage1Presenter{}
}
presenter for Page1
@Presenter(view = Page1View.class)
public class Page1Presenter extends BasePresenter<IPage1View, AppEventBus> implements IPage1View.IPage1Presenter{
@Override
public void bind() {
view.getCheckBox().setValue(true);
view.getAddButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
eventBus.addNewButton();
}
});
view.getCheckBox().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if(event.getValue()){
eventBus.enableMOM();
}
else {
eventBus.disableMOM();
}
}
});
}
public void onStart(){
RootPanel.get("page1").add(view);
}
public void onEnableMOM(){
view.getAddButton().setEnabled(true);
}
public void onDisabledMOM(){
view.getAddButton().setEnabled(false);
}}
Page1View
public class Page1View extends ReverseCompositeView<IPage1View.IPage1Presenter> implements IPage1View{
private Button addButton;
private CheckBox checkBox;
Page1View(){
SimplePanel mainPanel = new SimplePanel();
DecoratorPanel backgroundPanel = new DecoratorPanel();
addButton = new Button("Add new button");
checkBox = new CheckBox("Enable adding new buttons");
VerticalPanel content = new VerticalPanel();
content.setSize("400px","400px");
content.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
content.add(addButton);
content.add(checkBox);
backgroundPanel.add(content);
mainPanel.add(backgroundPanel);
}
@Override
public Button getAddButton() {
return addButton;
}
@Override
public CheckBox getCheckBox() {
return checkBox;
}
}
Almost same thing with Page2. For saveing place i dont post it.
EventBus
@Events(startView = Page1.class)
public interface AppEventBus extends EventBus {
@Start
@Event(handlers = {Page1Presenter.class, Page2Presenter.class, Page3Presenter.class, Page4Presenter.class})
public void start();
@Event(handlers = {Page1Presenter.class}, activate = Page2Presenter.class)
public void enableMOM();
@Event(handlers = {Page1Presenter.class}, deactivate = Page2Presenter.class)
public void disableMOM();
@Event(handlers = Page2Presenter.class)
public void addNewButton();
@Event(handlers = Page2Presenter.class)
public void deleteSomeButton(Button killerButton);
@Event(handlers = Page3Presenter.class)
public void getData();
@Event(handlers = Page4Presenter.class)
public void addNewPoint();
}
And root package elements have same structure with Page1, but they empty. I dont know what code should contain they.
Can anyone with experience of using gin + mvp4g help me ?
Updt: I am trying to do this by myself, but still there a errors.( What i did:
public interface IRootView extends IsWidget{
interface IRootPresenter{}
}
I made RooView with UIBinder.
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:HTMLPanel>
<g:SimplePanel ui:field="page1">
</g:SimplePanel>
<g:SimplePanel ui:field="page2">
</g:SimplePanel>
</g:HTMLPanel>
</ui:UiBinder>
These panels should contain ours page1 and page2(how i imagine). But when i am trying to inject them - i have a errors with types.
public class RootView extends ReverseCompositeView<IRootView.IRootPresenter>
implements IRootView {
@UiField
SimplePanel page1, page2;
@Inject
public RootView(Page1View page1, Page2View page2){
//how to add them ?
}
interface RootViewUiBinder extends UiBinder<Widget, RootView> {
}
private static RootViewUiBinder ourUiBinder = GWT.create(RootViewUiBinder.class);
public RootView() {
initWidget(ourUiBinder.createAndBindUi(this));
}
}
RootPresenter
@Presenter(view = RootView.class)
public class RootPresenter extends BasePresenter<IRootView, AppEventBus> implements IRootView.IRootPresenter{
public void onStart(){
}
}
First, you should use the latest version of mvp4g (1.5.0). You find the latest version here: https://github.com/mvp4g/mvp4g/releases
Views and service are injected by mvp4g. So, there is no need to use GIN for this.
If you need to inject something else, just create a Provider for this class:
public class MyClassProvider
implements Provider<MyClass> {
static MyClass myClass = new MyClass();
@Override
public MyClass get() {
return MyClass;
}
}
Next you need a class which set up GIN:
public class MyApplicationGinModule
extends AbstractGinModule {
@Override
protected void configure() {
bind(MyClass.class).toProvider(MyClassProvider.class)
.in(Singleton.class);
}
}
Once you have this class, you can easily add it to the eventbus:
@Events(startPresenter = Page1Presenter.class,
ginModules = MyApplicationGinModule.class)
public interface AppEventBus extends EventBus {
...
}
Here you will find more informations: https://github.com/mvp4g/mvp4g/wiki/08.-GIN-Integration