GXT is open source

I have been working over the past few months with Sencha EXTJS4 javascript library. In my time with GWT, I have mainly used the Google widgets. However, I am pleasantly surprised that Sencha GXT also offers an open source version of their product.  Another popular offering for a widget library is SmartGWT.

May 27, 2012 at 6:45 pm Leave a comment

GWT Testing

I have done some mocking before, but for now the focus will be on the use of the  Mocking Framework known as Mockito

http://ars-codia.raphaelbauer.com/2010/11/writing-testcases-part-1-overview-gwt.html

http://ars-codia.raphaelbauer.com/2010/11/writing-testcases-part-2-mocked-unit.html

http://ars-codia.raphaelbauer.com/2011/01/clicking-on-mocked-views-in-gwt.html

http://blog.codiform.com/2011/03/view-presenter-interaction-patterns-in.html
http://www.youtube.com/watch?v=T_CLzgEL7FA
http://code.google.com/p/gwt-test-utils/

http://efreedom.com/Question/1-3417551/Comprehensive-Pros-Cons-Mocking-Frameworks-GWT

http://arcbees.wordpress.com/2010/11/25/testing-views-using-gwt-platform-mockingbinder/

http://onthejvm.com/mocking-your-gwt-widgets-without-gwttestcase

http://code.google.com/webtoolkit/articles/testing_methodologies_using_gwt.html

http://blog.reflectedcircle.co.uk/2009/12/08/gwt-rpc-asynccallback-testing-using-mockito/

http://ars-codia.raphaelbauer.com/2011/01/clicking-on-mocked-views-in-gwt.html

http://blog.webdistortion.com/

http://jeantessier.com/SoftwareEngineering/Mocking.html

http://blog.danielwellman.com/2009/02/mocking-gwt-widgets-with-gwtmockutilities.html

July 12, 2011 at 1:36 am Leave a comment

Getting to know the gwt xml file better

From the DevGuideOrganizingProjects : “the individual units of GWT configuration are called modules and are defined as XML files with a file extension of .gwt.xml”

From gwt style configuration reference guide:  “the source path is a relative path name used to override the default location of the client-side Java source destined to be compiled into JavaScript. The source path you specify is appended to the path where the module configuration file resides, and you may specify multiple source paths.”

Deferred Binding is a technique used by the GWT compiler to create and select a specific implementation of a class based on a set of parameters. For example, special  processing based on the user-agent  with ConditionalProperties .

More info can be found in the GWT Wiki: [DeferredBindings For JRE]

July 5, 2011 at 3:36 pm Leave a comment

MVP plus Activity/Places

I have been through the new GWT 2.1  HelloMVP example , but I was disappointed that for a new technique, it was just to simple of a scenario. I wanted a more involved use case to show the merits of the Activities / Places.  Luckily, I came across the Ashton Thomas GWT 2.1 seminar example and tutorial .

Starting off in the gwt.xml of this GWT 2.1 project:

<!-- Inherit GIN. -->
    <inherits name='com.google.gwt.inject.Inject'/>
<!-- Inherit Activity -->
    <inherits name='com.google.gwt.activity.Activity'/>
<!-- Inherit Place. -->
    <inherits name='com.google.gwt.place.Place'/>
<!-- Inherit Resources -->
    <inherits name='com.google.gwt.resources.Resources'/>

The class AcrintaSeminar is the entry point class.
DesktopInjector is a gin injector  interface that defines method  getAcrintaSeminarApp()  which returns  DesktopApp.
The class AppInjectorModule does the gin injecting:

  • event bus: SimpleEventBus
  • placeController: PlaceControllerProvider

Place: A place basically represents a certain state of your UI. The place is identified using a name. The place string you provide is bascially the history token that will trigger things such as a presenter to activate.

public abstract class AppPlace extends Place {
	public abstract String getToken();
}

PlaceController: In charge of the user’s location in the GUI.

