Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » how to use ListDataProvider class...(package
icon5.gif  how to use ListDataProvider class... [message #991710] Thu, 20 December 2012 02:54 Go to next message
lau alex is currently offline lau alexFriend
Messages: 3
Registered: June 2012
Junior Member

i want to use MouseListener (mouseDoubleClick) get the current object.

object o = ListDataProvider.getRowObject(int rowIndex);

how to write in the mouselistener, or other implementation method。

please help.... Embarrassed Embarrassed Embarrassed Embarrassed Embarrassed Embarrassed

example :

package com.eoilio.mrpii.ui.currency;

 * Copyright (c) 2012 Original authors and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * Contributors:
 *     Original authors and others - initial API and implementation

import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.layer.cell.CellOverrideLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.springframework.context.ApplicationContext;

import ca.odell.glazedlists.GlazedLists;

import com.eoilio.mrpii.dao.AppContext;
import com.eoilio.mrpii.dao.Currencycodedata;
import com.eoilio.mrpii.dao.CurrencycodedataDAO;
import com.eoilio.mrpii.ui.widget.nattable.AbstractNatExample;
import com.eoilio.mrpii.ui.widget.nattable.extension.builder.NatTableBuilder;
import com.eoilio.mrpii.ui.widget.nattable.extension.builder.model.TableColumn;
import com.eoilio.mrpii.ui.widget.nattable.extension.builder.model.TableModel;

public class CurrencyBuilder extends AbstractNatExample implements MouseListener {
	private NatTableBuilder<Currencycodedata> builder;
	private NatTable natTable;

	public Control createExampleControl(Composite parent) {
		ApplicationContext appCon = AppContext.CreateApplicationContext();
		CurrencycodedataDAO dao = (CurrencycodedataDAO) appCon
		TableColumn[] columns = new TableColumn[] {
				new TableColumn(0, "code", "编码").setWidth(60).setCategory("A"),
				new TableColumn(1, "name", "币别").setWidth(60).setCategory("A"),
				new TableColumn(2, "exchange", "汇率").setWidth(80).setCategory(
				new TableColumn(3, "commutedDes", "折算方式").setWidth(200)
						.setCategory("A") };
		TableModel table = new TableModel(columns);

		builder = new NatTableBuilder<Currencycodedata>(parent, table,

		// Setup all the layer stacks
		natTable = builder.setupLayerStacks();
		// Since the build() method has not been invoked yet you can
		// tweak layer configuration as you want

	private void customize() {
		Style style = new Style();

		ListDataProvider<Currencycodedata> bodyDataProvider = builder
		CellOverrideLabelAccumulator<Currencycodedata> myAccumulator = new CellOverrideLabelAccumulator<Currencycodedata>(
		myAccumulator.registerOverride("AAA", 2, "myLabel");

		IConfigRegistry configRegistry = natTable.getConfigRegistry();
				style, DisplayMode.NORMAL, "myLabel");

	public void mouseDoubleClick(MouseEvent event) {
		// TODO Auto-generated method stub

	public void mouseDown(MouseEvent event) {
		// TODO Auto-generated method stub

	public void mouseUp(MouseEvent event) {
		// TODO Auto-generated method stub

Re: how to use ListDataProvider class... [message #991956 is a reply to message #991710] Thu, 20 December 2012 14:49 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2374
Registered: July 2012
Senior Member

there are several ways to achieve this.

1. Use tight coupling, which might be working for your example.
public void mouseDoubleClick(MouseEvent e) {
	//get the row position for the click in the NatTable
	int rowPos = natTable.getRowPositionByY(e.y);
	//transform the NatTable row position to the row position of the body layer stack
	int bodyRowPos = LayerUtil.convertRowPosition(natTable, rowPos, gridLayer.getBodyLayer());
	Currencycodedata ccd = bodyDataProvider.getRowObject(bodyRowPos);
	//Do something with ccd

2. You might want to use the selection provider mechanism
// Provides rows where any cell in the row is selected
ISelectionProvider selectionProvider = new RowSelectionProvider<Person>(gridLayer.getBodyLayer().getSelectionLayer(), bodyDataProvider, false);
selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
	public void selectionChanged(SelectionChangedEvent event) {
		System.out.println("Selection changed:");
		IStructuredSelection selection = (IStructuredSelection) event.getSelection();
		Iterator it = selection.iterator();
		while (it.hasNext()) {
			System.out.println("  " +;

The second code example is out of the Get_and_set_selected_objects examples of the NatTable examples.

Hope that helps,
Re: how to use ListDataProvider class... [message #1065493 is a reply to message #991956] Wed, 26 June 2013 06:10 Go to previous message
lau alex is currently offline lau alexFriend
Messages: 3
Registered: June 2012
Junior Member
thanks for your achieve.
you give me a better way to achieve this.

I use selection provider have something wrong
Previous Topic:Making columns sortable
Next Topic:about ListDataProvider.getRowObject(int rowIndex) Method of use
Goto Forum:

Current Time: Wed Mar 29 15:22:57 GMT 2017

Powered by FUDForum. Page generated in 0.02118 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software