package com.vci.client.uif.actions.client; import java.util.HashMap; import java.util.Map; import com.vci.client.portal.utility.PLDefination; import com.vci.client.portal.utility.UITools; 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; /** * 业务类型创建按钮事件 * 接受参数为btmname、context * @author VCI-STGK006 * */ public class AddAction extends DoseNotSelectDataHasRightCheckAction{ /** * 按钮参数 */ private Map paramsMap = null; /** * 是否需要先选择数据然后执行创建操作 * 默认为false */ boolean needSelect = false; public AddAction(){ super(); } @Override public String getKey() { return ADD; } /** * 判断执行Action任务之前是否需要先选择数据 */ public boolean beforePost() { if(!super.beforePost()){ return false; } //获得按钮参数 paramsMap = getButtonParams(); if(paramsMap.containsKey("needselect")){ String value = paramsMap.get("needselect"); if(value.equalsIgnoreCase("true")){ needSelect = true; } } if(needSelect){ if(!isSelectedObject()) return false; } return true; } @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 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; idn = getRegionPanel().getSourceData(); //默认增加新增窗口的来源对象 by zgy 2015-02 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 map = new HashMap(); map.put("AddShowLinkAbs", currentDef.getShowLinkAbs()); map.put("AddSeparator", currentDef.getSeparator()); map.put("AddCreateFolder", "true"); if (obj[0] instanceof IDataNode){ idn = (IDataNode) obj[0]; } if(idn.getValueMap() == null) { idn.setValueMap(map); } else { idn.getValueMap().putAll(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 map = new HashMap(); // 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]); } // add by xchao 2015.08.12 // 设置新打开的上下文模块的inputdata // 设置值类型:sourceData、inputData、selectData oad = super.setTargetUILayoutPanelInputData(oad); // add by xchao 2015.08.12 end 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; } } }