日期:2014-05-20  浏览次数:20926 次

遇到个问题不会写了,求帮助
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

import antsoldier.agent.mergefilter.bean.FileterFactory;
import antsoldier.agent.mergefilter.bean.Filter;
import antsoldier.agent.mergefilter.provider.TableviewerContentProvider;
import antsoldier.agent.mergefilter.provider.TableviewerTableLabelProvider;
import cn.antvision.soldier.portal.widgets.antdialog.AntDialog;

public class FilterDialog extends AntDialog {

private Filter filter;
CheckboxTableViewer ctv;

public FilterDialog(String title, String desc, Filter filter) {
super(title, desc, 0, 0);
// TODO Auto-generated constructor stub
}

@Override
protected void createArea(Composite parent) {
// TODO Auto-generated method stub
Composite tablecopo = new Composite(parent, SWT.NONE);

tablecopo.setLayout(new GridLayout());
Composite composite = new Composite(tablecopo, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setLayout(new FillLayout());

TableViewer tv = new TableViewer(composite, SWT.CHECK | SWT.MULTI
| SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
ctv = new CheckboxTableViewer(tv.getTable());

Table table = tv.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);

TableLayout tlayout = new TableLayout();
table.setLayout(tlayout);
tv.setContentProvider(new TableviewerContentProvider());
tv.setLabelProvider(new TableviewerTableLabelProvider());

tlayout.addColumnData(new ColumnWeightData(20));
new TableColumn(table, SWT.NONE);
tlayout.addColumnData(new ColumnWeightData(60));
new TableColumn(table, SWT.NONE).setText("字段");
tlayout.addColumnData(new ColumnWeightData(120));
new TableColumn(table, SWT.NONE).setText("描述");
tv.setInput(FileterFactory.getF());
tv.addDoubleClickListener(new IDoubleClickListener() {

@Override
public void doubleClick(DoubleClickEvent event) {
// TODO Auto-generated method stub

}
});

}

public int open() {

addListener();

return super.open();
}

private void addListener() {
// TODO Auto-generated method stub
addSelectionListener(ANTDIALOG_OK, new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
if (ctv != null) {
Object[] checkObj = ctv.getCheckedElements(); // 取得打勾的记录
if (checkObj.length== 0) {// 判断是否有勾选复选框
MessageDialog.openInformation(null, "提示", "请先勾选记录");
return;
}

for (int i = 0; i < checkObj.length; i++) {
Filter o = (Filter) checkObj[i];
List<Filter> list = new ArrayList<Filter>();
list.add(o);
}
}
close(0);
}
});