...
- Create your widget classes using the templates below.
- Write a test for your Presenter if you write business logic into it.
- In the PortalGinModule class, force your ViewImpl to be a Singleton and bind the ViewImpl to its View
Code Block //DatasetEditor bind(DatasetEditorViewImpl.class).in(Singleton.class); bind(DatasetEditorView.class).to(DatasetEditorViewImpl.class);
- Inject the Presenter class into the class that you're using. This automatically injects the ViewImpl into the presenter, and you have a fully ready object. When you want to add this to a UiBinder class, simply add it to a SimplePanel
Code Block language xml title In your UiBinder (ui.xml) file <g:SimplePanel ui:field="editorPanel" />
Code Block language java title In your ViewImpl class @UiField SimplePanel adminPanel; @Inject public SomeViewImpl(..., DatasetEditor datasetEditor) { adminPanel.add(datasetEditor); }
Widget MVP Templates
Presenter
The presenter stores the business logic. This is where your widget would, say, make calls to a remote service. Often the Presenter will also have several pass through methods for the view like "setTitle(...)".
...
The ViewImpl implements its view and extends LayoutContainer. LayoutContainer is Ext GWT's base container (widget) class. You should generally instantiate view objects in the constructor, and add the main content-containing element for this view in the onRender(...) method with a simple add(myContent) call.
Code Block | ||||
---|---|---|---|---|
| ||||
package org.sagebionetworks.web.client.widget.editpanels; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; public class DatasetEditorViewImpl extends LayoutContainer implements DatasetEditorView { private Presenter presenter; @Inject public DatasetEditorViewImpl() { } @Override protected void onRender(Element parent, int pos) { super.onRender(parent, pos); } @Override public Widget asWidget() { return this; } @Override public void setPresenter(Presenter presenter) { this.presenter = presenter; } } |