package com.vci.client.uif.actions.client; import java.awt.Component; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import javax.swing.JOptionPane; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientLinkObject; import com.vci.client.common.ConfigUtils; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.logon.base.TabPanelManage; import com.vci.client.omd.provider.BtmProvider; import com.vci.client.portal.utility.DataModelFactory; import com.vci.client.portal.utility.PLDefination; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.JClosableTabbedPane; import com.vci.client.ui.swing.components.VCIJDialog; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJDialog.DialogResult; import com.vci.client.uif.engine.client.IDataModel; import com.vci.client.uif.engine.client.IRegionPanel; import com.vci.client.uif.engine.client.UILayoutPanel; import com.vci.client.uif.engine.client.controls.FileChooseControlPanel; import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog; import com.vci.client.uif.engine.client.tableArea.TablePanel; import com.vci.client.uif.engine.common.GlobalContextParam; import com.vci.client.uif.engine.common.IDataNode; import com.vci.corba.common.VCIError; import com.vci.corba.common.data.VCIInvocationInfo; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.framework.data.CheckValue; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLUILayout; import com.vci.corba.portal.data.PLTabButton; import com.vci.corba.portal.data.PLTabPage; import com.vci.corba.portal.data.PortalVI; import com.vci.mw.ClientContextVariable; /** * 抽象的单数据操作接口封装 * @author xchao * */ public abstract class AbstractBatchBusionessOperationAction implements BusinessOperationAction { private Map buttonParams = new HashMap(); private Component parentComponent = null; private IDataModel dataModel = null; private PLDefination defination = null; private PLTabButton button = null; private VCIJDialog ownerDialog = null; private IRegionPanel regionPanel = null; /** * Action配置信息 */ private PLAction action = null; private Component buttonComponent = null; public AbstractBatchBusionessOperationAction(){ } @Override public void setButtonParams(Map buttonParams){ this.buttonParams = buttonParams; } @Override public Map getButtonParams(){ return this.buttonParams; } @Override public Component getParentComponent(){ return this.parentComponent; } @Override public void setParentComponent(Component parentComponent){ this.parentComponent = parentComponent; } /** * 设置 Action 所在区域的DataModel * @param dataModel */ @Override public void setDataModel(IDataModel dataModel){ this.dataModel = dataModel; } /** * 返回 Action 所在区域的DataModel * @return */ @Override public IDataModel getDataModel(){ return this.dataModel; } /** * 设置Button 对应的 Action 所在的Defination * @param defination */ public void setDefination(PLDefination defination){ this.defination = defination; } /** * 返回 Button 对应的 Action 所在的Defination * @return */ public PLDefination getDefination(){ return this.defination; } /** * 设置 Button * @param button */ public void setButton(PLTabButton button){ this.button = button; } /** * 返回 与此Action关联对应的Button * @return */ public PLTabButton getButton(){ return this.button; } protected int getPreeventCount(){ int def = 10; int res = def; String preeventCountValue = getParameterValue(ValueType.ButtonConfig, "preeventCount", 1); if(preeventCountValue == null || "".equals(preeventCountValue)){ return def; } else { try{ res = Integer.valueOf(preeventCountValue); }catch(Exception ex){ return def; } } return res; } protected int getPostEventCount(){ int def = 10; int res = def; String preeventCountValue = getParameterValue(ValueType.ButtonConfig, "posteventCount", 1); if(preeventCountValue == null || "".equals(preeventCountValue)){ return def; } else { try{ res = Integer.valueOf(preeventCountValue); }catch(Exception ex){ return def; } } return res; } private String getClassNameDefPreFix(String classNameDef){ String prefix = ""; if(classNameDef == null) { return ""; } classNameDef = classNameDef.trim(); if("".equals(classNameDef)) { return ""; } if (classNameDef.length() > 7 && classNameDef.toLowerCase().indexOf("net_") == 0) { prefix = classNameDef.substring(0, 6); if (prefix.toLowerCase().equals("net_cs")) { prefix = "net_cs"; classNameDef = classNameDef.substring(7); }else if (prefix.toLowerCase().equals("net_bs")) { prefix = "net_bs"; classNameDef = classNameDef.substring(7); } }else if (classNameDef.length() > 8 && classNameDef.toLowerCase().indexOf("java_") == 0) { prefix = classNameDef.substring(0, 7); if (prefix.toLowerCase().equals("java_cs")) { prefix = "java_cs"; classNameDef = classNameDef.substring(8); }else if (prefix.toLowerCase().equals("java_bs")) { prefix = "java_bs"; classNameDef = classNameDef.substring(8); } }else if (classNameDef.length() > 10 && classNameDef.toLowerCase().indexOf("mobile_") == 0) { prefix = classNameDef.substring(0, 9); if (prefix.toLowerCase().equals("mobile_cs")) { prefix = "mobile_cs"; classNameDef = classNameDef.substring(10); }else if (prefix.toLowerCase().equals("mobile_bs")) { prefix = "mobile_bs"; classNameDef = classNameDef.substring(10); } } return prefix; } protected boolean getPreeventResult(String className){ if(className == null) { return true; } className = className.trim(); if("".equals(className)) { return true; } //edit start by lmh20151223.在一个值中配置多个事件,用;号分隔,分别前后触发 String[] classNames = className.split(";"); boolean res = true; for(String name : classNames) { String prefix = this.getClassNameDefPreFix(name); if (!(prefix.equals("") || prefix.equals("java_cs"))) { return true; }else { if (prefix.equals("java_cs")) { name = name.substring(prefix.length() + 1); } } //前置事件对象实例化 PostActionListener pal = createPostActionListenerInstance(name); if(pal == null) { return true; } //前置事件参数对象 PostActionEvent pae = new PostActionEvent(); //pae.setSource(this);//当前Action对象 --目前如果都是this对象传入,那么先不赋值(以便插件获取参数的清晰) pae.setBusinessOperationAction(this);//当前业务对象 try { PostActionResult par = pal.actionPerformed(pae); //触发事件 res = par.isSuccess(); String message = par.getLastErrorMessage(); if(!par.isSuccess() && !"".equals(message)){ UIFUtils.showMessage(ClientContextVariable.getFrame(), message); break;//lizf add 20160621如果当前的前置事件饭后的是false,则跳出循环。 } } catch (Exception e) { e.printStackTrace(); res = false; //终止 UIFUtils.showMessage(ClientContextVariable.getFrame(), e.getMessage()); } } //edit end return res; } private PostActionListener createPostActionListenerInstance(String className){ PostActionListener pal = null; try { if (className != null && !className.equals("")) { Object obj = Class.forName(className).getConstructor().newInstance(); if(obj instanceof PostActionListener){ pal = (PostActionListener)obj; } } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return pal; } protected boolean isSelectedObject(){ IDataModel dataModel = getDataModel(); if(getDataModel() == null) { VCIJOptionPane.showMessageDialog( ClientContextVariable.getFrame(), " dataModel is null", "提示", JOptionPane.WARNING_MESSAGE); System.out.println(getClassName() + ".doAction() execute, getDataModel() result is null"); return false; } Object[] objs = dataModel.getSelectObjects(); if(objs == null){ VCIJOptionPane.showMessageDialog( ClientContextVariable.getFrame(), "请选择数据再进行此操作!", "提示", JOptionPane.INFORMATION_MESSAGE); System.out.println(getClassName() + ".doAction() execute, getDataModel().getSelectObjects() result is null"); return false; } else if(objs.length == 0){ VCIJOptionPane.showMessageDialog( ClientContextVariable.getFrame(), "请选择数据再进行此操作!", "提示", JOptionPane.INFORMATION_MESSAGE); System.out.println(getClassName() + ".doAction() execute, getDataModel().getSelectObjects().length = 0 "); return false; } else if(objs != null && objs.length == 0) { return false; } return true; } /** * Action框架主入口,继承复写请慎重... * @Title :doAction * @Description : * @return */ public boolean doAction(){ boolean res = false; if(!isSelectedObject()) return false; //判断是否需要进行数据权限校验 String rightSwitch = ConfigUtils.getConfigValue("right.switch"); if(rightSwitch != null && rightSwitch.equals("on")){ // 权限检查,有权限时才执行后续的操作 if(!checkHasRight()){ VCIJOptionPane.showMessageDialog( ClientContextVariable.getFrame(), sbBatchCheckHasRightMessage.toString(), "提示", JOptionPane.INFORMATION_MESSAGE); return false; } } // 在选定了数据及有权限之后,执行 res = doActionDetailBySelectedObject(); return res; } @Override //Modify by ZhongGY 2015-05-29 public boolean beforePost() { return true; } protected boolean getAllPreEventResult(){ boolean res = true; String className = getParameterValue(ValueType.ButtonConfig, "preevent", 1); res &= getPreeventResult(className); if (res == false) { return false; //前置事件主要存在错误就退出 ADD By ZhongGY } int preEventCount = getPreeventCount(); //同事也支持多事件 for (int i = 0; (i <= preEventCount); i++) { //&& res == true className = getParameterValue(ValueType.ButtonConfig, "preevent" + String.valueOf(i), 1); res &= getPreeventResult(className); if (res == false) { return false; //前置事件主要存在错误就退出 ADD By ZhongGY } } return res; } /** * //ADD by ZhongGY 2015-05-29 --保证Action本身能的前置事件能触发 * @Title :rawBeforePost * @Description : * @return */ private boolean rawBeforePost() { boolean res = false; if ((res = beforePost())) { res = getAllPreEventResult(); } return res; } /** * Action真实处理入口 * @Title :doActionDetailBySelectedObject * @Description : * @return */ protected boolean doActionDetailBySelectedObject(){ boolean res = false; // 有权限时,先执行 beforePost() // 当且仅当 beforePost() == true 时,才执行 doPost() if(rawBeforePost()){ res = doPost(); // 当且仅当 doPost() == true 时,才执行 afterPost() if(res){ res = rawAfterPost(); // 当且仅当 afterPost() == true 时,才执行 getDataModel().refresh() ,即刷新 if(res){ afterPostAfterRefresh(); } } } return res; } /** * //ADD by ZhongGY 2015-05-29 --保证Action本身能的后置事件能触发 * @Title :rawAfterPost * @Description : * @return */ private boolean rawAfterPost() { //System.out.println(getClassName() + ".afterPost() execution"); boolean res = true; //先处理Button自定义的后处理事件 String className = getParameterValue(ValueType.ButtonConfig, "postevent", 1); res &= getPostEventResult(className); //后置事件之间默认是连续执行(哪怕是前一事件有错误) By ZhongGY int preEventCount = getPostEventCount(); //支持多事件(默认10个) for (int i = 0; (i <= preEventCount && res == true); i++) { className = getParameterValue(ValueType.ButtonConfig, "postevent" + String.valueOf(i), 1); res &= getPostEventResult(className); } //再处理Action本身的后处理事件 return res && afterPost(); //保证Action本身的后置事件也能触发 } /** * Button(定义的)后处理事件触发 --ADD By ZhongGY 2015-05-29 * @Title :getPostEventResult * @Description : * @param className * @return */ protected boolean getPostEventResult(String className){ if (className == null || className.trim().equals("")) { return true; } String prefix = this.getClassNameDefPreFix(className); if (!(prefix.equals("") || prefix.equals("java_cs"))) { return true; }else { if (prefix.equals("java_cs")) { className = className.substring(prefix.length() + 1); } } //edit start by lmh20151223.在一个值中配置多个事件,用;号分隔,分别前后触发 String[] classNames = className.split(";"); boolean res = true; for(String name : classNames) { //前置事件对象实例化 PostActionListener pal = createPostActionListenerInstance(className); if(pal == null) { return true; } //前置事件参数对象 PostActionEvent pae = new PostActionEvent(); //pae.setSource(this);//当前Action对象 pae.setBusinessOperationAction(this);//当前业务对象 try { //getDataModel().refresh(getDataModel()); //保证后处理的相关数据为Post()之后刷新的数据 ADD By ZhongGY PostActionResult par = pal.actionPerformed(pae); //触发事件 res = par.isSuccess(); String message = par.getLastErrorMessage(); if(!par.isSuccess() && !"".equals(message)){ UIFUtils.showMessage(ClientContextVariable.getFrame(), message); } } catch (Exception e) { e.printStackTrace(); res = true; UIFUtils.showMessage(ClientContextVariable.getFrame(), e.getMessage()); } } //edit end return res; } /** //Modify by ZhongGY 2015-05-29 * Action行为处理后事件 * 返回True表示要触发界面刷新 */ @Override public boolean afterPost() { return true; } private Object afterPostDataExt = null; /** * AfterPost事件与事件之间可需要额外特殊处理的数据 * @Title :getAfterPostDataExt * @Description : * @return */ public Object getAfterPostDataExt() { return afterPostDataExt; } /** * AfterPost事件与事件之间可需要额外特殊处理的数据 * @Title :setAfterPostDataExt * @Description : * @param afterPostDataExt */ public void setAfterPostDataExt(Object afterPostDataExt){ this.afterPostDataExt = afterPostDataExt; } protected void afterPostAfterRefresh(){ getDataModel().refresh(getDataModel()); // add by xchao 2014.10.27 begin // 根据按钮参数定义,在结束后,是否需要进行UI全刷新 String refreshValue = getParameterValue(ValueType.ButtonConfig, "refresh", -1); if(refreshValue != null && Boolean.valueOf(refreshValue)){ refreshUI(); } // add by xchao 2014.10.27 end } private void refreshUI(){ JClosableTabbedPane tab = TabPanelManage.getInstance().getTabPanel(); for (int i = 0; i < tab.getTabCount(); i++) { Component compt = tab.getComponent(i); if(compt instanceof UILayoutPanel){ UILayoutPanel uilayout = (UILayoutPanel)compt; refreshUILayoutModel(uilayout); } } } private void refreshUILayoutModel(UILayoutPanel uilayoutPanel){ Map map = uilayoutPanel.getRegionPanelMap(); Iterator its = map.keySet().iterator(); while(its.hasNext()){ String key = its.next(); IRegionPanel regionPanel = map.get(key); if(regionPanel instanceof TablePanel){ TablePanel tablePanel = (TablePanel)regionPanel; tablePanel.getDataTablePanel().refreshTableData(); } } } private StringBuffer sbBatchCheckHasRightMessage = new StringBuffer(); //增加一个全局的变量用来存储需要进行数据权限的数据 private Object checkObj = null; private Object[] getCheckObjects() { if(this.checkObj != null) { return new Object[]{checkObj}; } else { return getDataModel().getSelectObjects(); } } private int[] getCheckRowIndexs() { if(this.checkObj != null) { return new int[]{1}; } else { return getDataModel().getSelectObjectRowIndexs(); } } public void setCheckObject(Object checkObj) { this.checkObj = checkObj; } //end @Override public boolean checkHasRight() { // add by xchao 2014.08.20 显示的根据按钮中定义的参数,确定是否需要进行数据权限校验 boolean res = false; String ignoredr = this.getParameterValue(ValueType.ButtonConfig, "ignoredr", -1); if("true".equalsIgnoreCase(ignoredr)){ return true; } // add by xchao 2014.08.20 end StringBuffer sbNotRightRowIndex = new StringBuffer(); int[] rows = getCheckRowIndexs(); Object[] objs = getCheckObjects(); Boolean[] hasRights = new Boolean[objs.length]; boolean allTrue = true; DataRightUtil dRU= new DataRightUtil(this.buttonParams); for (int i = 0; i < objs.length; i++) { boolean checkRes = false;//checkHasRight(objs[i], this.getButtonParams()); // V2 String dataRightCheckType = getDataRightCheckType(); Object seledObj = objs[i]; String key = getKey(); try { checkRes=dRU.getCheckRes(dataRightCheckType,seledObj,key); } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } // add by xchao 2015.01.14 begin // 将没有权限的数据索引添加单独的结构中维护,以便统一输出提示信息 if(!checkRes){ sbNotRightRowIndex.append(String.valueOf(rows[i] + 1)).append("、"); } // add by xchao 2015.01.14 end hasRights[i] = checkRes; // 按位与,确定是否对全部数据有权限 allTrue &= checkRes; } //权限校验完成后清空临时全局变量 this.checkObj = null; res = allTrue; // add by xchao 2015.01.14 begin // 按统一的方式提示没有权限 sbBatchCheckHasRightMessage = new StringBuffer(""); if(!allTrue && sbNotRightRowIndex.length() > 0){ String rowIndexStr = sbNotRightRowIndex.toString(); if(rowIndexStr.endsWith("、")){ rowIndexStr = rowIndexStr.substring(0, rowIndexStr.length() - 1); } sbBatchCheckHasRightMessage.append("您没有权限对第\n" + rowIndexStr + "\n条数据进行此操作!"); } // add by xchao 2015.01.14 end return res; } private String getButtonParamLinkType(){ String res = ""; res = getParameterValue(ValueType.ButtonConfig, "linktype", -1); if(res == null){ res = getParameterValue(ValueType.ButtonConfig, "linkType", -1); if(res == null){ res = getParameterValue(ValueType.ButtonConfig, "LinkType", -1); if(res == null){ res = ""; } } } return res; } /** * 1、对于一个按钮可能是业务类型,也可能是链接类型, * 但是在操作时用户选择的数据可能是LO,也可能BO, * 所以在校验试需要根据按钮的类型来判断传递的oid * 和businesstype是什么值 * 2、 * @param selectedObject 用户选择的数据 * @return */ protected boolean checkHasRight(Object selectedObject, Map buttonParam){ // add by xchao 2014.08.20 显示的根据按钮中定义的参数,确定是否需要进行数据权限校验 boolean res = false; String ignoredr = this.getParameterValue(ValueType.ButtonConfig, "ignoredr", -1); if("true".equalsIgnoreCase(ignoredr)){ return true; } // add by xchao 2014.08.20 end try { String rightCheckType = null; String rightCheckLogical = null; String boOpReflect = null; Iterator itor = buttonParam.keySet().iterator(); //TODO //对单独的link进行鉴权处理 //对to端link进行测试 while (itor.hasNext()) { String key = itor.next(); if (key == null) { continue; } if (key.equals(RightCheckConstants.RIGHT_CHECK_TYPE)) { rightCheckType = buttonParam.get(key); } else if (key.equals(RightCheckConstants.RIGHT_CHECK_LOGICAL)) { rightCheckLogical = buttonParam.get(key); } else if (key.equals(RightCheckConstants.BO_OP_REFLECT)) { boOpReflect = buttonParam.get(key); } } String[][] result = new String[2][]; String[] boResult = null; String[] loResult = null; if (rightCheckType == null || rightCheckType.equals("")) { boResult = getCheckObject(selectedObject); } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_B)) { boResult = this.getBOcheckObject(selectedObject); } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_L)) { loResult = this.getLOcheckObject(selectedObject); } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_FB)){ boResult = this.getFromBOCheckObject(selectedObject); } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_TB)){ boResult = this.getToBOCheckObject(selectedObject); } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_LFB)){ result = this.getLoFromBOCheckObject(selectedObject); boResult = result[0]; loResult = result[1]; } else if (rightCheckType.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_TYPE_LTB)){ result = this.getLoToBOCheckObject(selectedObject); boResult = result[0]; loResult = result[1]; } boolean[] checkRes = new boolean[2]; checkRes[0] = false; checkRes[1] = false; String opname = getKey(); if (boResult != null && boResult.length != 0) { if (boOpReflect != null) { opname = boOpReflect; } checkRes[0] = getCheckResult(boResult, opname); } if (loResult != null && loResult.length != 0) { opname = loResult[4] + "." + getKey(); checkRes[1] = getCheckResult(loResult, opname); } // for (int i = 0; i < 2; i++) { // if (result[i] == null || result[i].length == 0) { // continue; // } // if (i == 0 && boOpReflect != null) { // opname = boOpReflect; // } else if (i == 1){ // opname = result[i][4] + "." + getKey(); // } // checkRes[i] = getCheckResult(result[i], opname); // } if (rightCheckLogical != null && rightCheckLogical.equalsIgnoreCase(RightCheckConstants.RIGHT_CHECK_LOGICAL_B)) { res = checkRes[0] && checkRes[1]; } else { res = checkRes[0] || checkRes[1]; } }catch(Exception ex){ ex.printStackTrace(); } return res; } private boolean getCheckResult(String[] result, String opname) throws VCIError { VCIInvocationInfo invocationInfo = ClientContextVariable.getInvocationInfo(); String oid = result[0]; String btmName = result[1]; String revisionOid = result[2]; String nameOid = result[3]; CheckValue params = new CheckValue(); params.users = invocationInfo.userName; params.roles = getArrayString(invocationInfo.roleNames); params.userGroups = getArrayString(invocationInfo.groupNames); params.paramValues= GlobalContextParam.getInstance().getDefaultConditionString(); params.opname = opname; params.objectmoid = nameOid; params.objectroid = revisionOid; params.businesstype = btmName; params.objectoid = oid; String where = ServiceProvider.getFrameService().checkRight(params); String[] ops = where.split(":"); String msg = "0"; //TODO 需要处理 query 类型的操作,权限定义(返回数据格)不一样的问题 for (String s : ops) { if (s != null && !s.equals("")) { String[] op = s.split(","); msg = op[1]; break; } } boolean res = ("1".equals(msg)); return res; } protected String getArrayString(String[] values){ String res = ""; if (values != null) { for (int i = 0; i < values.length; i++) { if (i != 0) { res += ","; } res += values[i]; } } return res; } protected String[] getSelectedObjectIds(){ String[] res = new String[0]; return res; } protected String getSelectedObjectId(int index){ String res = ""; IDataModel dataModel = getDataModel(); if(dataModel == null) { System.out.println(getClassName() + ".getDataModel() result is null"); return ""; } Object[] objs = dataModel.getSelectObjects(); if(objs.length == 0) return ""; Object obj = objs[index]; if(IDataNode.class.isAssignableFrom(obj.getClass())){ IDataNode dataNode = (IDataNode)obj; obj = dataNode.getMaterObject(); } if(ClientBusinessObject.class.isAssignableFrom(obj.getClass())){ ClientBusinessObject bo = (ClientBusinessObject)obj; res = bo.getBusinessObject().oid; } else if(ClientLinkObject.class.isAssignableFrom(obj.getClass())){ ClientLinkObject lo = (ClientLinkObject)obj; res = lo.getLinkObject().oid; } return res; } public boolean isAssignableFrom(Class superClass, Class instanceClass){ return superClass.isAssignableFrom(instanceClass); } protected String getClassName(){ return getClass().getName(); } protected int getQuestionDialogResult(String message){ return VCIJOptionPane.showConfirmDialog(ClientContextVariable.getFrame(), message, "询问", VCIJOptionPane.YES_NO_OPTION); } protected PortalVI getFormPortalVIByFormId(String formId){ PortalVI res = null; DataModelFactory factory = new DataModelFactory(); try { res = factory.getFormViewById(formId); } catch (VCIError e) { e.printStackTrace(); } return res; } /** * 获取参数 * @param valueType 参数值的来源 * @param key 参数的 key * @param dataIndex 参数数据索引(第xx条数据的 x) * @return */ public String getParameterValue(ValueType valueType, String key, int dataIndex){ String res = null; Map map = null; if(valueType == ValueType.ButtonConfig){ map = getButtonParams(); } else if(valueType == ValueType.RuntimeData){ IDataModel dataModel = getDataModel(); Object rowData = dataModel.getSelectObjects()[dataIndex]; if(rowData instanceof IDataNode){ IDataNode dataNode = (IDataNode)rowData; map = dataNode.getValueMap(); } } res = map.get(key); return res; } /** * 设置Action所在的Dialog * @param ownerDialog */ @Override public void setOwnerDialog(VCIJDialog ownerDialog){ this.ownerDialog = ownerDialog; } /** * 返回 Action 所在的Dialog * @return VCIJDialog */ @Override public VCIJDialog getOwnerDialog(){ return this.ownerDialog; } public void closeOwnerDailog(VCIJDialog ownerDialog, DialogResult dialogResult){ if(ownerDialog != null){ ownerDialog.setDialogResult(dialogResult); ownerDialog.dispose(); ownerDialog.setVisible(false); } } /** * 设置 Button&Action所在的RegionPanel */ @Override public void setRegionPanel(IRegionPanel regionPanel){ this.regionPanel = regionPanel; } /** * 返回 Button&Action所在的RegionPanel * @return */ @Override public IRegionPanel getRegionPanel(){ return this.regionPanel; } /** * 获得控制区中一个tab页的PLDefination * @param type 类型 * @param context 上下文 * @return * @throws Throwable */ public PLDefination getDefination(String type, String context) throws Throwable{ PLDefination btnOwnDefinatio = null; PLUILayout plDef = getContext(type, context); Map tabPageMap = getTabPage(plDef.plOId, (short)2); Iterator it = tabPageMap.keySet().iterator(); while(it.hasNext()){ PLTabPage tabPage = it.next(); btnOwnDefinatio = tabPageMap.get(tabPage); } return btnOwnDefinatio; } /** * 获取当前context的详细信息 * @return * @throws Throwable * @throws Exception */ private PLUILayout getContext(String type, String context) throws Exception, Throwable { DataModelFactory factory = new DataModelFactory(); PLUILayout contextDef = factory.getContextDefination( type, context); if (contextDef == null || contextDef.plOId.equals("")) { BtmItem item = BtmProvider.getInstance().getBtmItemByName(type); if (item.fName == null || item.fName.equals("")) { return null; } return getContext(item.fName, item.fName); } return contextDef; } /** * 获得当前上下文的所有tab page * @return * @throws Throwable */ private Map getTabPage(String contextOid, short areaType) throws Throwable { PLTabPage[] tabs = UITools.getService().getTabPagesByContextIdAndType(contextOid, areaType); Map defMap = new LinkedHashMap(); for (int i = 0; i < tabs.length; i++) { PLPageDefination[] definations = UITools.getService().getPLPageDefinationsByPageContextOId(tabs[i].plOId); if (definations != null && definations.length < 1) { continue; } PLDefination defination = UITools .getPLDefination(definations[0].plDefination); defMap.put(tabs[i], defination); } return defMap; } /** * 如果有文件控件则判断是否需要上传文件 * @param oaed oaed * @param cbo 创建的CBO对象 * @return */ public boolean UploadFile(ObjectAddEditDialog oaed, ClientBusinessObject cbo){ try { if(oaed == null){ return true; } HashMap ctrlComptMap= oaed.getOaep().getCtrlComptMap(); Iterator it = ctrlComptMap.keySet().iterator(); while(it.hasNext()){ //如果设置原色在界面上显示并且设置为必填项 Object obj = ctrlComptMap.get(it.next()); if(obj != null && obj instanceof FileChooseControlPanel){ FileChooseControlPanel comp = (FileChooseControlPanel) obj; //XXX 暂时没有判断是否保存成功 comp.executeUpload(cbo); } } } catch (Exception e){ e.printStackTrace(); return false; } return true; } /** * 得到数据权限校验相关信息 * @param selectedObject 用户选择对象 * @return String[0] oid * [1] btmName * [2] revisionOid * [3] nameOid */ @SuppressWarnings("rawtypes") public String[] getCheckObject(Object selectedObject){ String[] result = new String[4]; String oid = ""; String btmName = ""; String revisionOid = ""; String nameOid = ""; try { PLAction action = getAction(); PLDefination pldef = getDefination(); //TODO 暂时没有处理反向的问题 if(action.plTypeType.equals("business")){ if(selectedObject instanceof String){ oid = (String) selectedObject; btmName = pldef.getShowType(); } else if (selectedObject instanceof Map){ if(pldef.getType() == 0){ oid = (String) ((Map)selectedObject).get("oid"); btmName = (String) ((Map)selectedObject).get("btmName"); } else if (pldef.getType() == 1){ oid = (String) ((Map)selectedObject).get("t_oid"); btmName = (String) ((Map)selectedObject).get("t_btmName"); } } else if (selectedObject instanceof IDataNode){ ClientBusinessObject cbo = new UIFUtils( ).getBusinessObject(selectedObject, true); if(cbo != null && cbo.getBusinessObject() != null){ oid = cbo.getBusinessObject().oid; btmName = cbo.getBusinessObject().btName; revisionOid = cbo.getBusinessObject().revisionid; nameOid = cbo.getBusinessObject().nameoid; } } } else { if(selectedObject instanceof String){ oid = (String) selectedObject; btmName = pldef.getLinkType(); } else if (selectedObject instanceof Map){ if(pldef.getType() == 0){ oid = (String) ((Map)selectedObject).get("oid"); btmName = (String) ((Map)selectedObject).get("btmName"); } else if (pldef.getType() == 1){ oid = (String) ((Map)selectedObject).get("oid"); btmName = pldef.getLinkType(); } } else if (selectedObject instanceof IDataNode){ if(((IDataNode) selectedObject).getMaterObject() instanceof ClientLinkObject){ oid = ((ClientLinkObject)((IDataNode ) selectedObject).getMaterObject()).getLinkObject().oid; btmName = pldef.getShowType(); } } } } catch (Exception e) { e.printStackTrace(); } result[0] = oid; result[1] = btmName; result[2] = revisionOid; result[3] = nameOid; return result; } private String[] getBOcheckObject(Object selectedObject) { String[] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject) masterObj; result = new String[4]; result[0] = cbo.getBusinessObject().oid; result[1] = cbo.getBusinessObject().btName; result[2] = cbo.getBusinessObject().revisionid; result[3] = cbo.getBusinessObject().nameoid; } } return result; } private String[] getLOcheckObject(Object selectedObject) { String[] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject) masterObj; result = new String[5]; PLDefination pldef = getDefination(); result[0] = clo.getFromOid() + ";" + clo.getOid(); result[1] = clo.getFromBTMName(); result[2] = ""; result[3] = ""; result[4] = pldef.getLinkType(); } } return result; } private String[] getFromBOCheckObject(Object selectedObject) { String[] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject) masterObj; result = new String[4]; result[0] = clo.getFromOid(); result[1] = clo.getFromBTMName(); result[2] = clo.getFromRevisionOid(); result[3] = clo.getFromNameOid(); } } return result; } private String[] getToBOCheckObject(Object selectedObject) { String[] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject) masterObj; result = new String[4]; result[0] = clo.getToOid(); result[1] = clo.getToBTMName(); result[2] = clo.getToRevisionOid(); result[3] = clo.getToNameOid(); } } return result; } private String[][] getLoFromBOCheckObject(Object selectedObject) { String[][] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientLinkObject) { result = new String[2][]; ClientLinkObject clo = (ClientLinkObject) masterObj; result[0] = new String[4]; result[0][0] = clo.getFromOid(); result[0][1] = clo.getFromBTMName(); result[0][2] = clo.getFromRevisionOid(); result[0][3] = clo.getFromNameOid(); PLDefination pldef = getDefination(); result[1] = new String[5]; result[1][0] = clo.getFromOid() + ";" + clo.getOid(); result[1][1] = clo.getFromBTMName(); result[1][2] = ""; result[1][3] = ""; result[1][4] = pldef.getLinkType(); } } return result; } private String[][] getLoToBOCheckObject(Object selectedObject) { String[][] result = null; if (selectedObject instanceof IDataNode){ IDataNode dataNode = (IDataNode) selectedObject; Object masterObj = dataNode.getMaterObject(); if (masterObj instanceof ClientLinkObject) { result = new String[2][]; ClientLinkObject clo = (ClientLinkObject) masterObj; result[0] = new String[4]; result[0][0] = clo.getToOid(); result[0][1] = clo.getToBTMName(); result[0][2] = clo.getToRevisionOid(); result[0][3] = clo.getToNameOid(); PLDefination pldef = getDefination(); result[1] = new String[4]; result[1][0] = clo.getFromOid() + ";" + clo.getOid(); result[1][1] = clo.getFromBTMName(); result[1][2] = ""; result[1][3] = ""; result[1][4] = pldef.getLinkType(); } } return result; } public Component getButtonComponent() { return buttonComponent; } public void setButtonComponent(Component buttonComponent) { this.buttonComponent = buttonComponent; } /** * 设置Action配置信息 * @param action */ public void setAction(PLAction action){ this.action = action; } /** * 获得Action配置信息 * @return */ public PLAction getAction(){ return this.action; } /** * 检查按钮上定义的参数是否有效(不等于null且不等于"") * @param param 参数值 * @param errorMessage 无效时的提示信息 * @return */ protected boolean checkButtonParamIsValid(String paramValue, String message){ return checkButtonParamIsValid(paramValue, message, true); } /** * 检查按钮上定义的参数是否有效(不等于null且不等于"") * @param param 参数值 * @param errorMessage 无效时的提示信息 * @return */ protected boolean checkButtonParamIsValid(String paramValue, String errorMessage, boolean showErrorMessage){ boolean res = true; if(UIFUtils.isNullOrEmpty(paramValue)){ res = false; UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), new VCIException(errorMessage)); } return res; } private String dataRightCheckType = RightCheckConstants.RIGHT_CHECK_TYPE_NONE; /** * 设置 action 需要使用的数据权限检查类型 * @param dataRightCheckType 数据权限检查类型 */ public void setDataRightCheckType(String dataRightCheckType){ this.dataRightCheckType = dataRightCheckType; } /** * 返回 action 使用的数据权限检查类型 * @return */ public String getDataRightCheckType(){ return this.dataRightCheckType; } /** * 调用按钮所在Dialog的注册的回调函数 */ public void invokeOwnedDialogCallback(){ VCIJDialog dialog = this.getOwnerDialog(); if(dialog != null){ Runnable runnable = dialog.getDialogCallback(); if(runnable != null){ VCISwingUtil.invokeLater(runnable, 0); } } } }