I'm trying to create an eclipse plugin that creates a view with a Tree table that has two columns. I'm currently working off of the sample view template eclipse provides, but I cannot figure out how to specify different data for different columns to be displayed. Here is the code:
public class Variables extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "com.amazon.funce.views.Variables";
private TreeViewer viewer;
private DrillDownAdapter drillDownAdapter;
private Action action1;
private Action action2;
private Action doubleClickAction;
/*
* The content provider class is responsible for
* providing objects to the view. It can wrap
* existing objects in adapters or simply return
* objects as-is. These objects may be sensitive
* to the current input of the view, or ignore
* it and always show the same content
* (like Task List, for example).
*/
class TreeObject implements IAdaptable {
private String name;
private TreeParent parent;
public TreeObject(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setParent(TreeParent parent) {
this.parent = parent;
}
public TreeParent getParent() {
return parent;
}
public String toString() {
return getName();
}
public Object getAdapter(Class key) {
return null;
}
}
class TreeParent extends TreeObject {
private ArrayList children;
public TreeParent(String name) {
super(name);
children = new ArrayList();
}
public void addChild(TreeObject child) {
children.add(child);
child.setParent(this);
}
public void removeChild(TreeObject child) {
children.remove(child);
child.setParent(null);
}
public TreeObject [] getChildren() {
return (TreeObject [])children.toArray(new TreeObject[children.size()]);
}
public boolean hasChildren() {
return children.size()>0;
}
}
class ViewContentProvider implements IStructuredContentProvider,
ITreeContentProvider {
private TreeParent invisibleRoot;
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object parent) {
if (parent.equals(getViewSite())) {
if (invisibleRoot==null) initialize();
return getChildren(invisibleRoot);
}
return getChildren(parent);
}
public Object getParent(Object child) {
if (child instanceof TreeObject) {
return ((TreeObject)child).getParent();
}
return null;
}
public Object [] getChildren(Object parent) {
if (parent instanceof TreeParent) {
return ((TreeParent)parent).getChildren();
}
return new Object[0];
}
public boolean hasChildren(Object parent) {
if (parent instanceof TreeParent)
return ((TreeParent)parent).hasChildren();
return false;
}
/*
* We will set up a dummy model to initialize tree heararchy.
* In a real code, you will connect to a real model and
* expose its hierarchy.
*/
private void initialize() {
TreeObject to1 = new TreeObject("Leaf 1");
TreeObject to2 = new TreeObject("Leaf 2");
TreeObject to3 = new TreeObject("Leaf 3");
TreeParent p1 = new TreeParent("Parent 1");
p1.addChild(to1);
p1.addChild(to2);
p1.addChild(to3);
TreeObject to4 = new TreeObject("Leaf 4");
TreeParent p2 = new TreeParent("Parent 2");
p2.addChild(to4);
TreeParent root = new TreeParent("Root");
root.addChild(p1);
root.addChild(p2);
invisibleRoot = new TreeParent("");
invisibleRoot.addChild(root);
}
}
class ViewLabelProvider extends LabelProvider {
public String getText(Object obj) {
return obj.toString();
}
public Image getImage(Object obj) {
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
if (obj instanceof TreeParent)
imageKey = ISharedImages.IMG_OBJ_FOLDER;
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}
}
class NameSorter extends ViewerSorter {
}
/**
* The constructor.
*/
public Variables() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
//new
Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("Name");
column1.setWidth(400);
TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
column2.setText("Value");
column2.setWidth(200);
//end new
drillDownAdapter = new DrillDownAdapter(viewer);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "com.Amazon.FuncE.viewer");
}
Right now what I have is two columns, but both show the same thing. How can I specify what kind of data goes into one column or the other?
Thanks
The issue is with your label provider. You are implementing an interface that doesn't give you ability to provide different text for different columns. You should implement ITableLabelProvider instead.
Related
I want to implement a Visitor for My class MyList. The List itself holds Elements of the type MyEntry. Those Entrys hold a generic Value and a reference to the next Entry in the List.
public class MyEntry<E> implements Visitable {
MyEntry<E> next;
E o;
MyEntry() {
this(null, null);
}
MyEntry(E o) {
this(o, null);
}
MyEntry(E o, MyEntry<E> e) {
this.o = o;
this.next = e;
}
public void accept(Visitor visitor) {
}
}
The List class
public class MyList<E> implements Visitable {
private MyEntry<E> begin;
private MyEntry<E> pos;
public MyList() {
pos = begin = new MyEntry<E>();
}
public void add(E x) {
MyEntry<E> newone = new MyEntry<E>(x, pos.next);
pos.next = newone;
}
public void advance() {
if (endpos()) {
throw new NoSuchElementException("Already at the end of this List");
}
pos = pos.next;
}
public void delete() {
if (endpos()) {
throw new NoSuchElementException("Already at the end of this List");
}
pos.next = pos.next.next;
}
public E elem() {
if (endpos()) {
throw new NoSuchElementException("Already at the end of this List");
}
return pos.next.o;
}
public boolean empty() {
return begin.next == null;
}
public boolean endpos() {
return pos.next == null;
}
public void reset() {
pos = begin;
}
#Override
public void accept(Visitor visitor) {
begin = pos;
while(pos.next != null && visitor.visit(pos.o)) {
//Move one Item forward
pos = pos.next;
}
}
I have implemented the Visitor interface to my ListVisitor class
public class ListVisitor implements Visitor {
public ListVisitor() {
}
#Override
public boolean visit(Object o) {
return false;
}
}
The Interface Visitor that will be implemented in every new Visitor that i want to create, for now i only have the ListVisitor
public interface Visitor<E> {
boolean visit(Object o);
}
And the Interface Visitable, that is implemented in every class i want to visit, in this case the MyList class and the MyEntry class.
public interface Visitable {
public void accept(Visitor visitor);
}
To test the implementation of the Visitor pattern I made a Testclass that creates a new Mylist and puts some Strings in it. Next it creates a new Visitor that visits the List.
import org.junit.Test;
public class MyListTest {
#Test
public void MyListTest() {
MyList s = new MyList();
s.add("Hello");
s.add("World");
s.add("!");
Visitor v = new Visitor() {
#Override
public boolean visit(Object o) {
System.out.println(o);
return true;
}
};
s.accept(v);
}
}
Now when I run MyListTest the output is:
null
!
World
My Question now is why the first Element that the Visitor visits has a null reference in it. When i add more items to my List before creating a Visitor the output always extends, except for the first item that has been inserted into the List, it will always be null.
Visitor pattern will not change the current code structure. It is used to add the new functionality in existing code. Classes which holds the new behaviors are commonly known as Visitors.
The classes and objects participating in this pattern are:
Visitor: It declares a Visit operation for each class of ConcreteElement in the object structure. The operation's name and
signature identify the class.
ConcreteVisitor: It implements each operation declared by the Visitor.
Element: It defines an Accept operation that takes a visitor as an argument.
ConcreteElement: It implements an Accept operation that takes a visitor as an argument.
ObjectStructure: It holds all the elements of the data structure as a collection, list of something which can be enumerated and used by
the visitors.
public abstract class Food {
public final string Name {
get {}
set {}
}
public final Decimal Price {
get {}
set {}
}
public final int Count {
get {}
set {}
}
public Food(string name, Decimal price, int count) {
this.Name = name;
this.Price = price;
this.Count = count;
}
public abstract void Accept(Visitor visitor);
}
public class Pizza extends Food {
public Pizza(string name, Decimal price, int count) {
super(name, price, count);
}
public override void Accept(Visitor visitor) {
visitor.Visit(this);
}
}
public class Pasta extends Food {
public Pasta(string name, Decimal price, int count) {
super(name, price, count);
}
public override void Accept(Visitor visitor) {
visitor.Visit(this);
}
}
public abstract class Visitor {
public abstract void Visit(Pasta pasta);
public abstract void Visit(Pizza pizza);
}
public class DiscountVisitor extends Visitor {
public override void Visit(Pasta pasta) {
var totalPrice = (pasta.Price * pasta.Count);
byte discount = 10;
pasta.Price = (totalPrice - (totalPrice * (discount / 100)));
}
public override void Visit(Pizza pizza) {
byte discount = 0;
if ((pizza.Count < 5)) {
discount = 10;
}
else if (((pizza.Count >= 5) && (pizza.Count < 20))) {
discount = 20;
}
else {
discount = 30;
}
var totalPrice = (pizza.Price * pizza.Count);
pizza.Price = (totalPrice - (totalPrice * (discount / 100)));
}
}
public class OrderList extends List<Food> {
public final void Attach(Food element) {
Add(element);
}
public final void Dettach(Food element) {
Remove(element);
}
public final void Accept(Visitor visitor) {
this.ForEach(() => { }, x.Accept(visitor));
}
public final void PrintBill() {
this.ForEach(() => { }, this.Print(x));
}
private final void Print(Food food) {
Console.WriteLine(string.Format("FoodName: {0}, Price:{1}, Count:{2}", food.Name, food.Price, food.Count));
}
}
}
OrderList orders = new OrderList();
orders.Add(new Pizza("pizza", 45000, 2));
orders.Add(new Pasta("pasta", 30000, 1));
DiscountVisitor visitor = new DiscountVisitor();
orders.Accept(visitor);
orders.PrintBill();
The SWT control classes Tree and Table have several methods with the same signature and that work in the same way.
For example:
getItems
getSelection
But these methods are defined directly on Tree and Table, there is no common super class or interface where the methods are declared. Because of this it is hard to write code that works for both Tree and Table.
Is there a solution to this that makes it possible to write common code for both of the classes?
One possible solution is to create a class with the common methods, with subclasses that wraps a Tree or a Table and that delegate these methods to their wrapped control.
Using such classes generic code can look like this:
CollectionControl c = CollectionControl.create(treeOrTable);
int nrItems = c.getSelectionCount();
The following is an example of such classes:
/**
* Wrapps a {#link Tree} or {#link Table} to make it possible to work with them
* in a generic way.
*
* This class could be an interface in Java 8, which allows static methods on interfaces.
*/
public abstract class CollectionControl {
public abstract CollectionItem[] getItems();
public abstract CollectionItem[] getSelection();
public abstract int getSelectionCount();
public abstract Control getControl();
public abstract int getColumnCount();
interface CollectionItem {
String getText(int columnIx);
}
/**
* #param control Either a {#link Tree} or {#link Table}..
* #return A collection which wraps the argument an delegate method calls to it.
* #throws IllegalArgumentException if the argument is not a Tree or a Table.
*/
public static CollectionControl create(Control control) {
if (control instanceof Tree) {
return new TreeControl((Tree) control);
} else if (control instanceof Table) {
return new TableControl((Table) control);
}
throw new IllegalArgumentException();
}
private static class TreeControl extends CollectionControl {
private Tree tree;
public TreeControl(Tree tree) {
this.tree = tree;
}
#Override
public CollectionItem[] getSelection() {
CollectionItem[] items = new CollectionItem[tree.getSelectionCount()];
int ix = 0;
for (TreeItem item : tree.getSelection()) {
items[ix++] = new TreeCollectionItem(item);
}
return items;
}
#Override
public int getSelectionCount() {
return tree.getSelectionCount();
}
#Override
public Tree getControl() {
return tree;
}
#Override
public CollectionItem[] getItems() {
CollectionItem[] items = new CollectionItem[tree.getItemCount()];
int ix = 0;
for (TreeItem item : tree.getItems()) {
items[ix++] = new TreeCollectionItem(item);
}
return items;
}
#Override
public int getColumnCount() {
return tree.getColumnCount();
}
private static class TreeCollectionItem implements CollectionItem {
private TreeItem item;
public TreeCollectionItem(TreeItem item) {
this.item = item;
}
#Override
public String getText(int columnIx) {
return item.getText(columnIx);
}
}
}
private static class TableControl extends CollectionControl {
private Table table;
public TableControl(Table table) {
this.table = table;
}
#Override
public CollectionItem[] getSelection() {
CollectionItem[] items = new CollectionItem[table.getSelectionCount()];
int ix = 0;
for (TableItem item : table.getSelection()) {
items[ix++] = new TableCollectionItem(item);
}
return items;
}
#Override
public int getSelectionCount() {
return table.getSelectionCount();
}
#Override
public Table getControl() {
return table;
}
#Override
public CollectionItem[] getItems() {
CollectionItem[] items = new CollectionItem[table.getItemCount()];
int ix = 0;
for (TableItem item : table.getItems()) {
items[ix++] = new TableCollectionItem(item);
}
return items;
}
#Override
public int getColumnCount() {
return table.getColumnCount();
}
private static class TableCollectionItem implements CollectionItem {
private TableItem item;
public TableCollectionItem(TableItem item) {
this.item = item;
}
#Override
public String getText(int columnIx) {
return item.getText(columnIx);
}
}
}
}
I have a TableView and a form with some TextBox and ComboBox in my javafx application. I am trying to populate the form components with selected rows data from TableView. I can populate all the TextBox without any error or exception. But while setting values to ComboBoxes, it's throwing an ClassCastException, java.lang.ClassCastException: java.lang.String cannot be cast to entity.StockUOM.
This is my StringCoverter
unitCombo.setConverter(new StringConverter<StockUOM>() {
#Override
public String toString(StockUOM object) {
return object.getStockUOM();
}
#Override
public StockUOM fromString(String string) {
return null;
}
});
This is my entity.StockUOM class
#Entity
#Access(AccessType.PROPERTY)
#NamedQueries({
#NamedQuery(name = StockUOM.findStockUOM, query = "SELECT s from StockUOM s")
})
public class StockUOM implements Externalizable{
public final static String PREFIX = "entity.StockUOM.";
public final static String findStockUOM = PREFIX + "findStockUOM";
private IntegerProperty id;
private int _id;
private StringProperty stockUOM;
private String _stockUOM;
public StockUOM() {
if (id == null) {
id = new SimpleIntegerProperty(this, "id", _id);
}
if( stockUOM== null){
stockUOM= new SimpleStringProperty(this,"stockUOM",_stockUOM);
}
}
public StockUOM(String stockUOM) {
this();
this.stockUOM.set(stockUOM);
}
public IntegerProperty idProperty() {
if (id == null) {
id = new SimpleIntegerProperty(this, "id", _id);;
}
return id;
}
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
public final int getId() {
if (id == null) {
return _id;
} else {
return id.get();
}
}
public final void setId(int id) {
if (this.id == null) {
_id = id;
} else {
this.id.set(id);
}
}
public StringProperty stockUOMProperty() {
if( stockUOM== null){
stockUOM= new SimpleStringProperty(this,"stockUOM",_stockUOM);
}
return stockUOM;
}
public final String getStockUOM() {
if(stockUOM == null){
return _stockUOM;
}else{
return stockUOM.get();
}
}
public void setStockUOM(String stockUOM) {
if (this.stockUOM == null) {
_stockUOM=stockUOM ;
} else {
this.stockUOM.set(stockUOM);
}
}
#Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(getId());
out.writeChars(getStockUOM());
}
#Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
setId(in.readInt());
setStockUOM((String)in.readObject());
}
#Override
public String toString() {
return getStockUOM();
}
}
This is how i am setting values to ComboBox
unitCombo.setValue(newValue.getUnit());
Here newValue is the instance of StockUOM of ChangeListner which is listening on TableView row selection.
So what's wrong i am doing ? And what's the solution.
Thanks.
The problem is that most probably you defined your ComboBox like:
ComboBox unitCombo = new ComboBox();
So you missed to define the generic argument and you ended up with the raw type (your IDE most probably gives you a warning on this line).
At this point it is not specified what kind of objects do you want to display in the ComboBox.
When you do the following:
unitCombo.setValue(newValue.getUnit());
you set the valueProperty as a String value.
And then comes your converter:
unitCombo.setConverter(new StringConverter<StockUOM>() {
#Override
public String toString(StockUOM object) {
return object.getStockUOM();
}
#Override
public StockUOM fromString(String string) {
return null;
}
});
which expects StockUOM object being displayed, which does not happen hence the error.
You have to decide what kind of object do you want to display: if it is StockUOM, then declare the ComboBox as ComboBox<StockUOM> unitCombo = new ComboBox<StockUOM>();. After this you will have a compile time error on the line where you set the value for a String value, to fix that error you have to modify that line as unitCombo.setValue(newValue);. If you want to display String objects, the methodology is the same.
What is the proper relationship, in code, between a table model and the actual database queries?
Inside the addRow() method in the table model, should I place a further call to my database class, which in turn inserts the row into the database? I've illustrated this in the below code snippets.
public class MainPanel extends JPanel
{
...
public MainPanel()
{
personTableModel = new PersonTableModel();
personTable = new JTable(personTableModel);
...
insertButton = new JButton("Insert");
insertButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String name = nameTextBox.getText();
String address = addressTextBox.getText();
Object[] row = { name, address };
personTableModel.addRow(row); // <--- Add row to model
}
});
}
}
public class PersonTableModel extends AbstractTableModel
{
private List<Object[]> data;
private List<String> columnNames;
PersonDB personDB = new PersonDB();
...
public void addRow(Object[] row)
{
// insert row into 'data'
personDB.addPerson(row); // <---- Call the personDB database class
}
...
}
public class PersonDB
{
public PersonDB()
{
// establish database connection
}
public addPerson(Object[] row)
{
// code that creates a SQL statement based on row data
// and inserts new row into database.
}
...
}
Whether or not you should directly make an insert call depends on some aspects:
Do you want other processes to access the data immediately?
Do you fear that your program crashes and you lose important information?
Can you ensure that any data persisted during addRow is meaningful (the program could terminate directly after the insert)?
Than of course it may be a good idea to directly insert the data into the backing Database.
You should however watch out, that there are two variants of addRow and two variants of insertRow. DefaultTableModel directs calls internally through insertRow(int, Vector), which would probably be the only function to overwrite, if you want to immediately persist data.
If you like the proposed idea of DTOs the examples below may help you.
The Idea is to represent "Entities" or table rows as classes in Java. A DTO is the simplest representation and normally only contains fields with respective getter and setter.
Entities can generically be persisted and loaded through ORM libraries like EclipseLink or Hibernate. Additionally for this table-application the use of DTOs provide a way of storing data not shown to the user in a clean and typed way.
DTO:
public class PersonDto {
private Long id;
private String name;
private String street;
public PersonDto() {
}
public PersonDto(Long id, String name, String street) {
this.id = id;
this.name = name;
this.street = street;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public static class NameColumn extends DtoTableModel.ColumnProvider<PersonDto, String> {
public NameColumn() {
super("Name", String.class);
}
#Override
public String getValue(PersonDto dto) {
return dto.getName();
}
#Override
public void setValue(PersonDto dto, Object value) {
dto.setName((String) value);
}
}
public static class StreetColumn extends DtoTableModel.ColumnProvider<PersonDto, String> {
public StreetColumn() {
super("Street", String.class);
}
#Override
public String getValue(PersonDto dto) {
return dto.getStreet();
}
#Override
public void setValue(PersonDto dto, Object value) {
dto.setStreet((String) value);
}
}
}
DTO based TableModel:
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
public class DtoTableModel<T> extends AbstractTableModel {
private final ArrayList<T> rows;
private final ArrayList<ColumnProvider<T, ?>> columns;
protected DtoTableModel() {
rows = new ArrayList<T>();
columns = new ArrayList<ColumnProvider<T, ?>>();
}
#Override
public int getRowCount() {
return rows.size();
}
#Override
public int getColumnCount() {
return columns.size();
}
#Override
public Object getValueAt(int rowIndex, int columnIndex) {
return columns.get(columnIndex).getValue(rows.get(rowIndex));
}
#Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
#Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
final ColumnProvider<T, ?> column = columns.get(columnIndex);
column.setValue(rows.get(rowIndex), aValue);
this.fireTableCellUpdated(rowIndex, columnIndex);
}
#Override
public String getColumnName(int column) {
return columns.get(column).getTitle();
}
public void addColumn(ColumnProvider<T, ?> column) {
this.columns.add(column);
this.fireTableStructureChanged();
}
public void addRow(T row) {
this.rows.add(row);
this.fireTableRowsInserted(this.rows.size() - 1, this.rows.size() - 1);
}
#Override
public Class<?> getColumnClass(int columnIndex) {
return this.columns.get(columnIndex).getValueClass();
}
public static abstract class ColumnProvider<T, V> {
private String title;
private final Class<V> valueClass;
protected ColumnProvider(String title, Class<V> valueClass) {
this.title = title;
this.valueClass = valueClass;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Class<V> getValueClass() {
return valueClass;
}
public abstract V getValue(T dto);
public abstract void setValue(T dto, Object value);
}
}
Example-"Application":
import javax.swing.*;
import java.awt.*;
public class JTableTest extends JFrame {
private final JTable jTable;
public JTableTest() throws HeadlessException {
super("JFrame test");
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
final GridBagLayout layout = new GridBagLayout();
final Container contentPane = this.getContentPane();
contentPane.setLayout(layout);
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
final DtoTableModel<PersonDto> dm = new DtoTableModel<PersonDto>();
jTable = new JTable(dm);
dm.addColumn(new PersonDto.NameColumn());
dm.addColumn(new PersonDto.StreetColumn());
dm.addRow(new PersonDto(1L, "Paul", "Mayfairy Street"));
dm.addRow(new PersonDto(2L, "Peter", "Ferdinand Street"));
JScrollPane scrollpane = new JScrollPane(jTable);
contentPane.add(scrollpane, gridBagConstraints);
this.pack();
}
public static void main(String[] args) {
final JTableTest jTableTest = new JTableTest();
jTableTest.setVisible(true);
}
}
I use the MGWT CellList which works perfect.
I have the following problem. How can I keep selected cells selected such that the remain selected after the user releases the cell?
Here is my implementation:
CellList<Item> myCellList = new CellList<Item>(new ItemCell());
My ItemCell class:
public class ItemCell implements Cell<Item> {
private static Template TEMPLATE = GWT.create(Template.class);
public interface Template extends SafeHtmlTemplates {
#SafeHtmlTemplates.Template("<div>{0}</div>")
SafeHtml content(String cellContents);
}
#Override
public void render(SafeHtmlBuilder safeHtmlBuilder, Item model) {
SafeHtml content = TEMPLATE.content(model.getName());
safeHtmlBuilder.append(content);
}
#Override
public boolean canBeSelected(Item model) {
return true;
}
}
My Item class:
public class Item {
private String name;
public Item() {
setName("");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
What you want is selection handler. If you want single slection use SingleSelectionHandler, if you want multiple selections use MultiSelectionHandler,
Sample code :
SelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
cellList.setSelectionModel(selectionModel);
if you want to do anything on selection you can do it here
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
/** Do your thing here **/
selectionModel.getSelectedObject(); //for single Selection
selectionModel.getSelectedSet(); //for multiple Selection
}
});