public class PlaceControllerProvider implements Provider<PlaceController>{
	// set up the evenBus to be injected via the constructor
	private final EventBus eventBus;

Activity: is analogous to a presenter in MVP terminology. Activities are started and stopped by an ActivityManager associated with a container Widget.

public class HomeActivity extends AbstractActivity {
	private HomeView view;
	...
	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		panel.setWidget(view.asWidget());

	}

Activity Mapper: Returns the activity to run for the given place

public class MainActivityMapper implements ActivityMapper {…

@Inject
	public MainActivityMapper(HomeActivity homeActivity, RsvpActivity rsvpActivity, AboutActivity aboutActivity,
								ContactActivity contactActivity, LocationActivity locationActivity, ResourcesActivity resourcesActivity){
		...

	public Activity getActivity(Place place) {
		// there are other ways of doing this
		// but just check the instnaces and return
		// the appropriate Activity
		if(place instanceof HomePlace){
			return homeActivity;
		}

ActivityManager: with a given place event, it associates a representative activity to invoke. Here you can start or stop activities where they are associated with a particular widget.

public class DesktopApp extends AcrintaSeminarApp {
	private final DesktopShell shell;
	private final EventBus eventBus;
	private final PlaceController placeController;
	private final MainActivityMapper mainActivityMapper;
	private final AppPlaceHistoryMapper appPlaceHistoryMapper;

	....

	public void run(){
		/* Add handlers, setup activities */
		GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
			public void onUncaughtException(Throwable e) {
				Window.alert("Hey, something went wrong: " + e.getMessage());
				// we could log this if we were using logging...

			}
		});

		CachingActivityMapper cached = new CachingActivityMapper(mainActivityMapper);
		final ActivityManager mainActivityManager = new ActivityManager(cached, eventBus);

		mainActivityManager.setDisplay(shell.getContent());


PlaceHistoryMapper: attach all places which the PlaceHistoryHandler should be aware of.

public class AppPlaceHistoryMapper implements PlaceHistoryMapper{

	private HomePlace homePlace;
	private RsvpPlace rsvpPlace;
	...
@Override
	public Place getPlace(String token) {

		if(token.startsWith("home")){
			return homePlace;
		}else if(token.startsWith("rsvp")){
			return rsvpPlace;
		}else if(token.startsWith("about")){
			return aboutPlace;
		}else if(token.startsWith("contact")){
			return contactPlace;
		}else if (token.startsWith("location")){
			return locationPlace;
		}else if(token.startsWith("resources")){
			return resourcesPlace;
		}

		return null;
	}

	@Override
	public Place getPlace(String token) {

		if(token.startsWith("home")){
			return homePlace;

PlaceHistoryHandler: updates the browser URL corresponding to each Place in your app.

public class DesktopApp extends AcrintaSeminarApp {
	private final DesktopShell shell;
	private final EventBus eventBus;
	private final PlaceController placeController;
	private final MainActivityMapper mainActivityMapper;
	private final AppPlaceHistoryMapper appPlaceHistoryMapper;

	....

	public void run(){
        ....
// History management
		AppPlaceHistoryMapper historyMapper = appPlaceHistoryMapper;
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
		historyHandler.register(placeController, eventBus, defaultPlace);

		// add out UiBinder shell to the Root Panel (the main html document thingy)
		RootLayoutPanel.get().add(shell);
		historyHandler.handleCurrentHistory();

July 4, 2011 at 8:38 pm Leave a comment

Easy To Use UI Binder in your GWT

UI Binder was introduced in GWT 2.0 . I had noted the new functionality in an earlier post.

#1 reason to use it: UiBinder can also make your app more efficient

public class SimpleEntryPoint implements EntryPoint {

  public void onModuleLoad() {

	  HelloWidgetWorld h = new HelloWidgetWorld();  

    RootPanel.get().add(h);
  }
}

You must declare access to UiBinder. Here is HelloWidgetWorld.java:

 public class HelloWidgetWorld extends Composite{
        interface MyUiBinder extends UiBinder<
HTMLPanel, HelloWidgetWorld
> {}
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

	@UiField
	ListBox listBox;

	public HelloWidgetWorld(){
		initWidget(uiBinder.createAndBindUi(this));
		listBox.addItem("Willie Mays");
	}

}

UiBinder<U, O> interface declares two parameter types:

  • HtmlPanel = U is the type of root element declared in the ui.xml file, returned by the createAndBindUi call
  • HelloWorld = O is the owner type whose @UiFields are to be filled in.

HelloWidgetWorld.ui.xml

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui'>

  <g:HTMLPanel>
    Hello, <g:ListBox ui:field='listBox' visibleItemCount='1'/>.
  </g:HTMLPanel>

</ui:UiBinder>

July 3, 2011 at 3:25 pm Leave a comment

Developer Sharing June Edition

UI Binder  http://www.canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/

UI Binder Dock Panel http://www.giantflyingsaucer.com/blog/?p=2302

UI Binder split panel http://www.giantflyingsaucer.com/blog/?p=2324

UI Binder Hello World http://blog.jeffdouglas.com/2010/01/19/gwt-uibinder-hello-world-tutorial/
Create a QR Code with Chart API  http://tamsler.blogspot.com/2010/08/how-to-create-qr-code.html

@Override in Java 6  http://www.bright-creations.com/blog/gwt-2-1-mvp-gin-example/

Strategy & Decorator patterns http://codeofdoom.com/wordpress/2009/05/10/learn-this-strategy-pattern-vs-decorator-pattern/

HTML5 canvas with gwt http://www.giantflyingsaucer.com/blog/?p=2350

GWT Module organizing http://www.summa-tech.com/blog/2011/02/22/structuring-gwt-modules-for-large-applications/

GWT new features http://tbroyer.posterous.com/gwt-211-requestfactory-part-ii http://tbroyer.posterous.com/gwt-21-editors http://tbroyer.posterous.com/gwt-21-places-activities-what-changed-between

GWT wraps JSON http://www.zackgrossbart.com/hackito/gwt-slider/

vaadin http://codebalance.blogspot.com/2011/06/developing-rich-web-interfaces-using.html

Advanced GWT Widgets   http://www.jhkuperus.nl/articles/java/gwt-dynamically-changing-css-styles/

June 29, 2011 at 12:30 am Leave a comment

Converting my GAE application from JDO to JPA

In past I had used the GAE with JDO, and in this exercise I will convert it to JPA.

In javasource/META-INF is the jdoconfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
  <persistence-manager-factory name="transactions-optional">
    <property name="javax.jdo.PersistenceManagerFactoryClass" 
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
    <property name="javax.jdo.option.ConnectionURL" value="appengine"/>
    <property name="javax.jdo.option.NontransactionalRead" value="true"/>
    <property name="javax.jdo.option.NontransactionalWrite" value="true"/>
    <property name="javax.jdo.option.RetainValues" value="true"/>
    <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
  </persistence-manager-factory>
</jdoconfig>

private static final PersistenceManagerFactory PMF =
JDOHelper.getPersistenceManagerFactory(“transactions-optional”);

Example write:

PersistenceManager pm = getPersistenceManager();
try {
  pm.makePersistent(new Movie(getUser(), symbol, note));
} finally {
  pm.close();
}

Example read and delete:

Query q = pm.newQuery(Movie.class, "user == u");
q.declareParameters("com.google.appengine.api.users.User u");
List<Movie> movies = (List<Movie>) q.execute(getUser());
for (Movie movie : movies) {
if (moviename.equals(movie.getSymbol())) {
    deleteCount++;
    pm.deletePersistent(movie);
}

Now to JPA queries:

 

private static final EntityManagerFactory EMF =
      Persistence.createEntityManagerFactory("transactions-optional");
private EntityManager getEntityManager() {
	    return EMF.createEntityManager();
	  }
EntityManager em = getEntityManager();
		// Read the existing entries
		javax.persistence.Query q = em.createQuery("select m from Movie m");


@Entity
public class Movie {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

June 25, 2011 at 2:38 pm Leave a comment

Older Posts


@davidmbloom


Follow

Get every new post delivered to your Inbox.