package com.vci.client.uif.actions.client;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.swing.JOptionPane;
|
|
import com.vci.client.portal.utility.PLDefination;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.client.ui.swing.components.VCIJDialog.DialogResult;
|
import com.vci.client.uif.engine.client.UIHelper;
|
import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.corba.portal.data.PortalVI;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 扩展AddAction功能
|
* 实现功能,判断getDataModel().getSelectObjects()是否为空
|
* 如果不为空,基于SelectObjects进行创建,如果为空,基于DataSource
|
* 进行创建。
|
*
|
* 在AddAction基础上增加exttype,extcontext,needselect参数不再起作用。
|
* 当getDataModel().getSelectObjects()是否为空时上下文使用type,context
|
* 为空时使用exttype,extcontext。
|
*
|
* 相关按钮,保存、取消和AddAction一致。
|
*
|
* @author VCI-STGK006
|
*
|
*/
|
public class ExtAddAction extends DoseNotSelectDataAction{
|
/**
|
* 按钮参数
|
*/
|
private Map<String, String> paramsMap = null;
|
|
/**
|
* 根据getDataModel().getSelectObjects()是否为空
|
* 设置needSelect的值,如果不为空为true。
|
*/
|
boolean needSelect = false;
|
|
public ExtAddAction(){
|
super();
|
}
|
|
@Override
|
public String getKey() {
|
return "extadd";
|
}
|
|
@Override
|
public boolean doPost() {
|
try{
|
//获得按钮参数
|
paramsMap = getButtonParams();
|
//得到打开窗口的上下文信息
|
String type = paramsMap.get("type");
|
String context = paramsMap.get("context");
|
String extType = paramsMap.get("exttype");
|
String extContext = paramsMap.get("extcontext");
|
if(type == null || type.trim().equals("")
|
|| context == null || context.trim().equals("")
|
||extType == null || extType.trim().equals("")
|
||extContext == null || extContext.trim().equals("")){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.parmerror", "");
|
return false;
|
}
|
//判断用户是否选择了数据
|
if(getDataModel().getSelectObjects() != null
|
&& getDataModel().getSelectObjects().length > 0) {
|
//判断,只能单选
|
if(getDataModel().getSelectObjects().length > 1){
|
VCIJOptionPane.showMessageDialog(
|
getParentComponent(), "最多选择一条数据进行此操作!", "提示", JOptionPane.INFORMATION_MESSAGE);
|
return false;
|
}
|
needSelect = true;
|
paramsMap.put("needselect", "true");
|
} else {
|
type = extType;
|
context = extContext;
|
}
|
//当前按钮所在窗口的PLDefination
|
PLDefination currentDef = getDefination();
|
//打开窗口的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;
|
}
|
//验证是否是创建BO类型
|
PortalVI sheet = UITools.getService().getPortalVIBySymbol(formName);
|
if(sheet.typeFlag != 0){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.syserror.btnconferror");
|
return false;
|
}
|
|
//如果是文件夹类型
|
//做了一下特殊处理,如果是创建文件夹时,在SourceDataNode的ValueMap中增加了一个AddShowLinkAbs属性
|
IDataNode idn = null;
|
if(currentDef.getTemplateType().equals("5")
|
&& currentDef.getLinkType().equals("")
|
&& !currentDef.getShowLinkAbs().equals("")) {
|
//获得当前节点作为创建节点的父节点
|
Object[] obj = getDataModel().getSelectObjects();
|
if(obj == null || obj.length < 1){
|
UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.folder.selectparent");
|
return false;
|
}
|
Map<String, String> map = new HashMap<String, String>();
|
map.put("AddShowLinkAbs", currentDef.getShowLinkAbs());
|
map.put("AddSeparator", currentDef.getSeparator());
|
map.put("AddCreateFolder", "true");
|
if (obj[0] instanceof IDataNode){
|
idn = (IDataNode) obj[0];
|
}
|
idn.setValueMap(map);
|
}
|
// if("folder".equalsIgnoreCase(plDef.getShowType())){
|
// //获得当前节点作为创建节点的父节点
|
// Object[] obj = getDataModel().getSelectObjects();
|
// if(obj == null || obj.length < 1){
|
// UIFUtils.showMessage(ClientContextVariable.getFrame(),
|
// "uifmodel.plm.uif.actions.folder.selectparent");
|
// return false;
|
// }
|
// Map<String, String> map = new HashMap<String, String>();
|
// map.put("AddShowLinkAbs", currentDef.getShowLinkAbs());
|
// map.put("AddSeparator", currentDef.getSeparator());
|
// if (obj[0] instanceof IDataNode){
|
// idn = (IDataNode) obj[0];
|
// }
|
// idn.setValueMap(map);
|
// }
|
//defination信息
|
//PLDefination defination = getDefination();
|
//生成创建窗口
|
ObjectAddEditDialog oad = new ObjectAddEditDialog(type, context,
|
plDef, paramsMap, ObjectAddEditDialog.OperateType.ADD, null, this);
|
oad.setSourceDataNode(idn);
|
oad.setSelectObjects(getDataModel().getSelectObjects());
|
oad.setTypeFlag(0);
|
if(needSelect){
|
oad.setSourceDataNode((IDataNode)getDataModel().getSelectObjects()[0]);
|
}
|
oad.init();
|
oad.setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
|
oad.setLocationRelativeTo(ClientContextVariable.getFrame());
|
oad.setVisible(true);
|
if(oad.getDialogResult() == DialogResult.OK){
|
return true;
|
} else {
|
return false;
|
}
|
} catch (Throwable e){
|
UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
|
"uifmodel.plm.uif.actions.createloerror", e);
|
return false;
|
}
|
}
|
}
|