package com.vci.client.uif.actions.client;
|
|
import java.awt.Component;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.Map;
|
import javax.swing.ComboBoxModel;
|
import javax.swing.text.JTextComponent;
|
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.portal.utility.PLDefination;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.components.VCIJComboBox;
|
import com.vci.client.uif.engine.client.UIHelper;
|
import com.vci.client.uif.engine.client.controls.VCIJComboBoxModelValueObject;
|
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
|
import com.vci.client.uif.engine.common.DefaultTableNode;
|
import com.vci.corba.portal.data.PortalVI;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* link类型修改按钮事件
|
* @author VCI-STGK006
|
*
|
*/
|
public class BrowserLinkAction extends AbstractBusionessOperationAction {
|
|
/**
|
* 方法集合
|
*/
|
private UIFUtils operation =
|
new UIFUtils();
|
/**
|
* 将操作的业务对象作为一个全局变量存储
|
*/
|
private Map<String, Object> dataMap = null;
|
|
/**
|
* 判断form的类型
|
* 不同的form类型得到属性的key是不同的
|
* 0:业务类型,1:链接类型
|
*/
|
private int operationType = 0;
|
|
/**
|
* 按钮参数
|
*/
|
private Map<String, String> paramsMap = null;
|
|
public BrowserLinkAction(){
|
super();
|
}
|
|
@Override
|
public String getKey() {
|
return BROWSERLINK;
|
}
|
|
@Override
|
public boolean checkHasRight(){
|
// 按BO进行数据权限检查
|
setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_L);
|
return super.checkHasRight();
|
}
|
|
@Override
|
public boolean doPost() {
|
//显示创建窗口
|
try{
|
//获得按钮参数
|
paramsMap = getButtonParams();
|
//得到打开窗口的上下文信息
|
String type = paramsMap.get("type");
|
String context = paramsMap.get("context");
|
if(type == null || type.equals("") || context == null || context.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.parmerror", "");
|
return false;
|
}
|
//获得按钮打开窗口的PLDefination
|
PLDefination plDef = getDefination(type, context);
|
if(plDef == null){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.configerror.notformname", type, context);
|
return false;
|
}
|
String formName = plDef.getTemplateId();
|
if(formName == null || formName.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.configerror.notformname", type, context);
|
return false;
|
}
|
//判断创建表单类型
|
PortalVI sheet = UITools.getService().getPortalVIBySymbol(formName);
|
if(sheet != null){
|
this.operationType = sheet.typeFlag;
|
}
|
|
// 得到业务对象、设置需要显示的属性值
|
dataMap = getBusinessObject();
|
if(dataMap == null){
|
return false;
|
}
|
//创建浏览窗口
|
ObjectAddEditDialog oad = new ObjectAddEditDialog(type, context,
|
plDef, paramsMap, ObjectAddEditDialog.OperateType.BROWSER, null, this);
|
oad.setTypeFlag(1);
|
oad.init();
|
oad.setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
|
oad.setLocationRelativeTo(ClientContextVariable.getFrame());
|
//设置窗口字段值
|
setEditDialogValue(oad, dataMap);
|
oad.setVisible(true);
|
} catch(Throwable e){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.editloerror", e);
|
}
|
return true;
|
}
|
|
/**
|
* 设置窗口属性值
|
* 需要在创建编辑窗口初始化完成后执行设置操作
|
* @return
|
*/
|
private void setEditDialogValue(ObjectAddEditDialog oad, Map<String,Object> dataMap){
|
HashMap<String, Component> comptMap = oad.getCtrlComptMap();
|
//遍历所有属性
|
for(Iterator<String> i = comptMap.keySet().iterator(); i.hasNext();){
|
String field = i.next();
|
//获得属性名称对应的属性值
|
String fieldText = "";
|
if(this.operationType == 0) {
|
fieldText = operation.getBusinessObejctAttrValue((ClientBusinessObject)dataMap.get("to"), field);
|
} else if(this.operationType == 1) {
|
fieldText = operation.getLinkObejctAttrValue(
|
(ClientLinkObject)dataMap.get("lo"),(ClientBusinessObject)dataMap.get("to"), field);
|
}
|
Component compt = comptMap.get(field);
|
|
if(compt instanceof JTextComponent){
|
//如果是文本框、直接设置文本内容
|
((JTextComponent)compt).setText(fieldText);
|
} else if(compt instanceof VCIJComboBox){
|
//如果是选择框 设置选项选中
|
VCIJComboBox cbx = (VCIJComboBox)compt;
|
ComboBoxModel model = cbx.getModel();
|
//遍历所有下拉框选项
|
for(int j = 0; j < model.getSize(); j++){
|
Object Obj = model.getElementAt(j);
|
if(Obj instanceof VCIJComboBoxModelValueObject){
|
VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj;
|
//比较是否与业务对象属性值相同
|
if(fieldText.equals(vo.getValue())){
|
model.setSelectedItem(vo);
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 得到用户选择的业务对象数据
|
* @return
|
*/
|
private Map<String, Object> getBusinessObject(){
|
//获得业务对象数据
|
Object[] objs = getDataModel().getSelectObjects();
|
if(objs == null || objs.length < 1){
|
return null;
|
}
|
//查询结果
|
Map<String, Object> resultMap = new HashMap<String, Object>();
|
//modify 2014.03.09 start
|
DefaultTableNode dtn = (DefaultTableNode) objs[0];
|
try {
|
//判断主对象类型,修改link是主对象类型一定是link对象
|
if (dtn.getMaterObject() instanceof ClientLinkObject){
|
ClientLinkObject lo = (ClientLinkObject) dtn.getMaterObject();
|
String foid = lo.getFromOid();
|
String fbtmName = lo.getFromBTMName();
|
String toid = this.getParameterValue(ValueType.RuntimeData, "t_oid", 0);
|
String tbtmName = this.getParameterValue(ValueType.RuntimeData, "t_btwname", 0);
|
//如果操作所需参数不存在则直接停止操作
|
if(foid == null || foid.equals("") ||fbtmName == null || fbtmName.equals("")
|
|| toid == null || toid.equals("") ||tbtmName == null || tbtmName.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.parmerror.bo");
|
return null;
|
}
|
//下载from对象
|
ClientBusinessObject fcbo = operation
|
.reloadClientBusinessObject(ClientContextVariable.getFrame(), foid, fbtmName);
|
//对象不存在或者已经被删除
|
if(fcbo.getBusinessObject().oid == null || fcbo.getBusinessObject().oid.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.notexistmsg", "父对象");
|
return null;
|
}
|
resultMap.put("from", fcbo);
|
//下载to对象
|
ClientBusinessObject tcbo = operation
|
.reloadClientBusinessObject(ClientContextVariable.getFrame(), toid, tbtmName);
|
//对象不存在或者已经被删除
|
if(tcbo.getBusinessObject().oid == null || tcbo.getBusinessObject().oid.equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.notexistmsg", "子对象");
|
return null;
|
}
|
resultMap.put("to", tcbo);
|
//添加link
|
resultMap.put("lo", lo);
|
} else {
|
//主对象为其他类型的处理
|
|
}
|
} catch (Exception e){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),e);
|
return null;
|
}
|
//modify 2014.03.09 end
|
return resultMap;
|
}
|
}
|