Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » about ListDataProvider.getRowObject(int rowIndex) Method of use(nattable use MouseListener DoubleClick get the current object.)
icon5.gif  about ListDataProvider.getRowObject(int rowIndex) Method of use [message #991714] Thu, 20 December 2012 03:06 Go to next message
lau alex is currently offline lau alexFriend
Messages: 3
Registered: June 2012
Junior Member
Embarrassed

hello:

how to use package org.eclipse.nebula.widgets.nattable.data;
ListDataProvider<T> getRowObject(int rowIndex) ;

in the mouseEvent
public void mouseDoubleClick(MouseEvent event) {
		// TODO Auto-generated method stub
		System.out.println(event.toString());
	}

or other implementation method on mouseDoubleClick get the current row object.

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
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * 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.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.layer.cell.CellOverrideLabelAccumulator;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.style.Style;
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
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
				.getBean("CurrencycodedataDAO");
		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(
						"A"),
				new TableColumn(3, "commutedDes", "折算方式").setWidth(200)
						.setCategory("A") };
		TableModel table = new TableModel(columns);

		builder = new NatTableBuilder<Currencycodedata>(parent, table,
				GlazedLists.eventList(dao.findAll()),
				Currencycodedata.rowIdAccessor);

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

	private void customize() {
		Style style = new Style();
		style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR,
				GUIHelper.COLOR_RED);

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

		builder.addCellLabelsToBody(myAccumulator);
		
		IConfigRegistry configRegistry = natTable.getConfigRegistry();
		configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE,
				style, DisplayMode.NORMAL, "myLabel");
	}

	@Override
	public void mouseDoubleClick(MouseEvent event) {
		// TODO Auto-generated method stub
		System.out.println(event.toString());
	}

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

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

}
Re: about ListDataProvider.getRowObject(int rowIndex) Method of use [message #991958 is a reply to message #991714] Thu, 20 December 2012 14:49 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
This seems to be the same question as here http://www.eclipse.org/forums/index.php/t/441881/

So you will find the answer there.
Previous Topic:how to use ListDataProvider class...
Next Topic:Getting Data from the DB to the NatTable?
Goto Forum:
  


Current Time: Fri Apr 26 19:39:47 GMT 2024

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

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

Back to the top