/*
* Created on 2004/08/03 Author aki@www.xucker.jpn.org License Apache2.0 or
* Common Public License
*/
package org.jpn.xucker.commons.swt.series;
import org.apache.commons.lang.ArrayUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class ResultDialog implements SelectionListener {
/**
* @param shell
*
*/
private Table table1;
private Button button1;
Shell shell;
private String[] labelName;
private int[] labelWidth;
public ResultDialog(Shell shell,String labelName[],int labelWidth[]) {
this.shell = shell;
this.labelName=(String[])ArrayUtils.clone(labelName);
this.labelWidth=ArrayUtils.clone(labelWidth);
if(labelName.length!=labelWidth.length){
throw new RuntimeException("labelName and labelWidth size is different");
}
shell.setBounds(0, 0, 300, 300);
RowLayout layout = new RowLayout();
shell.setLayout(layout);
table1 = new Table(shell, SWT.FULL_SELECTION);
table1.setHeaderVisible(true);
table1.addSelectionListener(this);
RowData table1_data = new RowData();
table1_data.width=270;
table1_data.height=220;
table1.setLayoutData(table1_data);
for(int i=0;i<labelName.length;i++){
TableColumn table1_column = new TableColumn(table1, SWT.NULL);
table1_column.setText(labelName[i]);
table1_column.setWidth(labelWidth[i]);
}
button1 = new Button(shell, SWT.NULL);
button1.setText("•Â‚¶‚é");
button1.addSelectionListener(this);
RowData button1_data = new RowData();
button1.setLayoutData(button1_data);
}
public void widgetSelected(SelectionEvent event) {
Object target = event.getSource();
if (target == null) {
//maybe not happen.
System.out.println("target==null");
}
//null1
else if (target == table1) {
do_table1();
}
// null1
else if (target == button1) {
do_button1();
}
}
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
//null1
public void do_table1() {
//System.out.println("table1");
}
// null1
public void do_button1() {
shell.close();
}
/**
* @param data
*/
public void setResultData(ResultData[] data) {
for (int i = 0; i < data.length; i++) {
String values[]=new String[labelName.length];
for(int j=0;j<labelName.length;j++){
values[j]=data[i].getValue(labelName[j]);
}
TableItem item=new TableItem(table1,SWT.NULL);
item.setText(values);
}
}
}
|