package com.vci.client.uif.actions.client;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.JOptionPane;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientBusinessObjectOperation;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.bof.ClientLinkObjectOperation;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
|
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
|
import com.vci.client.uif.engine.common.ClientLOAndBOData;
|
import com.vci.client.uif.engine.common.DefaultTableNode;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 选择保存按钮
|
* XXX 暂时不考虑批量选择的情况, 但是代码中加入了一些批量添加的判断
|
* @author VCI-STGK006
|
*
|
*/
|
public class ChooseSaveAction extends DoseNotSelectDataAction{
|
|
/**
|
* 操作方法
|
*/
|
private UIFUtils operation =
|
new UIFUtils();
|
|
/**
|
* 业务对象操作方法
|
*/
|
private ClientBusinessObjectOperation boOperation = new ClientBusinessObjectOperation();
|
|
/**
|
* link对象操作方法
|
*/
|
private ClientLinkObjectOperation loOperation = new ClientLinkObjectOperation();
|
|
/**
|
* 判断是创建有link属性的BO,还是创建没有link属性的BO
|
* 0:无link属性(业务类型),1:有link属性(有链接属性)
|
*/
|
private int operationType = 0;
|
|
/**
|
* 按钮参数信息
|
*/
|
private Map<String, String> paramsMap;
|
|
@Override
|
public String getKey() {
|
return "choosesave";
|
}
|
|
@Override
|
public boolean checkHasRight(){
|
return true;
|
}
|
|
@Override
|
public boolean doPost() {
|
try {
|
|
//获得按钮参数
|
paramsMap = getButtonParams();
|
String linkType = paramsMap.get("linktype");
|
//用户输入属性 期中以t_oid开始的为业务对象属性,其它为link对象属性
|
//获得按钮所属窗口,此窗口一定要是一个弹出窗口
|
//并且窗口的类型一定是ObjectAddEditDialog
|
ObjectAddEditDialog oaed = null;
|
VCIJDialog dialog = getOwnerDialog();
|
if(dialog instanceof ObjectAddEditDialog){
|
oaed = (ObjectAddEditDialog) dialog;
|
}
|
if(oaed == null){
|
return false;
|
}
|
//设置linktype
|
if(oaed.getDefination().getLinkType() != null
|
&& !oaed.getDefination().getLinkType().equals("")){
|
linkType = oaed.getDefination().getLinkType();
|
}
|
//得到主对象对象,根据主对象得到From BO
|
ClientBusinessObject from = null;
|
IDataNode sourceData = oaed.getSourceDataNode();
|
Object fromObj = sourceData.getMaterObject();
|
if(fromObj instanceof ClientBusinessObject){
|
from = (ClientBusinessObject) fromObj;
|
} else if(fromObj instanceof ClientLinkObject) {
|
//如果是LO对象,使用LO对应TO端BO对象作为创建的From对象
|
ClientLinkObject fromLO = (ClientLinkObject) fromObj;
|
from = getToBusinessObject(fromLO);
|
}
|
//验证from对象
|
if(from == null
|
|| from.getBusinessObject().oid == null
|
|| from.getBusinessObject().oid.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.createlinkerror.fromdelete");
|
return false;
|
}
|
//得到所有选择的to端对象
|
//得打选择的to端数据,现在只支持选择一个BO对象
|
ClientBusinessObject to = null;
|
Object[] selectedDatas = oaed.getSelectedDatas();
|
if(selectedDatas == null){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.choosesave.noselect");
|
return false;
|
}
|
List<ClientBusinessObject> toBoList = new ArrayList<ClientBusinessObject>();
|
for(Object obj : selectedDatas){
|
//重新下载用户选择的对象
|
DefaultTableNode dtn = (DefaultTableNode) obj;
|
//已经在选择的时候经行过数据的类型的校验,此处不再经行校验直接转换
|
ClientBusinessObject cbo = (ClientBusinessObject) dtn.getMaterObject();
|
if(cbo != null && cbo.getBusinessObject().oid != null
|
&& !cbo.getBusinessObject().oid.equals("")){
|
toBoList.add(cbo);
|
}
|
}
|
|
//From端已经存在的LINK对象,用来端选择是否重复
|
Map<String,ClientBusinessObject> existtoMap = new HashMap<String,ClientBusinessObject>();
|
ClientLinkObject[] existClos;
|
try {
|
existClos = loOperation.readLinkObjectByFromBO(from, linkType);
|
if(existClos != null && existClos.length > 0){
|
for(int i = 0; i<existClos.length; i++){
|
String oid = existClos[i].getToOid();
|
String btmName = existClos[i].getToBTMName();
|
ClientBusinessObject tempto = boOperation.readBusinessObjectById(oid, btmName);
|
if(tempto != null){
|
existtoMap.put(oid, tempto);
|
}
|
}
|
}
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
//获得使用的表单类型
|
operationType = oaed.getTypeFlag();
|
//获得用户设置数据是 IDataNode类型
|
Object obj = getDataModel().getRootObject();
|
if(obj == null){
|
return false;
|
}
|
IDataNode idn = (IDataNode) obj;
|
//根据表单类型判断要执行的操作
|
ClientLinkObject clo = null;
|
boolean result = false;
|
if(this.operationType == 0){
|
//按钮参数linktype放在此处校验,因为当使用LO的from创建时,linktype直接使用了Form对应的类型
|
if(linkType == null || linkType.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.configerror.nolinktype");
|
return false;
|
}
|
//判读选择的TO端对象是否存在
|
if(toBoList != null && !toBoList.isEmpty()){
|
for(int i = 0; i < toBoList.size(); i++){
|
//验证to端对象是否已经存在
|
if(existtoMap.get(toBoList.get(i).getBusinessObject().oid) != null){
|
int confirm = VCIOptionPane.showConfirmDialog(
|
ClientContextVariable.getFrame(),"对象“"
|
+ toBoList.get(i).getBusinessObject().name
|
+"”已经存在,继续添加系统将会忽略“"+ toBoList.get(i).getBusinessObject().name
|
+"”!\n是否继续执行添加操作?", "系统提示",JOptionPane.YES_NO_OPTION);
|
if(confirm == JOptionPane.NO_OPTION){
|
return false;
|
}
|
continue;
|
}
|
//创建一个空的link对象
|
clo = operation.createEmptyClientLinkObject(
|
ClientContextVariable.getFrame(), linkType);
|
clo.setFromBO(from);
|
clo.setToBO(toBoList.get(i));
|
to = toBoList.get(i);
|
}
|
}
|
} else if (this.operationType == 1){
|
//如果表单类型是1,可以再Form中直接获得要创建的LO和BO对象
|
ClientLOAndBOData clbo = (ClientLOAndBOData) idn.getMaterObject();
|
List<ClientLinkObject> loList = clbo.getLoDatas();
|
if(loList.isEmpty()){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.createloerror", new Exception("系统异常:没有找到link对象"));
|
return false;
|
}
|
//在创建保存link中只会有一个LO对象
|
clo = loList.get(0);
|
to = clbo.getBOData(clo.getLinkObject().oid);
|
clo.setToBO(to);
|
}
|
//保存link对象 如果link保存失败则终止执行
|
if(oaed.isDirection()){
|
clo.setFromBO(from);
|
clo.setToBO(to);
|
} else {
|
clo.setFromBO(to);
|
clo.setToBO(from);
|
}
|
|
result = loOperation.saveLinkObject(new ClientBusinessObject[0], clo);
|
|
if(!result){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.createlinkerror");
|
return false;
|
}
|
closeOwnerDailog(getOwnerDialog(), DialogResult.OK);
|
|
return true;
|
} catch (Exception e){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
|
return false;
|
}
|
}
|
|
/**
|
* 查询LO对象TO端的BO对象
|
* @param clo
|
* @return
|
* @throws Exception
|
*/
|
public ClientBusinessObject getToBusinessObject(ClientLinkObject clo) throws Exception{
|
ClientBusinessObject cbo = null;
|
String btmName = clo.getLinkObject().toBTName;
|
String oid = clo.getLinkObject().toOid;
|
cbo = operation.reloadClientBusinessObject(
|
ClientContextVariable.getFrame(), oid, btmName);
|
return cbo;
|
}
|
}
|