Book Image

Ext GWT 2.0: Beginner's Guide

By : Daniel Vaughan
Book Image

Ext GWT 2.0: Beginner's Guide

By: Daniel Vaughan

Overview of this book

<p>Ext GWT, also known as GXT, takes Google Web Toolkit one step further by providing a wide range of powerful user interface components. It allows a developer to create powerful web applications that are almost like desktop applications. However to leverage all the features of this powerful Java library for creating desktop-style web applications, you need to learn how and when to use the right user interface component.<br /><br />Ext GWT 2.0: Beginner's Guide is a practical book that teaches you how to use the EXT GWT library to its full potential. It provides a thorough and no-nonsense explanation of the Ext GWT library, what it offers and how to use it through practical examples. This book provides clear, step-by-step instructions for getting the most out of Ext GWT and offers practical examples and techniques that can be used for building your own applications in EXT GWT<br /><br />This book gets you up and running instantly to build powerful Rich Internet Applications (RIA) with Ext GWT. It then takes you through all the interface-building widgets and components of Ext GWT using practical examples to demonstrate when, where, and how to use each of them. Layouts, forms, panels, grids, trees, toolbars, menus, and many other components are covered in the many examples packed in this book. You will also learn to present your data in a better way with templates and use some of the most sought-after features of Ext GWT in your web applications such as drag-and-drop and charts. Throughout the book a real application is built step by step using Ext GWT and deployed to Google App Engine.</p> <p>Imagine how great you'll feel when you're able to create great-looking desktop-style user interfaces for your web applications with Ext GWT!</p>
Table of Contents (17 chapters)
Ext GWT 2.0 Beginner's Guide
Credits
About the Author
About the Reviewers
Preface
Index

Time for action – adapting the GWT app to use GXT controls


  1. When we created the GWT application, a class named FirstApp will be created. We created a copy of that class named FirstGxtApp.

  2. In the imports section of the FirstGxtApp class, we removed the following GWT specific imports:

    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.event.dom.client.KeyUpEvent;
    import com.google.gwt.event.dom.client.KeyUpHandler;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.user.client.ui.DialogBox;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.TextBox;
    import com.google.gwt.user.client.ui.VerticalPanel;
  3. We then added imports to the equivalent GXT classes as follows:

    import com.extjs.gxt.ui.client.event.ButtonEvent;
    import com.extjs.gxt.ui.client.event.SelectionListener;
    import com.extjs.gxt.ui.client.event.KeyListener;
    import com.extjs.gxt.ui.client.event.ComponentEvent;
    import com.extjs.gxt.ui.client.widget.Dialog;
    import com.extjs.gxt.ui.client.widget.Label;
    import com.extjs.gxt.ui.client.widget.VerticalPanel;
    import com.extjs.gxt.ui.client.widget.button.Button;
    import com.extjs.gxt.ui.client.widget.form.TextField;

    You may notice that some of the GXT classes share a similar name to their GWT equivalents. The following table shows the GXT classes we used and the GWT equivalents:

    GXT

    GWT

    com.extjs.gxt.ui.client.widget.Dialog

    com.google.gwt.user.client.ui.DialogBox

    com.extjs.gxt.ui.client.widget.Label

    com.google.gwt.user.client.ui.Label

    com.extjs.gxt.ui.client.widget.VerticalPanel

    com.google.gwt.user.client.ui.VerticalPanel

    com.extjs.gxt.ui.client.widget.button.Button

    com.google.gwt.user.client.ui.Button

    com.extjs.gxt.ui.client.widget.form.TextField

    com.google.gwt.user.client.ui.TextBox

    com.extjs.gxt.ui.client.event.ButtonEvent

    com.google.gwt.event.dom.client.ClickEvent

    com.extjs.gxt.ui.client.event.SelectionListener

    com.google.gwt.event.dom.client.ClickHandler

    com.extjs.gxt.ui.client.event.KeyListener

    com.google.gwt.event.dom.client.KeyUpEvent

    com.extjs.gxt.ui.client.event.ComponentEvent

    com.google.gwt.event.dom.client.KeyUpHandler

  4. We then needed to redefine the controls. In the GWT example, all the code sits inside the onModuleLoad method and makes use of inner classes. However, due to the way listeners are implemented in GXT, we lose some of the flexibility that enables this. Instead, we had to define the controls as private members as follows:

    private final Button sendButton = new Button("Send");
    private final TextField<String> nameField = new TextField<String>();
    private final Dialog dialogBox = new Dialog();
    private final Label textToServerLabel = new Label();
    private final HTML serverResponseLabel = new HTML();
  5. There are differences in syntax between the GXT and GWT methods. Although the GXT controls are similar to GWT controls, there are a number of differences. Firstly, there are many small differences on the methods of the controls between GWT and GXT. Here are the ones we see in this example:

    GXT

    GWT

    TextField.setValue()

    TextBox.setText()

    TextField.focus()

    TextBox.setFocus(true)

    DialogBox.setHeading()

    DialogBox.setText()

    DialogBox.setAnimCollapse(true)

    DialogBox.setAnimationEnabled(true)

    VerticalPanel .setHorizontalAlign(HorizontalAlignment.RIGHT);

    VerticalPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT)

  6. Another difference that is important is that while GWT now uses event handlers for events such as clicking on a button, GXT uses event listeners similar to the earlier version of GWT. However, in this case, the actual code is very similar.

    Here is how you implement the close button click event in GWT using a click handler:

    closeButton.addClickHandler(new ClickHandler() 
    {
      public void onClick(ClickEvent event) 
        {
          dialogBox.hide();
          sendButton.setEnabled(true);
          sendButton.setFocus(true);
        }
    });

    Here is the same thing in GXT using a selection listener:

    closeButton.addSelectionListener(new SelectionListener<ButtonEvent>()
    {
      public void componentSelected(ButtonEvent ce) 
        {
          dialogBox.hide();
          sendButton.setEnabled(true);
          sendButton.focus();
        }
    });
  7. We now have two classes: the original GWT FirstApp class and our new FirstGXTApp class. To use the FirstGXTApp, we need to change the application's gwt.xml module file to use the FirstGXTApp instead of FirstApp.

    Open FirstApp.gxt.xml and change the entry point element from:

    <entry-point class='com.danielvaughan.firstapp.client.FirstApp' />

    to:

    <entry-point class='com.danielvaughan.firstapp.client.FirstGXTApp' />

    Now when running the web application again, you will see a new version with GXT controls.

What just happened?

Hopefully, you now can see that using GXT is not vastly different from using GWT. It is also important to realize that there are some subtle differences. Over the coming chapters, we will show that there are many great features in GXT that go far beyond the basics provided by GWT.

Pop quiz – introducing GXT

  1. What JavaScript library is GXT closely related to?

  2. Which GXT alternative wraps the Smart Client JavaScript library?

  3. Which GXT alternative does most of the work on the server?

  4. Which GXT alternative has a name and appearance that is easily confused with Ext GWT?

  5. What is the name of the company that develops GXT?

  6. What is the name of the GXT Java library file?

  7. What is the license of GXT?

  8. In what file must you inherit the GXT module?

  9. Where must you include a reference to the GXT CSS?

  10. Where must you copy the gxt.jar library file?