package com.vci.client.uif.actions.client;
|
|
import java.util.Map;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.fm.FileObject;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 文档文件下载按钮
|
* 对于下载操作,需要在按钮中配置fileObject oid所在字段
|
* 下载操作始终针对的是BO对象,如果按钮获得的输入时LO时加载LO的FROM端或TO端对象
|
* 加一个参数是否调用系统的默认打开方式
|
* @author VCI-STGK006
|
*
|
*/
|
public class DownloadAction extends AbstractBatchBusionessOperationAction {
|
|
/**
|
* 操作方法
|
*/
|
private UIFUtils operation =
|
new UIFUtils();
|
|
/**
|
* 文件上传下载方法
|
*/
|
private FileOperation fopreation = new FileOperation();
|
|
public DownloadAction(){
|
super();
|
}
|
|
@Override
|
public String getKey() {
|
return DOWNLOAD;
|
}
|
|
@Override
|
public boolean checkHasRight(){
|
// 按BO进行数据权限检查
|
setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B);
|
return super.checkHasRight();
|
}
|
|
@SuppressWarnings("unchecked")
|
@Override
|
public boolean doPost() {
|
try {
|
//显示创建窗口
|
Map<String, String> paramsMap = getButtonParams();
|
String oidField = paramsMap.get("oid");
|
String direction = paramsMap.get("direction");
|
String open = paramsMap.get("open");
|
if(oidField == null || oidField.equals("")){
|
oidField = "oid";
|
}
|
if(direction == null || direction.equals("")){
|
direction = "true";
|
}
|
if(open == null || open.equals("")){
|
open = "false";
|
}
|
|
//基本信息
|
boolean isOpen = open.equals("true")? true : false;
|
boolean isDirection = direction.equals("false")? false : true;
|
|
//得到用户选择数据
|
Object[] selectedObjects = getDataModel().getSelectObjects();
|
|
//根据不同的参数获得所有FileObject对象的OID
|
String[] foOids = new String[selectedObjects.length];
|
for(int i = 0; i< selectedObjects.length; i++){
|
if(selectedObjects[i] instanceof Map){
|
foOids[i] = ((Map<String, String>) selectedObjects[i]).get("OID");
|
} else if (selectedObjects[i] instanceof IDataNode){
|
Object mainObject = ((IDataNode)selectedObjects[i]).getMaterObject();
|
if(mainObject instanceof ClientBusinessObject){
|
foOids[i] = ((ClientBusinessObject) mainObject).getAttributeValue(oidField);
|
} else if(mainObject instanceof ClientLinkObject){
|
String oid = "";
|
String btmName = "";
|
if(isDirection){
|
oid = ((ClientLinkObject) mainObject).getLinkObject().toOid;
|
btmName = ((ClientLinkObject) mainObject).getLinkObject().toBTName;
|
} else {
|
oid = ((ClientLinkObject) mainObject).getLinkObject().fromOid;
|
btmName = ((ClientLinkObject) mainObject).getLinkObject().fromBTName;
|
}
|
//加载BO对象
|
ClientBusinessObject cbo = operation.reloadClientBusinessObject(
|
ClientContextVariable.getFrame(), oid, btmName);
|
if(cbo != null){
|
foOids[i] = cbo.getAttributeValue(oidField);
|
}
|
}
|
}
|
}
|
//判断附件是否存在
|
if(foOids == null || foOids.length < 1
|
|| (foOids.length == 1 && (foOids[0] == null || foOids[0].equals("")))){
|
UIFUtils.showMessage(null, "uifmodel.plm.uif.actions.download.filenotexist", "");
|
return false;
|
}
|
//判断是下载文件还是打开文件
|
if(isOpen){
|
if(!fopreation.openFile(foOids)){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.downloadfileerror", new Exception("文件不存在!"));
|
}
|
} else {
|
FileObject[] fos = fopreation.downloadFile(ClientContextVariable.getFrame(), foOids, "");
|
if(fos == null){
|
return false;
|
}
|
String fileName = "";
|
if(fos.length > 0 && fos.length <= 5){
|
for(FileObject fo : fos){
|
fileName += ";" + fo.getBusinessObject().name;
|
}
|
}
|
if(!fileName.equals("")){
|
fileName = fileName.substring(1);
|
}
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.downloadfilesuccessmsg",fileName);
|
}
|
return false;
|
} catch (Exception e){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.downloadfileerror", e);
|
return false;
|
}
|
}
|
|
}
|