使用TableViewer动态增加一行值时老是报错

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import dbclass.BarCode;
import dbclass.BarcodeEntity;
import dbdao.BarCodeDao;


public class SellerShell {
MainShell mainshell = new MainShell();
private Text goodsText;
//BarcodeEntity bce=new BarcodeEntity();
private TableViewer tv;
private List savalist;


public void opensheller(String seller) {
MainShell.shell.setVisible(false);
Shell newShell = new Shell(SWT.CLOSE|SWT.MIN);
SWTUtils.setCenter(newShell);
newShell.setText("销售窗口");
newShell.setSize(700,500);
newShell.setLayout(new GridLayout());
//newShell.setLayout(new FillLayout(SWT.VERTICAL));
newShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (!MainShell.shell.isVisible())
MainShell.shell.setVisible(true);
}
});
//窗口中的版块
GridData gd=null;
Composite header=new Composite(newShell,SWT.BORDER);
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
header.setLayout(new GridLayout(4,false));

Label hd_lb1=new Label(header,SWT.NONE);
// gd=new GridData();
// gd.horizontalSpan=4;
// hd_lb1.setLayoutData(gd);
hd_lb1.setLayoutData(createGridData(GridData.BEGINNING, 4));
hd_lb1.setText("销售员"+seller);

Label hd_lb2=new Label(header,SWT.NONE);
GridData hd_lb2_gd=new GridData();
hd_lb2_gd.horizontalIndent=100;
hd_lb2.setLayoutData(hd_lb2_gd);
hd_lb2.setText("请输入商品防伪条码");

goodsText = new Text(header,SWT.BORDER|SWT.RIGHT);
goodsText.setLayoutData(new GridData(150,-1));
//goodsText.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 2));

Button smite=new Button(header,SWT.PUSH);
smite.setText("确定");
//窗口中部
Composite body=new Composite(newShell,SWT.BORDER);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
body.setLayout(new FillLayout());

tv=new TableViewer(body,SWT.MULTI|SWT.BORDER|SWT.FULL_SELECTION);
Table table=tv.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableLayout layout=new TableLayout();
table.setLayout(layout);
layout.addColumnData(new ColumnWeightData(30));
new TableColumn(table,SWT.NONE).setText("ID号");
layout.addColumnData(new ColumnWeightData(40));
new TableColumn(table,SWT.NONE).setText("商品名称");
layout.addColumnData(new ColumnWeightData(10));
new TableColumn(table,SWT.NONE).setText("单价");
layout.addColumnData(new ColumnWeightData(15));
new TableColumn(table,SWT.NONE).setText("购买数量");
layout.addColumnData(new ColumnWeightData(10));
new TableColumn(table,SWT.NONE).setText("合计");
tv.setContentProvider(new TableViewerContentProvider());
tv.setLabelProvider(new TableViewerLabelProvider());
//Object data=PeopleFactory.getPeoples();
////
// BarcodeEntity bce=new BarcodeEntity();
// smite.addSelectionListener(new SmiteSelectionListener(tv,bce,goodsText.getText()));
smite.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){

ArrayList bc_list=new BarCodeDao().getGoodsArrayList(goodsText.getText());
if(bc_list!=null){
Iterator itor=bc_list.iterator();
while (itor.hasNext()) {
BarcodeEntity bce=new BarcodeEntity();
BarCode barcode=(BarCode)itor.next();
bce.setBar_code(barcode.getBar_code());
bce.setGoods_name(barcode.getGoods_name());
bce.setGoods_price(barcode.getGoods_price());
bce.setGoods_count(1);
bce.setTotal(barcode.getGoods_price());

System.out.println(bce.getBar_code());
System.out.println(bce.getGoods_name());
System.out.println(bce.getGoods_count());
System.out.println(bce.getGoods_price());

tv.add(bce);

System.out.println(bce.getBar_code());
savalist=(List)tv.getInput();
savalist.add(bce);
System.out.println(bce.getBar_code());
}
return;
}
}
});


//窗口底部
Composite footer=new Composite(newShell,SWT.BORDER);
footer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
footer.setLayout(new GridLayout(4,false));
Label ft_lb=new Label(footer,SWT.NONE);
ft_lb.setText("总价");
Text ft_text=new Text(footer,SWT.BORDER|SWT.READ_ONLY|SWT.RIGHT);
new Label(footer,SWT.NONE).setText("元     ");
Button ft_add=new Button(footer,SWT.PUSH);
ft_add.setText("结算");

//System.out.print(ft_text.getTopPixel()+" "+ft_text.getTopIndex());
Button ft_print=new Button(footer,SWT.PUSH);
ft_print.setLayoutData(new GridData(GridData.END));
GridData ft_print_gd=new GridData();
ft_print_gd.horizontalSpan=4;
ft_print_gd.horizontalAlignment=GridData.END;
ft_print_gd.horizontalIndent=500;
ft_print.setLayoutData(ft_print_gd);
ft_print.setText("打印清单");
// int x=newShell.getSize().x;
// int y=newShell.getSize().y;
// System.out.print(x+"           "+y+"\n");



newShell.open();

}
private GridData createGridData(int style,int horizontalSpan){
GridData griddata=new GridData(style);
griddata.horizontalSpan=horizontalSpan;
return griddata;
}
}
就是在savalist.add(bce);
这一行老是报错,一运行到这一行,界面就自己没有了。希望哪位高手帮我解决一下,很急,毕业设计的。
另外其它的类都是按严格要求写的,应该没有错。

你可能感兴趣的:(eclipse)