1、需要在页面加载时绘制table控件,并填充数据
2、需要在特定的单元格进行监听事件,用来进行下载功能
protected void kDTable1_tableDataRequest(KDTDataRequestEvent e)
throws Exception {
// TODO Auto-generated method stub
super.kDTable1_tableDataRequest(e);
KDTable table = this.kDTable1;
table.getStyleAttributes().setLocked(true);
//表头
for(int i=0;i<3;i++){
table.addColumn();
table.getColumn(i).setWidth(120);
}
IRow row1 = table.addHeadRow(0);
row1.getCell(0).setValue("序号");
row1.getCell(1).setValue("附件名称");
row1.getCell(2).setValue("上传日期");
//附件
String boId = null;
if(editData.getId() == null)
return;
boId = editData.getId().toString();
//List attachmentList = AttachmentUtils.getAttachmentListByBillID(boId);
AttachmentClientManager ac = AttachmentManagerFactory.getClientManager();
String strs[] = ac.getAttachmentIDsByBoID(boId);
System.out.println("attchment.id:"+Arrays.toString(strs));
int n = 0;
// if(attachmentList != null){
// n = attachmentList.size();
// }
if( strs != null ){
n = strs.length;
}
//内容
IRow row;
for(int i=0;i<n;i++){
row = table.addRow(i);
AttachmentInfo atInfo = AttachmentFactory.getRemoteInstance().getAttachmentInfo(new ObjectUuidPK(strs[i]));
for(int j=0;j<3;j++){
if(j == 0){
row.getCell(j).setValue(i+1);
}else if(j == 1){
row.getCell(j).setValue(atInfo.getName());
}else{
row.getCell(j).setValue(atInfo.getCreateTime());
}
}
}
table.addKDTMouseListener(new KDTMouseListener(){
public void tableClicked(KDTMouseEvent e) {
// TODO Auto-generated method stub
String boId = editData.getId().toString();
if(e.getClickCount() == 1){
if(e.getColIndex() == 1){
AttachmentClientManager ac = AttachmentManagerFactory.getClientManager();
try {
String strs[] = ac.getAttachmentIDsByBoID(boId);
System.out.println("-----str:"+strs[e.getRowIndex()]);
downloadAttachment1(strs[e.getRowIndex()]);
//downloadAttachment(strs[e.getRowIndex()], "D:\\");
} catch (BOSException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
}
});
}
private void downloadAttachment1(String attchID){
AttachmentClientManager ac = AttachmentManagerFactory.getClientManager();
try {
ac.downloadAttachment(attchID,this);
System.out.println("---down:");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}