Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create your widget classes using the templates below.
  2. Write a test for your Presenter if you write business logic into it.
  3. In the PortalGinModule class, force your ViewImpl to be a Singleton and bind the ViewImpl to its View
    1. Code Block
      //DatasetEditorEntityChildBrowser
      bind(DatasetEditorViewImplEntityChildBrowserViewImpl.class).in(Singleton.class);
      bind(DatasetEditorViewEntityChildBrowserView.class).to(DatasetEditorViewImplEntityChildBrowserViewImpl.class);
  4. 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
    1. Code Block
      languagexml
      titleIn your UiBinder (ui.xml) file
      <g:SimplePanel ui:field="editorPanel" />
    2. Code Block
      languagejava
      titleIn your ViewImpl class
      @UiField
      SimplePanel adminPanel;
      
      @Inject
      public SomeViewImpl(..., DatasetEditorEntityChildBrowser datasetEditorbroswer) {
      	adminPanel.add(datasetEditor);
      }

...

Code Block
languagejava
titleDatasetEditorEntityChildBrowser.java
package org.sagebionetworks.web.client.widget.entity.children;

import org.sagebionetworks.web.client.PlaceChanger;
import org.sagebionetworks.web.client.widget.editpanelsSynapseWidgetPresenter;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class DatasetEditorEntityChildBrowser implements DatasetEditorViewEntityChildBrowserView.Presenter, SynapseWidgetPresenter {
	
	private DatasetEditorViewEntityChildBrowserView view;
	private PlaceChanger placeChanger;
	private HandlerManager handlerManager = new HandlerManager(this);
	
	@Inject
	public DatasetEditorEntityChildBrowser(DatasetEditorViewEntityChildBrowserView view) {
		this.view = view;		
		view.setPresenter(this);
	}	
	
	@SuppressWarnings("unchecked")
	public void clearState() {
		view.clear();
	}

	@Override
	public Widget asWidget() {
		
             return view.asWidget();
	}

    public void setPlaceChanger(PlaceChanger placeChanger) {
    	this.placeChanger = placeChanger;
    }
    
	@Override
	public PlaceChanger getPlaceChanger() {
		return placeChanger;
	}
		
}

View

The view interface defines the view and the Presenter interface--the view's method to make conceptual business logic calls like "saveValues(...)"

Code Block
languagejava
titleDatasetEditorViewEntityChildBrowserView.java
package org.sagebionetworks.web.client.widget.editpanels;

package org.sagebionetworks.web.client.widget.entity.children;

import org.sagebionetworks.web.client.PlaceChanger;
import org.sagebionetworks.web.client.widget.SynapseWidgetView;
import com.google.gwt.user.client.ui.IsWidget;

public interface DatasetEditorViewEntityChildBrowserView extends IsWidget, SynapseWidgetView {

	/**
	 * Set the presenter.
	 * @param presenter
	 */
	public void setPresenter(Presenter presenter);

	
	/**
	 * Presenter interface
	 */
	public interface Presenter {

		PlaceChanger getPlaceChanger();

	}
}

ViewImpl

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
languagejava
titleDatasetEditorViewImplEntityChildBrowserViewImpl.java
package org.sagebionetworks.web.client.widget.editpanels;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.user.client.Element;
entity.children;

import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class DatasetEditorViewImplEntityChildBrowserViewImpl extends LayoutContainer implements DatasetEditorViewEntityChildBrowserView {

	private Presenter presenter;
	private SageImageBundle sageImageBundle;
	private IconsImageBundle iconsImageBundle;
		
	@Inject
	public DatasetEditorViewImplEntityChildBrowserViewImpl()SageImageBundle {sageImageBundle,
	}
			IconsImageBundle iconsImageBundle) {
	@Override
	protectedthis.sageImageBundle void onRender(Element parent, int pos) {= sageImageBundle;
		this.iconsImageBundle = iconsImageBundle;
		superthis.onRendersetLayout(parent, posnew FitLayout());
	}
	
	@Override
	public Widget asWidget() {
		return this;
	}
	

	@Override 
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
		
	@Override
	public void showErrorMessage(String message) {
		DisplayUtils.showErrorMessage(message);
	}

	@Override
	public void showLoading() {
	}

	@Override
	public void showInfo(String title, String message) {
		DisplayUtils.showInfo(title, message);
	}

	@Override
	public void clear() {
	}

}