Table of contents
1.
Introduction
2.
Class Declaration of GWT CellList Widget
3.
Class Constructors and Description
4.
Nested Class Summary
5.
Class Methods and Description
6.
GWT CellList Widget Methods Inherited
7.
GWT CellList Widget Example
8.
Frequently Asked Questions
8.1.
What is the purpose of GWT?
8.2.
What is GWT?
8.3.
What is GWT CellList Widget?
8.4.
What characteristics does GWT have?
8.5.
Who uses GWT - Google Web Toolkit?
9.
Conclusion
Last Updated: Mar 27, 2024
Medium

GWT CellList Widget

Author Alok Pandey
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The GWT CellList Widget represents a single-column list of cells. This GWT CellList Widget can be used to create layouts with a single-column list of cells. Now let's see its class declaration along with other properties like class construction and methods.

GWT CellList Widget

Must Recommended Topic, procedure call in compiler design

Class Declaration of GWT CellList Widget

GWT CellList Widget declaration for com.google.gwt.user.cellview.client.CellList<T> class −

public class CellList<T>
extends AbstractHasData<T>

Class Constructors and Description

GWT CellList Widget constructors and their descriptions are listed below:

Constructor 

Description

CellList(Cell<T> cell)

This constructs a new CellList.

CellList(Cell<T> cell, CellList.Resources resources)

It constructs a new CellList with the specified CellList.Resources.

CellList(Cell<T> cell, ProvidesKey<T> keyProvider)

This constructs a new CellList with the specified key provider.

CellList(Cell<T> cell, CellList.Resources resources, ProvidesKey<T> keyProvider)

It constructs a new CellList with the specified CellList.Resources and key providers.

Nested Class Summary

GWT CellList Widget uses the different types of classes with specific purposes some of the nested classes are defined below

  • Nested classes/interfaces inherited from class com.google.gwt.user.cellview.client.AbstractHasData
    AbstractHasData.DefaultKeyboardSelectionHandler<T>, AbstractHasData.RedrawEvent
     
  • Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
    UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
     
  • Nested classes/interfaces inherited from interface com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy
    HasKeyboardPagingPolicy.KeyboardPagingPolicy
     
  • Nested classes/interfaces inherited from interface com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy
    HasKeyboardSelectionPolicy.KeyboardSelectionPolicy

Class Methods and Description

GWT CellList Widget constructors and their descriptions are listed below:

Sr.No.

Function name 

Description

1

protected boolean dependsOnSelection()

This method checks whether or not the cells in the view depend on the selection state.

2

protected void doSelection(Event event, T value, int indexOnPage)

Deprecated. This method uses Abstract HasData.add Cell Preview Handler(com.google.gwt.view.client.Cell Preview Event.Handler) instead.

3

protected void fireEventToCell(Cell.Context context, Event event, Element parent, T value)

 

This fires an event to the cell.

4

protected Cell<T> getCell()

 

This method returns the cell used to render each item.

5

protected Element getCellParent(Element item)

 

It gets the parent element that wraps the cell from the list item.

6

protected Element getChildContainer()

 

This return the element that holds the rendered cells.

7

SafeHtml getEmptyListMessage()

It gets the message that is displayed when there is no data.

8

protected Element getKeyboardSelectedElement()

It gets the element that has keyboard selection.

9

Element getRowElement(int indexOnPage)

 

It gets the Element for the specified index.

10

protected boolean isKeyboardNavigationSuppressed()

 

This method checks if keyboard navigation is being suppressed, such as when the user is editing a cell

11

protected void onBlur()

It is called when the widget is blurred.

12

protected void onBrowserEvent2(Event event)

This is called after AbstractHasData.onBrowserEvent(Event) completes.

13

protected void onFocus()

It is called when the widget is focused.

14

void setEmptyListMessage(SafeHtml html)

This method sets the message to display when there is no data.

15

void setValueUpdater(ValueUpdater<T> valueUpdater)

This method sets the value updater to use when cells modify items.

16

protected boolean resetFocusOnCell()

This method resets focus on the currently focused cell.

17

protected void renderRowValues(SafeHtmlBuilder sb, java.util.List<T> values, int start, SelectionModel<? super T> selectionModel)

It renders all row values into the specified SafeHtmlBuilder.

18

protected void setKeyboardSelected(int index, boolean selected, boolean stealFocus)

This method updates an element to reflect its keyboard selected state.

19

protected void setSelected(Element elem, boolean selected)

Deprecated. It is never called by AbstractHasData, render the selected styles in renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)

GWT CellList Widget Methods Inherited

GWT CellList Widget uses many inbuilt methods. Some of the Inherited methods are defined below

  • java.lang.Object
  • com.google.gwt.user.client.ui.UIObject
  • com.google.gwt.user.client.ui.Widget
  • com.google.gwt.user.client.ui.Composite
  • com.google.gwt.user.cellview.client.AbstractHasData<T>
  • com.google.gwt.user.cellview.client.CellList<T>

GWT CellList Widget Example

