| |
When it comes to Unit testing a piece of Java code, I
prefer JUnit.
When it comes to check the coding style of my java code,
I prefer Checkstyle.
When it comes to check how much percentage of code is being
covered under unit testing while using JUnit framework,
I prefer Cobertura.
Let us explore an example of using GWT and EXT GridPanel
with Store from EXT.
GWT EXT - GridPanel and its usage using Store, MemoryProxy
and ArrayReader.
One has to obtain GWTEXT along with Google's GWT in order to
make this example work.
Software environment used for this example as follows:
Eclipse 3.5
Java 5.0
GWT 2.0.3 Plugin for Eclipse
EXT 2.0.2
For creation of a GWT web application project, Steps include:
1. openning the GWT Web Application Project wizard, and filled
all the required details such as project name, package,
unchecked "Use Google App Engine", and used default checkbox
"Use Google Web Toolkit" and using default SDK (GWT - 2.0.3)
2. On Finish, all the default folder structures including src,
war, and test automatically created for me.
3. Most of the packages like client, shared, server folders
appended to the initial package choosen for the project.
4. In this example the root package choosen/mentioned as
example. So the Example.gwt.xml file will be automatically
created in this "example" package, while the GWT Web
Application Project is first created.
5. Initially Example.gwt.xml file has many such tags specific
to this module. Before actually adding any more code or
related files to make this Project uses EXT features, I thought
to compile and run this project and see if it works with
all default settings.
6. Using the toolbar and selecting the example project and then
clicking the "GWT Compile Project" and running GWT compiler
will all the default settings.....was able to compile this
example project successfully, with the console output as follows:
Compiling module example.Example
Compiling 6 permutations
Compiling permutation 0...
Compiling permutation 1...
Compiling permutation 2...
Compiling permutation 3...
Compiling permutation 4...
Compiling permutation 5...
Compile of permutations succeeded
Linking into D:\GWT-Workspace\Example\war\example.
Link succeeded
Compilation succeeded -- 42.204s
|
7. After successfully compiling the example project, then came
the time to test it. So selected the Example.html under war
folder, right clicked and selected "Run As"->"Web Application"
with the "blue g icon" showing the GWT specific web application.
8. Once the GWT Developement mode console started successfully
without any errors, time came to test the Example.html file
using a URL something like
"http://127.0.0.1:8888/Example.html"
9. It was real good to see the final screen on browser and
a sense of satisfaction that everything is working so far.
10. Then I started to integrate EXT with this example, by
copying gwtext.jar file to the war\web-inf\lib folder.
11. Then I created a JS folder under war folder and moved
selected js files from the EXT zip file to the project
war folder.
Please refer appropriate license before use
war->js->ext-all.js
war->js->ext-core.js
war->js->adapter (from the EXT 2.0.2)
war->resources (from EXT 2.0.2)
12. The main HTML file that is used for testing is "Example.html"
requires usage of js and css files as follows:
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>
<script type="text/javascript" src="js/adapter/ext/ext-base.js">
</script>
<script type="text/javascript" src="js/ext-all.js"></script>
13. After completing all the steps, I tried my code with the EXT
specific api and try GridPanel, MemoryProxy and Store api.
14. Written some code for testing a simple Grid Panel as follows:
Object[][] obj = new Object[][]{
new Object[]{"testname", 38},
new Object[]{"testname1", 8}
};
RecordDef recordDef = new RecordDef(new FieldDef[]{new
StringFieldDef("Name"),
new IntegerFieldDef("Age")});
ArrayReader arrayReader = new ArrayReader(recordDef);
MemoryProxy dProxy = new MemoryProxy(obj);
Store store = new Store(dProxy, arrayReader);
store.load();
ColumnModel cm = new ColumnModel(new BaseColumnConfig[]{
new ColumnConfig("Name List","Name",130,true),
new ColumnConfig("Age List","Age",130,true)
});
GridPanel gridPanel = new GridPanel(store,cm);
new Viewport(gridPanel);
In this example, data is hardcoded as in Object[][].
Record def has the definition of all the fields.
ArrayReader is having the record def and the memory proxy
has the Object[][] data.
After creating Store with the memory proxy and array reader,
a method "load" call loads all the data in the store.
This store and the ColumnModel are passed to the GridPanel
constructor.
This GridPanel object is added to the Viewport for displaying
on screen.
15. While compiling this example, encountered some of the
exceptions/errors, then added following tag in the
Example.gwt.xml file as follows;
<;inherits name="com.gwtext.GwtExt"/>
16. Again after compiling this project, I saw the output screen
as expected...
|
|