Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In this article, we’ve covered everything you need to know about GWT CellTable Widget. CellTable widget is similar to table and related tags in HTML. The GWT CellTable widget displays a column- and page-supported tabular representation.
GWT CellTable Class Declaration
Let's look at the declaration of com.google.gwt.user.cellview.client.CellTable<T>.
public class CellTable<T> extends AbstractHasData<T>
Here’s a diagram that shows the levels of inheritance and all the classes from which CellTable is inherited:
GWT CellTable Constructor
Here’s a list of GWT CellTable Constructors:
GWT CellTable Methods
Here’s a list of GWT CellTable Methods:
GWT CellTable Example
This example will walk you through some basic GWT VerticalSplitPanel Widget usage procedures.
Step 1: Create a project with a name HelloWorld under your package(com.your_email_id)
Step 2: Create files HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java
Step 3: Here is what the changed module descriptor contains( src/com.example/HelloWorld.gwt.xml.) :
<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'helloworld'>
<!-- Inheriting core Web Toolkit stuff and default GWT style sheet. →
<inherits name = 'com.google.gwt.user.User'/>
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify entry point class of the app →
<entry-point class = 'com.example.client.HelloWorld'/>
<!-- Specify the paths for translatable code →
<source path = 'client'/>
<source path = 'shared'/>
</module>
Step 4: The changed Style Sheet file HelloWorld.css content is listed below:
Step 6: Let's look at the Java file src/com.example/HelloWorld.java with the following contents to see how to use the GWT VerticalSplitPanel widget.
package com.example.client;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
public class HelloWorld implements EntryPoint {
/* A simple data type that represents a contact.*/
private static class Contact {
private final String address;
private final Date birthday;
private final String name;
public Contact(String name, Date birthday, String address) {
this.name = name;
this.birthday = birthday;
this.address = address;
}
}
/* The list of data to display. */
private static final List CONTACTS = Arrays.asList(
new Contact("Prabhas", new Date(47, 9, 5), "5th street, Pune"),
new Contact("Akshar", new Date(85, 7, 14), "22 Landran Road"),
new Contact("Lucas",new Date(11, 6, 6),"73 Pusa Road"));
public void onModuleLoad() {
// Create a CellTable.
CellTable table = new CellTable();
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
// Add a text column to show the name.
TextColumn nameColumn = new TextColumn() {
@Override
public String getValue(Contact object) {
return object.name;
}
};
table.addColumn(nameColumn, "Name");
// Add a date column to show the birthday.
DateCell dateCell = new DateCell();
Column dateColumn = new Column(dateCell) {
@Override
public Date getValue(Contact object) {
return object.birthday;
}
};
table.addColumn(dateColumn, "Birthday");
// Add a text column to show the address.
TextColumn addressColumn = new TextColumn() {
@Override
public String getValue(Contact object) {
return object.address;
}
};
table.addColumn(addressColumn, "Address");
// Add a selection model to handle user selection.
final SingleSelectionModel selectionModel = new SingleSelectionModel();
table.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler( new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
Contact selected = selectionModel.getSelectedObject();
if (selected != null) {
Window.alert("You selected: " + selected.name);
}
}
});
// Set the total row count. This isn't strictly necessary,
// but it affects paging calculations, so its good habit to
// keep the row count up to date.
table.setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
table.setRowData(0, CONTACTS);
VerticalPanel panel = new VerticalPanel();
panel.setBorderWidth(1);
panel.setWidth("400");
panel.add(table);
// Add the widgets to the root panel.
RootPanel.get().add(panel);
}
}
Output:
Frequently Asked Questions
What is GWT CellTable Widget?
The GWT CellTable widget displays a column- and page-supported tabular representation
What are the advantages of GWT?
An open-source Java software development platform; Google Web Toolkit (GWT) makes it simple to create AJAX apps. You can use the Java development tools to create and debug AJAX apps with GWT.
What advantages does GWT offer?
If you are a Java programmer with knowledge of Swing or AWT, selecting GWT should be simple. Even if you lack experience in Java GUI development, the years spent working on server-side Java will be helpful when creating GWT applications.
How advantageous is learning GWT?
Many Google projects, both internal and external, are based on GWT, therefore Google will need to sustain the technology as long as they need to keep improving the front-end.
Does Google use still GWT?
Some of Google's products, including Blogger, AdWords, Flights, Wallet, Offers, Groups, and Inbox, are GWT-based.
Conclusion
In this article, we have discussed everything you need to know about GWT CellTable Widget. Here are more articles to the rescue: