Thoughts on GWT, MVP and GWT-EXT

Posted October 27, 2009 by alexharvey
Categories: Java

Tags: ,

I have been working with implementing the MVP pattern while making use of the GWT-EXT library.

I was inspired by David Chandler’s technique for hide/showing DIV’s when switching between distinct views in the application. Because GWT-EXT uses a Viewport object to serve as the root panel on the page, David’s exact technique didn’t work out with GWT-EXT panels. The solution turns out to be to create a new Viewport on each change of the root view. In my case I simply implemented hide() and show() methods in my display to take care of this.


public void hide() {
 panel.setVisible(false);
 }

public void show() {
 Log.debug("in UserView.show");
 panel.setVisible(true);
 new Viewport(panel);
 }

In my case, panel represents the root panel for the view. My impression of Viewport is that the documentation is scarce and it is a mysery as to exactly how it manages the browser window. Perhaps there is more documentation in the underlying JS library but I didn’t go that far.

The other issue I’ve faced with GWT-EXT is that GWT-EXT aren’t always the same as GWT widgets and do not normally implement interfaces like HasClickHandlers, HasHTML, etc. I may work on extending GWT-EXT’s button to work with HasClickHandlers.

One handy feature of GWT-EXT’s Panel is the ability to add a Toolbar to the bottom or top. Immediately though I wanted to add a GWT Hyperlink. Here GWT-EXT expects controls added to the Toolbar class to derive from ToolbarItem. Eventually I discovered it is possible to add items to a Toolbar by DOM element:

private void initToolbar() {
 PlaceRequest placeRequestManageUsers = new PlaceRequest(UserPresenter.PLACE);
 linkManageUsers = new Hyperlink("Manager users", placeRequestManageUsers.toString());

 /**
 * call to addFill() makes toolbar right justify
 */
 toolbar.addFill();
 toolbar.addElement(linkManageUSers.getElement());
 ...
}

After so many years of programming in Struts I have to admit that programming in GWT represents a new way of thinking. Designing for the user experience that is possible with GWT is a welcome change of pace after so much page-oriented stuff in traditional Struts.

What I’ve been doing on my Mac

Posted April 22, 2008 by alexharvey
Categories: Java

I came across this little script here.

$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
208 mvn
121 cd
97 ls
12 mate
8 history
7 ping
4 sudo
4 rsync
4 ftp
3 ssh

more blogs

Posted November 26, 2007 by alexharvey
Categories: Blogroll, Digital Photography

I’ve added two blogs on Blogspot since this blog is mostly Java related. I’ve started learning Haskell so I decided to keep a separate blog for other coding topics not related to Java. The links are in the blogroll. I also started a photo blog.

Groovy/Grails in Eclipse on OS X

Posted November 16, 2007 by alexharvey
Categories: Groovy, Mac

I’ve been working with Grails for just a short time now and so far I’m fully impressed in the time savings it offers for development. The other factor the impresses me is that it all just makes intuitive sense for someone who has worked with a variety of web frameworks before.

I ran into an issue with Grails 1.0-RC1 with the Eclipse plugin on Mac. The framework was complaining that it could not find tools.jar which doesn’t exist on the Mac. I believe Apple for some reason merged the contents of tools.jar with another system jar. Anyhow, so far I have safely commented out a reference to tools.jar in conf/groovy-starter.conf. Other than that issue, I have had far fewer than there might be in setting up a full blown Struts 2/Spring/Hibernate project by hand.

I was just reading about the IntelliJ support for Groovy/Grails over on Glen Smith’s blog and think I will have to try it out. I have never used IntelliJ before but if it has better language support for Groovy than Eclipse currently does it would be worth switching.

Leopard so far

Posted November 6, 2007 by alexharvey
Categories: Mac

I’ve upgraded two Macs at home without issues during the upgrade. My work MBP is still running Tiger and probably will be for quite a while.

