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
}
}