In this example, we look for the usage of a GWT CellList Widget in simple steps. Now let's have a look at the step-wise construction of the GWT Vertical Panel Widget.

Step 1: Create a project with the name CellListWidget under a package com.codingninjas.
 

Step 2: Change CellListWidget.gwt.xml, CellListWidget.css, CellListWidget.html, and CellListWidget.java as explained below. 

 

Step 3: Compile and run the application to get the output


Code of the module descriptor src/com.codingninjas/CellListWidget.gwt.xml.

<?xml version = "1.0" encoding = "UTF-8"?>
<module rename-to = 'cellListWidget'>
   <inherits name = 'com.google.gwt.user.User'/>
   <inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
   <entry-point class = 'com.codingninjas.client.CellListWidget'/>
   <source path = 'client'/>
   <source path = 'shared'/>
</module>

 

Code of the Style Sheet file war/CellListWidget.css.

body {
	text-align: center;
}

h1 {
	font-size: 32px;
	font-weight: bold;
	color: #f79d00;
	text-align: center;
}

 

Code of the HTML host file war/CellListWidget.html.

<html>
    <head>
        <title>CellListWidget</title>
        <link rel="stylesheet" href="CellListWidget.css" />
        <script language="javascript" src="CellListWidget/CellListWidget.nocache.js"></script>
    </head>
    <body>
        <h1>GWT CellList Widget</h1>
        <div id="gwtContainer"></div>
    </body>
</html>

 

Code of Java file src/com.codingninjas/CellListWidget.java 

package com.codingninjas.client;
import java.util.Arrays;
import java.util.List;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel;

public class CellListWidget implements EntryPoint {

  /* Data type that represents a contact.*/
  private static class Contact {
    private String p_name;
    private static int nextId = 0;
    private final int id;

    public Contact(String p_name) {
      nextId++;
      this.id = nextId;
      this.p_name = p_name;
    }
  }

  /* A custom {@link Cell} used to render a {@link Contact}*/
  private static class ContactCell extends AbstractCell < Contact > {
    @Override
    public void render(Contact value, Object key, SafeHtmlBuilder sb) {
      if (value != null) {
        sb.appendEscaped(value.p_name);
      }
    }
  }

  /* The list of data to display.*/
  private static final List < Contact > CONTACTS = Arrays.asList(new Contact(
      "Rohit"), new Contact("Prateek"), new Contact("Deepak"),
    new Contact("Raman"), new Contact("Rajan"));

  public void onModuleLoad() {
    ProvidesKey < Contact > keyProvider = new ProvidesKey < Contact > () {
      public Object getKey(Contact item) {
        /* Null check.*/
        return (item == null) ? null : item.id;
      }
    };

    /*Create a CellList using the keyProvider. */
    CellList < Contact > cellList = new CellList < Contact > (new ContactCell(),
      keyProvider);

    /*Pushing data */
    cellList.setRowCount(CONTACTS.size(), true);
    cellList.setRowData(0, CONTACTS);

    /* Add a selection model using the same keyProvider. */
    SelectionModel < Contact > selectionModel = new SingleSelectionModel < Contact > (
      keyProvider);
    cellList.setSelectionModel(selectionModel);

    /*Selection of contact */
    Contact test = CONTACTS.get(3);
    selectionModel.setSelected(test, true);

    /* p_Name Modification */
    test.p_name = "Deepak";

    cellList.redraw();

    VerticalPanel panel = new VerticalPanel();
    panel.setBorderWidth(1);
    panel.setWidth("300");
    panel.add(cellList);
    RootPanel.get().add(panel);
  }
}
You can also try this code with Online Java Compiler
Run Code

 

Output:

Output of code

Frequently Asked Questions

What is the purpose of GWT?

A development toolkit called GWT is used to create and improve sophisticated browser-based apps. Its objective is to make it possible to construct high-performance web apps productively without the developer having to be an expert in JavaScript, XMLHttpRequest, or browser quirks.

What is GWT?

GWT (Google web toolkit) is an open-source development toolkit provided by google for developing browser-based, complex Ajax applications. We can even develop Rich Internet Applications (RIA) in Java using GWT, which will then be compiled into Javascript and cross-browser compliant.

What is GWT CellList Widget?

The GWT CellList Widget represents a single-column list of cells. This GWT CellList Widget can be used to create layouts with a single-column list of cells. 

What characteristics does GWT have?

Asynchronous remote procedure calls, history management, bookmarking, UI abstraction, internationalization, and cross-browser portability.

Who uses GWT - Google Web Toolkit?

Companies like Crimsonlogic Pte. Ltd., StudyBlue Inc., and Intrado Inc. are using GWT.

Conclusion

In this article, we have extensively discussed how the project GWT CellList Widget. We have discussed its constructors, methods, and implementation. GWT CellList Widget is a part of form widgets that are used in many places while developing applications. and if you would like to learn more, check out our articles on
 

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Conclusion Image

Do upvote our blog to help other ninjas grow. 

Happy Coding!

Live masterclass