I’ve had issues with Time Machine really dragging down system performance until the first complete sync was completed. For some reason the first synchronization failed for several days. My complaint on Time Machine is that there is no immediate link or callout for viewing its log. There should be. I assume it is someplace in /var but I have not gone there yet.

Terminal is a big improvement.

XDMCP seems broken in some way. Akthough I can connect to my Ubuntu box, the keyboard doesn’t work now on the login screen. Ouch. The old trick of switching the keyboard to extended layout has no affect.

Lack of Java 6 support is of course just a shame.

Overall my impression is that performance sufers just a bit.

Google Usability

Posted October 23, 2007 by alexharvey
Categories: Google

2 simple things are needed:

  1. Allow for customization of the top-level menu. Some items, like Reader, are buried in the drop down and it would be helpful if these could be moved or reordered.
  2. Add Notebook as an available item in the top level menu.

date puzzler explained

Posted September 15, 2007 by alexharvey
Categories: Java

As someone pointed out the unexpected behavior really is coming from the parse method. Looking in the JavaDocs the behavior is likely coming from the DateFormat class:

By default, parsing is lenient: If the input is not in the form used by this object’s format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

Although this isn’t specific, it may mean it will interpolate dates when the range falls outside of the correct value. Perhaps there is more detailed documentation, but this is all I found without being overly exhaustive about it. So beware if you are expecting parse() to perform strict date format checking for you. I have also found DateValidator() in Commons Validator to be useful in examining date formats.

a Java puzzler

Posted September 14, 2007 by alexharvey
Categories: Java

I’m a fan of Java Puzzlers and came across this one on my own. Perhaps it has been brought up before though. What happens when you run this program? Hopefully I can explain the answer by tomorrow!

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date d = sdf.parse("1957-02-29");
System.out.println("success: " + d.toString());
} catch (ParseException e) {
e.printStackTrace();
}
}

summer photos

Posted September 9, 2007 by alexharvey
Categories: Digital Photography

Now that summer is winding down a bit, I thought I would go back through a few of my photos and link to them here.




Groovy and Google Notebook

Posted September 8, 2007 by alexharvey
Categories: GData, Google, Groovy, Java

I started learning Groovy in the past few days. So far I am wondering why I waited so long to start learning it. I like the shorthand style and the ability to get tasks that are a pain in Java done quickly. These are obvious things to like certainly since they are objectives of the language.

Anyhow, I needed something to do with the language so I chose to write a simple script to download a list of public notebooks from Google Notebook and then process the first one in the list. Here are some observations on the process.

  • It was not immediately obvious to me how to obtain my Google userid that the documentation mentions. I discovered after a bit of frustration that it is a large numeric value that is passed no the query string and is not the userid that one logs in with. This didn’t jump out at me from the documentation.
  • I used Eclipse to write my script and boy did I miss several things that the plugin lacks: code auto formatting and a debugger. Even though the script I wrote is trivial a debugger would be a nice tool in learning Groovy. Maybe one of the other IDE’s has one for Groovy?
  • Groovy still awkward to me after living the structurd life of a Java programmer for so many years. The corner-cutting takes some getting used to. The missing ;’s can feel like nails on a chalkbaord.

  • import com.google.gdata.client.*;
    import com.google.gdata.data.*;
    def myId = 'big number from google url'
    def urlUser = "http://www.google.com/notebook/feeds/$myId"
    URL feedUrl = new URL(urlUser);


    GoogleService googleService = new GoogleService("notebook", "alex sample");

    /**
    * request the feed
    */
    Feed myFeed = googleService.getFeed(feedUrl, Feed.class);

    print 'notebook name: '
    println myFeed.title.plainText;

    List l = myFeed.entries;

    println "public notebook's: "
    for (Entry e in l) {

    print e.title.plainText;

    URL notebookUrl = new URL(e.id)

    Feed notebookFeed = googleService.getFeed(notebookUrl, Feed.class);
    /* process the feed */

    }