package com.vci.client.uif.engine.client.objopt; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import javax.swing.text.JTextComponent; import org.dom4j.DocumentException; import com.vci.client.bof.AttributeChecker; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObject; import com.vci.client.common.FreeMarkerCommon; import com.vci.client.common.FreemarkerParamObject; import com.vci.client.common.objects.UserObject; import com.vci.client.common.oq.OQTool; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.omd.provider.ApProvider; import com.vci.client.omd.provider.EnumProvider; import com.vci.client.oq.QTClient; import com.vci.client.portal.constants.QueryConditionConstants; import com.vci.client.portal.form.defaultvalue.DefaultValueController; import com.vci.client.portal.utility.DataModelFactory; import com.vci.client.portal.utility.DataModelProcessor; import com.vci.client.portal.utility.PLDefination; import com.vci.client.portal.utility.PRM; import com.vci.client.portal.utility.PRMItem; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.components.VCIJCalendarPanel; import com.vci.client.ui.swing.components.VCIJComboBox; import com.vci.client.ui.swing.components.VCIJLabel; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.VCIJScrollPane; import com.vci.client.ui.swing.components.VCIJTextField; import com.vci.client.uif.actions.client.AbstractBatchBusionessOperationAction; import com.vci.client.uif.actions.client.BusinessObjectAttributeChecker; import com.vci.client.uif.actions.client.EditLinkAction; import com.vci.client.uif.actions.client.UIFUtils; import com.vci.client.uif.engine.client.IRegionPanel; import com.vci.client.uif.engine.client.UIHelper; import com.vci.client.uif.engine.client.controls.BaseCustomControl; import com.vci.client.uif.engine.client.controls.ControlFactory; import com.vci.client.uif.engine.client.controls.DateTimeControl; import com.vci.client.uif.engine.client.controls.ICustomControl; import com.vci.client.uif.engine.client.controls.RefObjChooseControl; import com.vci.client.uif.engine.client.controls.VCIJComboBoxModelValueObject; import com.vci.client.uif.engine.client.custom.ICustomAttributeInteceptor; import com.vci.client.uif.engine.client.objopt.ObjectAddEditDialog.OperateType; import com.vci.client.uif.engine.common.CBOHelper; import com.vci.client.uif.engine.common.ClientLOAndBOData; import com.vci.client.uif.engine.common.DefaultTableNode; import com.vci.client.uif.engine.common.GlobalContextParam; import com.vci.client.uif.engine.common.IDataNode; import com.vci.common.portal.enums.ControlType; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.ConditionItem; import com.vci.common.qt.object.LeafInfo; import com.vci.common.qt.object.QueryTemplate; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.data.LinkObject; import com.vci.corba.omd.etm.EnumItem; import com.vci.corba.portal.data.PortalVI; import com.vci.corba.query.data.RefPath; import com.vci.mw.ClientContextVariable; import com.vci.omd.objects.OtherInfo; import com.vci.omd.utils.ObjectTool; public class ObjectAddEditPanel extends VCIJPanel { private static final long serialVersionUID = 6400165410571370254L; private String type = ""; private String context = ""; private PLDefination defination = null; private DataModelFactory factory = null; private Map paramsMap = new LinkedHashMap(); private OperateType operateType = OperateType.ADD; private AttributeChecker curAttrChecher = null; private IRegionPanel regionPanel = null; private Map valueMapNew = new LinkedHashMap(); private Map valueMapOriginal = new LinkedHashMap(); /** * 全部的Label */ private final HashMap ctrlLabelMap = new LinkedHashMap(); /** * 全部的Component 控件 */ private HashMap ctrlComptMap = new LinkedHashMap(); /** * 将界面元素属性集合设置成全局变量 在保存时用于判断属性是否为空 */ private final HashMap itemMap = new LinkedHashMap(); private final HashMap ctrlComboBoxMap = new LinkedHashMap(); /** * 控件的数据之间有级联数据控制的控件 KEY:主控属性字段 VALUE:受控(数据级联影响)属性字段 * 受控控件的数据受主控属性控件的数据影响,一般是主控数据作为受控数据的查询条件 */ private final HashMap> cascadeControlsMap = new LinkedHashMap>(); /** * 控件之间有显示控制 KEY:被控属性字段 VALUE:主控属性字段 受控件控件的显示与否,受主控属性的部分取值的影响 */ private final HashMap> hiddenControlsMap = new LinkedHashMap>(); /** * 被控属性与主控属性之间在关联关联 key:被控属性 value:主控属性 */ private final HashMap fieldToMasterFieldMap = new LinkedHashMap(); private final HashMap SELECT_ATTRIBUTE = new LinkedHashMap(); private final HashMap SELECT_ATTRIBUTE_VALUE = new LinkedHashMap(); /** * 当前窗口的表单类型 0:业务类型,1:链接类型 对于不同类型的表单,窗口中属性的命名规则不同 */ private int typeFlag = 0; /** * 如果是选择时记录用户选择的数据 */ private Object[] selectedDatas = null; private ClientBusinessObject cbo = null; private ClientLinkObject clo = null; private IDataNode dataNodeObject = new DefaultTableNode(); /** * 判断是正向还是反响向 */ private boolean direction = true; private final UIFUtils operation = new UIFUtils(); public ObjectAddEditPanel(String type, String context, PLDefination defination, DataModelFactory factory, Map paramsMap, OperateType operateType, IRegionPanel regionPanel) { this.regionPanel = regionPanel; this.type = type; this.context = context; this.defination = defination; this.factory = factory; this.paramsMap = paramsMap; this.operateType = operateType; curAttrChecher = new AttributeChecker(); curAttrChecher.getAllAttribute(); } /** * 是否是创建窗口 * * @return */ private boolean isAdd() { return (operateType == OperateType.ADD); } /** * 是否是添加窗口 * * @return */ private boolean isEdit() { return (operateType == OperateType.EDIT); } /** * 是否是选择窗口 * * @return */ private boolean isSelect() { return (operateType == OperateType.SELECT); } private boolean isOperateBusinessObject() { return getTypeFlag() == 0; } /** * 根据表单类型获得窗口的主对象 当为业务对象创建编辑时表单类型一定是 0; 当为link对象创建编辑时表单类型可能是0,也肯能是1 */ private void initEmptyObject() { if (isOperateBusinessObject()) { cbo = operation.createEmptyClientBusinessObject(ClientContextVariable.getFrame(), getDefination().getShowType()); dataNodeObject.setMasterObject(cbo); } else { clo = operation.createEmptyClientLinkObject(ClientContextVariable.getFrame(), getDefination().getLinkType()); dataNodeObject.setMasterObject(clo); } } public void init() { initEmptyObject(); setLayout(new BorderLayout()); VCIJScrollPane scroll = new VCIJScrollPane(getCenterPanel()); add(scroll, BorderLayout.CENTER); } private PortalVI sheet = null; private PortalVI getPortalVIByFormOrTypeAndDef() throws VCIError { // 根据type、context获取对应�?'editForm' String formName = null; try { formName = defination.getTemplateId();// factory.getFormNameByByTypeAndContext(type, // context); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } if (formName != null && !"".equals(formName)) { sheet = UITools.getService().getPortalVIBySymbol(formName); } return sheet; } private VCIJPanel getCenterPanel() { VCIJPanel pal = new VCIJPanel(new GridBagLayout()); try { PortalVI sheet = getPortalVIByFormOrTypeAndDef(); if (sheet == null) return pal; pal = createControlsPanel(sheet); // pal.setBorder(BorderFactory.createLineBorder(Color.GRAY)); } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } return pal; } private void addItemToMap(List items) { for (PRMItem item : items) { this.itemMap.put(item.getItemField(), item); } } private VCIJPanel createControlsPanel(PortalVI sheet) { VCIJPanel pal = new VCIJPanel(new GridBagLayout()); PRM sheetPrm = UITools.getPRM(sheet.prm); List itemList = sheetPrm.getPrmItemList(); // 缓存PRMItem addItemToMap(itemList); int showColumns = 2; if (!"".equals(sheetPrm.getShowCols())) { showColumns = Integer.valueOf(sheetPrm.getShowCols()); } int gridx = 0; int gridy = 0; int gridwidth = 1; int gridheight = 1; double weightx = 1.0; double weighty = 0.0; int padxy = 2; int latestGridx = 0; boolean latestIsTextArea = false; VCIJLabel lbl = null; Component compt = null; Component comptToAdd = null; for (int i = 0; i < itemList.size(); i++) { PRMItem item = itemList.get(i); String field = item.getItemField(); String itemCols = item.getItemCols(); lbl = new VCIJLabel(item.getItemName() + ":"); compt = ControlFactory.createControl(item); if (compt == null) continue; ctrlComptMap.put(field, compt); if (itemCols == null || itemCols.trim().equals("") || itemCols.equals("0")) { continue; } if (ControlFactory.isLCStatusAttr(field) && compt instanceof VCIJComboBox) { String btmType = defination.getShowType(); ((VCIJComboBox) compt).setModel(ControlFactory.getLCStatusComboboxModel(item, btmType)); } comptToAdd = compt; if (comptToAdd instanceof ICustomControl) { ((ICustomControl) comptToAdd).setParentComponent(this); } if (compt instanceof JTextArea) { comptToAdd = new VCIJScrollPane(compt); comptToAdd.setPreferredSize(new Dimension(1, 1)); } // 缓存控件 ctrlLabelMap.put(field, lbl); ctrlComptMap.put(field, compt); // TextArea 占整行显示 if (item.getItemType().toLowerCase().equals(ControlType.TextArea.name().toLowerCase())) { gridx = 0; gridy += 1; gridwidth = showColumns * 2 - 1; gridheight = 30; weightx = 1.0; weighty = 5.0; pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, padxy)); gridx += 1; pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty, GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy)); latestIsTextArea = true; // 重置一行位置信息 gridx = 0; gridy += gridheight; gridwidth = 1; gridheight = 1; weightx = 1.0; weighty = 0.0; latestGridx = 0; } else { if (latestIsTextArea) { // 如果最近的一个控件是TextArea,则位置信息已经是设置好了的,此时直接使用 pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, padxy)); gridx += 1; pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty, GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy)); latestIsTextArea = false; } else { if (latestGridx == showColumns) { // 本行已经到达最大,此时也需要换行,设置下一 // 重置一行位置信息 gridx = 0; gridy += 1; gridwidth = 1; gridheight = 1; weightx = 1.0; weighty = 0.0; latestGridx = 0; } else { // 重置一行位置信息 if (gridx != 0) { gridx += 1; } } // 普通单行内追加 pal.add(lbl, getGBC(gridx, gridy, 1, gridheight, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, padxy)); gridx += 1; pal.add(comptToAdd, getGBC(gridx, gridy, gridwidth, gridheight, weightx, weighty, GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy)); } latestGridx++; latestIsTextArea = false; String itemAndFilter = item.getItemAddFilter(); String itemCustomClass = item.getItemCustomClass(); if (itemAndFilter != null && !"".equals(itemAndFilter) && (itemCustomClass == null || "".equals(itemCustomClass))) { SELECT_ATTRIBUTE.put(field, itemAndFilter); } // 处理属性与属性之间的关联控制数据 // add by caill cascadeControlsMapConfig(item); // 处理属性与属性之间的 显示 控制数据 parseFieldRefHideAndShowData(item); if (compt instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) compt; // 主控属性,需要加入数据选择后的事件处理 // if (cascadeControlsMap.containsKey(field)) { // cbx.addActionListener(new CascadeComboBoxActionListener(item)); // } if (hiddenControlsMap.containsKey(field)) { cbx.addActionListener(new HiddenOrShowComboBoxActionListener(item)); } ctrlComboBoxMap.put(field, cbx); } else if (compt instanceof RefObjChooseControl) { // 参照类型的控件,需要注册数据选择后的处理逻辑 // add by songyf 2014.08.15 使空间在不可编辑的时候也注册事件 // 这样,不可编辑但是在窗口打开的时候具有初始值的控件在初始化的时候也能设置关联空间的值 RefObjChooseControl rocc = (RefObjChooseControl) compt; if (!"".equals(item.getItemListTable()) && !"".equals(item.getItemListVal()) // && !"1".equals(item.getItemIsEditable()) ) { registeRefObjChooseListener(rocc); } // end by songyf 2014.08.15 } // 如果是下拉列表、又是必填,尝试将其下拉列表的第一个值自动选择上 /* * if (compt instanceof VCIJComboBox && ControlFactory.isRequired(item)) { * loadComboBoxData(field); } */ if (compt instanceof VCIJComboBox) { // add by caill 将是“必填”的条件去掉,否则在设置级联下拉列表不是必填的时候,不会显示名称,只会显示id loadComboBoxData(field); } } // 当为浏览时设置空间不可编辑 if (operateType.equals(OperateType.BROWSER)) { // add by xchao 2014.04.21 begin // 浏览模式下的txt控件为只读 if (JTextComponent.class.isAssignableFrom(compt.getClass())) { compt.setEnabled(true); ((JTextComponent) compt).setEditable(false); } else { compt.setEnabled(false); } // add by xchao 2014.04.21 end } else if (operateType.equals(OperateType.SELECT)) { // 如果为选择窗口时,需要判断form的类型来禁用相关的控件 // 如果是业务类型,禁用所有控件,如果是link类型,禁用t_oid控件 if (typeFlag == 0) { compt.setEnabled(false); } else { String head = ""; if (direction) { head = "t_oid"; } else { head = "f_oid"; } if (field.toLowerCase().startsWith(head)) { compt.setEnabled(false); } } } VCIJLabel lblFill = new VCIJLabel(""); pal.add(lblFill, getGBC(0, gridy + 10, showColumns * 2, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, padxy)); if (compt instanceof VCIJComboBox && !item.getItemAddFilter().equals("")) { VCIJComboBox cbx = (VCIJComboBox) compt; cbx.addPopupMenuListener(new ComboBoxDataLoaderListener(field)); } } // 根据显示控制,隐藏控件显示 for (Iterator it = hiddenControlsMap.keySet().iterator(); it.hasNext();) { String masterField = it.next(); List list = hiddenControlsMap.get(masterField); for (String filedToControl : list) { if (ctrlLabelMap.containsKey(filedToControl)) ctrlLabelMap.get(filedToControl).setEnabled(false); if (ctrlComptMap.containsKey(filedToControl)) ctrlComptMap.get(filedToControl).setEnabled(false); } } return pal; } class ComboBoxDataLoaderListener implements PopupMenuListener { private String lastChangedName = ""; private boolean manual = false; private String field = ""; public ComboBoxDataLoaderListener(String field) { this.field = field; } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if (manual) { manual = false; return; } if (e.getSource() instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) e.getSource(); loadComboBoxData(field); manual = true; cbx.showPopup(); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if ("".equals(lastChangedName) && dataNodeObject != null) { lastChangedName = dataNodeObject.getValueMap().get(field); } VCIJComboBox cbx = (VCIJComboBox) e.getSource(); String changeName = cbx.getSelectedItem().toString(); if (!changeName.equals(lastChangedName)) { // 清空被关联控制的列表数据 if (cascadeControlsMap.containsKey(field)) { List list = cascadeControlsMap.get(field); for (String field : list) { clearCascadeComboBoxData(field); } } } lastChangedName = changeName; } @Override public void popupMenuCanceled(PopupMenuEvent e) { } } /** * 级联清空被关联控制控件的列表 * * @param cascadeField */ private void clearCascadeComboBoxData(String cascadeField) { Object compt = ctrlComboBoxMap.get(cascadeField); if (compt != null && compt instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) compt; cbx.setModel(getDefaultEmptyModel()); } if (cascadeControlsMap.containsKey(cascadeField)) { List list = cascadeControlsMap.get(cascadeField); for (String field : list) { // 递归级联清空被关联的列表数据 clearCascadeComboBoxData(field); } } } private DefaultComboBoxModel getDefaultEmptyModel() { DefaultComboBoxModel model = new DefaultComboBoxModel(); VCIJComboBoxModelValueObject vo = new VCIJComboBoxModelValueObject("", ""); model.addElement(vo); return model; } /** * 为参照属性注册数据选择&更换后的事件处理程序 * * @param rocc */ private void registeRefObjChooseListener(RefObjChooseControl rocc) { rocc.addPropertyChangeListener(RefObjChooseControl.REF_OBJECT_CHANGED, new PropertyChangeListener() { @SuppressWarnings("unchecked") @Override public void propertyChange(PropertyChangeEvent evt) { Map newValMap = (Map) evt.getNewValue(); RefObjChooseControl source = (RefObjChooseControl) evt.getSource(); refreshOtherRefObjChooseControlData(source, newValMap); } }); } /** * 刷新参照对象引用数据 * * @param rocc * @param newVal */ private void refreshOtherRefObjChooseControlData(RefObjChooseControl rocc, Map newVal) { PRMItem item = rocc.getPRMItem(); String itemField = item.getItemField(); String oid = newVal.get(UIHelper.OID); if (oid == null || "".equals(oid)) return; // 查询关联列,数据处理 if (item.getItemQueryRefFields() != null && !"".equals(item.getItemQueryRefFields())) { // 被关联的属性列表 String[] toFields = item.getItemQueryRefFields().split(","); for (String toField : toFields) { PRMItem toItem = itemMap.get(toField); if (toItem == null) continue; String toFilter = toItem.getItemAddFilter(); if (toFilter == null || "".equals(toFilter)) continue; if (!ctrlComboBoxMap.containsKey(toField)) continue; SELECT_ATTRIBUTE.put(toField, toFilter); SELECT_ATTRIBUTE_VALUE.put(itemField, oid); loadComboBoxData(toField); } } // 相同参照对象的数据处理 for (Iterator it = ctrlComptMap.keySet().iterator(); it.hasNext();) { String key = it.next(); Component compt = ctrlComptMap.get(key); // 规约:参照对象的其它参照只能是文本框。 if (compt instanceof VCIJTextField) { VCIJTextField txt = (VCIJTextField) compt; PRMItem itemOther = (PRMItem) txt.getObj(); String fieldOther = itemOther.getItemField(); if (fieldOther.startsWith(itemField + ".")) { // modify by songyf 2014.08.21 修改当创建表单时,控件值显示错误的问题 // 在表单上有多个参照属性,且参照属性如下 // smaterialratio(参照) // smaterialratio.usemat(参照) // 控件smaterialratio.usemat。xxx 还设置了默认值,此时由于参照属性设置顺序不同有时会出现 // 控件的值设置不上的情况。(smaterialratio控件如果后执行的话会出现错误) fieldOther = fieldOther.substring(itemField.length() + 1); if (newVal.containsKey(fieldOther)) { String valueOther = newVal.get(fieldOther); txt.setText(valueOther); } // end by songyf 2014.08.21 } } } } private void loadComboBoxData(String field) { VCIJComboBox cbx = ctrlComboBoxMap.get(field); String sql = SELECT_ATTRIBUTE.get(field); if (sql == null) return; DefaultComboBoxModel model = new DefaultComboBoxModel(); // 手工设置的默认选择值 String manualSelectedValue = ""; if (isFreemarkTemplateContent(sql)) { sql = getReplacedSql(sql); if (isSingleCol(sql)) { model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[0])); } else { model = convertSQLDataToDataModel(getMulColSQLData(sql, new AttributeValue[0])); } // 当查询出的数据值只有一个时,将其作为默认值 if (model.getSize() == 1) { manualSelectedValue = ((VCIJComboBoxModelValueObject) model.getElementAt(0)).getValue(); } model.insertElementAt(new VCIJComboBoxModelValueObject("", ""), 0); } else if (sql.indexOf(":") < 0) { // 纯SQL,直接执行查询 // 兼容带:时也支持SQL if (isFreemarkTemplateContent(sql)) { sql = getReplacedSql(sql); } if (isSingleCol(sql)) { model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[0])); } else { model = convertSQLDataToDataModel(getMulColSQLData(sql, new AttributeValue[0])); } // 当查询出的数据值只有一个时,将其作为默认值 if (model.getSize() == 1) { manualSelectedValue = ((VCIJComboBoxModelValueObject) model.getElementAt(0)).getValue(); } model.insertElementAt(new VCIJComboBoxModelValueObject("", ""), 0); } else { for (Iterator it = SELECT_ATTRIBUTE_VALUE.keySet().iterator(); it.hasNext();) { String akey = it.next(); String[] ckeys = akey.split("-"); String ckey = ckeys[ckeys.length - 1]; if (ckey.indexOf("\\.") >= 0) { ckey = ckey.split("\\.")[0]; } if (sql.indexOf(":" + ckey) >= 0) { AttributeValue attrVal = new AttributeValue(); attrVal.attrName = ckey; attrVal.attrVal = SELECT_ATTRIBUTE_VALUE.get(ckey); model = convertSQLDataToDataModel(getSQLData(sql, new AttributeValue[] { attrVal })); break; } } } String currentSelectedItemValue = ""; if (manualSelectedValue != null && !"".equals(manualSelectedValue)) { currentSelectedItemValue = manualSelectedValue; } else if (cbx.getSelectedItem() != null) { currentSelectedItemValue = ((VCIJComboBoxModelValueObject) cbx.getSelectedItem()).getValue(); } cbx.setModel(model); if (operateType == OperateType.BROWSER) { cbx.setEnabled(false); } else if (operateType == OperateType.ADD) { setComboBoxAddModeSelectItem(cbx, field, currentSelectedItemValue); } else if (operateType == OperateType.EDIT) { setComboBoxEditSelectItem(cbx, field, currentSelectedItemValue); } } /** * 查询语句查询是一列还是多列 * * @param sql * @return */ private boolean isSingleCol(String sql) { while (sql.indexOf("(") >= 0) { sql = transferSqlToSimple(sql); } sql = sql.substring("select".length() + 1); sql = sql.substring(0, sql.indexOf(" from ")); if (sql.split(",").length == 1) { return true; } else { return false; } } /** * 将sql中带括号的语句替换掉,方便截取 * * @param str * @return */ private String transferSqlToSimple(String str) { Matcher lmatcher = Pattern.compile("\\(").matcher(str); Matcher rmatcher = Pattern.compile("\\)").matcher(str); List lList = new ArrayList(); List rList = new ArrayList(); while (lmatcher.find()) { lList.add(lmatcher.start()); } while (rmatcher.find()) { rList.add(rmatcher.start()); } int c = 0; for (int i = 0; i < lList.size(); i++) { if ((i + 1 < lList.size()) && (lList.get(i + 1) > rList.get(i))) { c = i; break; } } if (c == 0) { c = lList.size() - 1; } int pos = rList.get(c); String rstr = str.substring(pos + 1); String lstr = str.substring(0, lList.get(0)); return (lstr + rstr); } private void setComboBoxAddModeSelectItem(VCIJComboBox cbx, String field, String currentSelectedItemValue) { ComboBoxModel model = cbx.getModel(); int i = -1; Object selectedItem = null; while (i++ <= model.getSize()) { Object obj = model.getElementAt(i); if (!(obj instanceof VCIJComboBoxModelValueObject)) { continue; } VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) obj; if (vo.getName().equals(currentSelectedItemValue) || vo.getValue().equals(currentSelectedItemValue)) { selectedItem = vo; break; } } model.setSelectedItem(selectedItem); } private void setComboBoxEditSelectItem(VCIJComboBox cbx, String field, String currentSelectedItemValue) { ComboBoxModel model = cbx.getModel(); if (this.dataNodeObject == null) return; Map objValMap = this.dataNodeObject.getValueMap(); if (objValMap.size() == 0) return; int i = -1; Object selectedItem = null; while (i++ <= model.getSize()) { Object obj = model.getElementAt(i); if (!(obj instanceof VCIJComboBoxModelValueObject)) { continue; } VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) obj; String valueInMap = objValMap.get(field); if (currentSelectedItemValue.equals(vo.getValue()) || currentSelectedItemValue.equals(vo.getName())) { selectedItem = obj; break; } else if (valueInMap == null) { continue; } else if ("".equalsIgnoreCase(valueInMap) || valueInMap.equals(vo.getValue()) || valueInMap.equals(vo.getName())) { selectedItem = obj; break; } } model.setSelectedItem(selectedItem); } private String getReplacedSql(String sql) { String res = sql; Map valueMap = new HashMap(); appendToValueMap(sql, valueMap); Iterator its = valueMap.keySet().iterator(); while (its.hasNext()) { String key = its.next(); sql = sql.replaceAll(key, key.replace(".", "_")); } Map rootMap = convertValueMapToFPOMap(valueMap); res = FreeMarkerCommon.getValueByTempRule(rootMap, sql); return res; } private String[] getSQLData(String sql, AttributeValue[] attrVals) { String[] clsfVals = new String[0]; ClientBusinessObjectOperation bofactory = new ClientBusinessObjectOperation(); try { clsfVals = bofactory.getClassficationValue(sql, attrVals); } catch (VCIError e) { e.printStackTrace(); } return clsfVals; } private String[][] getMulColSQLData(String sql, AttributeValue[] attrVals) { String[][] vals = new String[0][0]; ClientBusinessObjectOperation bofactory = new ClientBusinessObjectOperation(); try { vals = bofactory.getSqlQueryResult(sql, attrVals); } catch (VCIError e) { e.printStackTrace(); } return vals; } private DefaultComboBoxModel convertSQLDataToDataModel(String[] results) { DefaultComboBoxModel model = new DefaultComboBoxModel(); for (String res : results) { VCIJComboBoxModelValueObject obj = new VCIJComboBoxModelValueObject(res, res); model.addElement(obj); } return model; } private DefaultComboBoxModel convertSQLDataToDataModel(String[][] results) { DefaultComboBoxModel model = new DefaultComboBoxModel(); for (String[] res : results) { VCIJComboBoxModelValueObject obj = new VCIJComboBoxModelValueObject(res[0], res[1]); model.addElement(obj); } return model; } private class HiddenOrShowComboBoxActionListener implements ActionListener { private PRMItem fromItem = null; public HiddenOrShowComboBoxActionListener(PRMItem fromItem) { this.fromItem = fromItem; } @Override public void actionPerformed(ActionEvent e) { VCIJComboBox cbx = (VCIJComboBox) e.getSource(); VCIJComboBoxModelValueObject valObj = (VCIJComboBoxModelValueObject) cbx.getSelectedItem(); String[] displayConditions = fromItem.getItemCtrlDisplyCondition().split(";"); List controlToFiels = hiddenControlsMap.get(fromItem.getItemField()); for (int i = 0; i < controlToFiels.size(); i++) { // 被控制属性字段 String toField = controlToFiels.get(i); String condition = displayConditions[i]; // 允许显示出该属性的取值 String[] diplayShows = condition.split(","); boolean enable = false; for (String display : diplayShows) { enable |= valObj.getName().equals(display); } Component compt = ctrlLabelMap.get(toField); if (compt != null) compt.setEnabled(enable && operateType != OperateType.BROWSER); compt = ctrlComptMap.get(toField); if (compt != null) compt.setEnabled(enable && operateType != OperateType.BROWSER); } } } /** * 处理属性之间的关联查询控制 * * @param item */ private void cascadeControlsMapConfig(PRMItem item) { String field = item.getItemField(); String itemQueryRefFields = item.getItemQueryRefFields(); if (itemQueryRefFields != null && !"".equals(itemQueryRefFields)) { // 一个属性能够关联 多个属性,被关联的属性名称之间用逗号,分隔 String[] itemQueryRefFieldsArray = itemQueryRefFields.split(","); List list = new ArrayList(); if (cascadeControlsMap.containsKey(field)) { list = cascadeControlsMap.get(field); } for (String refField : itemQueryRefFieldsArray) { // 建立 主控属性与被属性之间关联关系,以控制被控属性的取值 list.add(refField); // 建立被控属性 与 主控属性 之间的映射关联 fieldToMasterFieldMap.put(refField, field); } cascadeControlsMap.remove(field); cascadeControlsMap.put(field, list); } } private void parseFieldRefHideAndShowData(PRMItem item) { String field = item.getItemField(); String itemCtrlDisplayCol = item.getItemCtrlDisplyCol(); if (itemCtrlDisplayCol != null && !"".equals(itemCtrlDisplayCol)) { String[] itemCtrlDisplayCols = itemCtrlDisplayCol.split(","); List list = new ArrayList(); if (hiddenControlsMap.containsKey(field)) { list = hiddenControlsMap.get(field); } for (String refField : itemCtrlDisplayCols) { list.add(refField); } hiddenControlsMap.remove(field); hiddenControlsMap.put(field, list); } } private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int padxy) { return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy); } /** * 设置已经修改了属性值的对象数据到UI * * @param clientObject */ public void setValueToUIControlByAttrValChange(Object clientObject) { if (clientObject instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject) clientObject; setValueToUIControl(cbo, false); } else if (clientObject instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject) clientObject; setValueToUIControl(clo, false); } } /** * 编辑Form对应的查询模板查询出的数据Map */ public void setValueToUIControl(Object clientObject) { if (clientObject instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject) clientObject; setValueToUIControl(cbo, true); } else if (clientObject instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject) clientObject; setValueToUIControl(clo, true); } } /** * 根据idn重新设置表单的内容 如果是链接类型,根据空间的名称判断表单是正向还是反向 * * @param idn * @param typeFlag 表单类型 0业务类型,1连接类型 */ public void setValueToUIControl(IDataNode idn, int typeFlag) { // 判断选择的对象是BO还是LO String idnType = "9"; if (idn.getMaterObject() instanceof ClientBusinessObject) { idnType = "0"; } else if (idn.getMaterObject() instanceof ClientLinkObject) { idnType = "1"; } if (idnType.equals("9")) { return; } // 根据表单的类型设置数据 if (typeFlag == 0) { // BO类型 if (idnType.equals("0")) { // BO对象对应业务类型的表单 setValueToUIControl(idn.getMaterObject()); } else { // TODO 暂时没有实现link设置到业务类型表单的情况 } } else { // 链接类型 if (idnType.equals("1")) { setValueToUIControl(idn.getMaterObject()); } else { // BO对象,link表单 setLinkFormData(idn, idn.getValueMap()); } } } /** * 设置LinkForm的内容 * * @param dataNode 控件关联的数据对象 * @param objValMap bo的valueMap */ private void setLinkFormData(IDataNode dataNode, Map objValMap) { HashMap comptMap = getCtrlComptMap(); for (Iterator i = comptMap.keySet().iterator(); i.hasNext();) { String field = i.next(); String newKey = ""; if (field.toUpperCase().startsWith("T_OID.")) { newKey = field.substring(field.indexOf(".") + 1, field.length()); } else if (field.toUpperCase().startsWith("F_OID.")) { newKey = field.substring(field.indexOf(".") + 1, field.length()); } if (!objValMap.containsKey(newKey)) continue; String value = objValMap.get(newKey); if (field.toUpperCase().endsWith(".LCSTATUS")) { value = operation.transferLifecycle(value); } if (value == null) { value = ""; } Component compt = comptMap.get(field); PRMItem item = itemMap.get(field); if (compt instanceof JTextComponent) { ((JTextComponent) compt).setText(value); } 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 (value.equals(vo.getValue())) { model.setSelectedItem(vo); break; } } } } else if (compt instanceof ICustomControl) { ICustomControl ctrl = (ICustomControl) compt; // 将控件与数据主对象 ctrl.setDataNode(dataNode); if (ctrl instanceof RefObjChooseControl) { String refObjField = item.getItemListVal(); String refObjKey = newKey + "." + refObjField; String refObjVal = value; if (objValMap.containsKey(refObjKey)) { refObjVal = objValMap.get(refObjKey); } value = value + "," + refObjVal; } ctrl.setValue(value); } } } /** * 从控件中取值 * * @param field * @param dataMap */ private String getValueFromUIControl(String field) { String res = ""; String key = field; Component compt = this.ctrlComptMap.get(key); if (compt instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) compt; Object obj = cbx.getModel().getSelectedItem(); if (obj != null && obj instanceof VCIJComboBoxModelValueObject) { VCIJComboBoxModelValueObject val = (VCIJComboBoxModelValueObject) obj; if (val != null && !val.getValue().trim().equalsIgnoreCase("")) { res = val.getValue(); } } } else if (compt instanceof JTextComponent) { res = ((JTextComponent) compt).getText(); } else if (compt instanceof VCIJCalendarPanel) { res = ((VCIJCalendarPanel) compt).getDateString(); } return res; } /** * 设置页面空间的属性值 cbo一定不为空 当clo为空的时候,页面说是用的Form一定是BO的Form * 当clo不为空的时候分为使用BO的Form或是使用LOForm * * @param clo * @param cbo */ public void setValueToUIControl(ClientLinkObject clo, ClientBusinessObject cbo) { if (cbo == null || cbo.getBusinessObject().oid == null || cbo.getBusinessObject().oid.equals("")) { return; } if (clo == null || clo.getLinkObject().oid == null || clo.getLinkObject().oid.equals("")) { setValueToUIControl(cbo); } else { // 此时为修改或浏览lo对象,需要判断所使用的form类型 if (getTypeFlag() == 0) { // 使用的是BO的Form,页面上所有的属性都是BO的属性 setValueToUIControl(cbo); } else { // 使用的LO的Form,以t_oid开头的属性是BO的属性 setValueToUIControl(clo); } } } /** * modify by songyf 2014.09.02 修改form中使用link表单时查询模板参数设置问题 * * @param objOid * @return */ @SuppressWarnings("deprecation") private IDataNode getDataNodeFromBoLoId(String objOid) { DataModelProcessor processor = new DataModelProcessor(); String showType = defination.getShowType(); String linkType = defination.getLinkType(); IDataNode dataNode = null; try { PortalVI formDef = UITools.getService().getPortalVIBySymbol(this.getDefination().getTemplateId()); boolean isShowLinkType = (formDef.typeFlag == 1); PRM prm = UITools.getPRM(formDef.prm); Map columnsMap = processor.getFormColumnMap(formDef); // 获得查询模板,并根据查询模板设置查询条件 Map conditionMap = getQueryTemplateReplaceMap(prm, objOid, this.regionPanel.getSourceData(), isShowLinkType); conditionMap.put(UIHelper.TYPE, showType); // conditionMap.put(UIHelper.OID, objOid); if (objOid != null && !"".equals(objOid)) { ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation(); conditionMap.put(QueryConditionConstants.TRAINSITIONOID, objOid); ClientBusinessObject ccbo = operation.readBusinessObjectById(objOid, showType); conditionMap.put(QueryConditionConstants.NAME_OID, ccbo.getNameoid()); } String queryTemplate = prm.getFormQtName(); // 提示查询模板未配置 if (queryTemplate == null || queryTemplate.equals("")) { UIFUtils.showMessage(this, "uifmodel.plm.uif.engine.querytemplate.notexits"); return null; } if (isShowLinkType) { dataNode = getLinkObjectDataNode(objOid, conditionMap, processor, queryTemplate, columnsMap, linkType); } else { dataNode = getBusinessObjectDataNode(objOid, conditionMap, processor, queryTemplate, columnsMap, showType); } } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataNode; } /** * 获得查询模板,并根据查询模板设置查询条件 * * @param prm * @param objOid * @param sourceData * @param isShowLinkType * @return */ private Map getQueryTemplateReplaceMap(PRM prm, String objOid, IDataNode sourceData, boolean isShowLinkType) { Map replaceMap = new HashMap(); String queryTemplateName = prm.getFormQtName(); QueryTemplate qt = UIFUtils.getQueryTemplateByName(queryTemplateName); if (qt != null) { Condition cond = qt.getCondition(); if (cond != null) { Map rootMap = new HashMap(); Map globalConditionMap = GlobalContextParam.getInstance().getDefaultConditionMap(); Map ciMap = cond.getCIMap(); Iterator it = ciMap.keySet().iterator(); while (it.hasNext()) { String key = it.next(); ConditionItem ci = ciMap.get(key); if (ci == null) continue; LeafInfo li = ci.getLeafInfo(); if (li == null) continue; // 替换值 String replaceField = li.getValue().getOrdinaryValue(); String replacedValue = ""; if (replaceField.equals(QueryConditionConstants.FROM_OID)) { replacedValue = objOid; } else if (replaceField.equals(UIHelper.OID)) { // 为了不影响原来的配置,如果是BO的表单,oid的值还设置为原来的objOid(objOid在MainDataFrompanel中已经转成了BO的OID) // 对于LO的表单,sourceData应该是一个LO对象,如果是一个BO的话应该在查询模板中配置${ui.inpu....}来获得相关的参数,此时再使用OID // 获得的参数可能会出现错误 if (isShowLinkType) { if (sourceData.getMaterObject() instanceof ClientBusinessObject) { replacedValue = this.regionPanel.getBusinessObjectOid(sourceData); } else if (sourceData.getMaterObject() instanceof ClientLinkObject) { replacedValue = this.regionPanel.getLinkObjectOid(sourceData); } } else { replacedValue = objOid; } } // 基础固有查询条件 else if (globalConditionMap.containsKey(replaceField)) { replacedValue = globalConditionMap.get(replaceField); } else if (replaceField.startsWith("#") && replaceField.endsWith("#")) { replaceField = replaceField.substring(1, replaceField.length() - 1); if (globalConditionMap.containsKey(replaceField)) { replacedValue = globalConditionMap.get(replaceField); } } // 替换值是 ${x}-${y} 形式的 变量 else if (isFreemarkTemplateContent(replaceField)) { Map valueMap = null; if (sourceData != null) valueMap = appendToValueMap(replaceField, sourceData.getValueMap()); // add by xhcao 2014.11.25 begin // 完善 如果被修改的对象来自选择的数据时 // 从被选择数据的valueMap取标记值 if (regionPanel != null) { Object[] secObjs = regionPanel.getDataModel().getSelectObjects(); if (secObjs != null && secObjs.length > 0 && secObjs[0] instanceof IDataNode) { valueMap = appendToValueMap(replaceField, ((IDataNode) secObjs[0]).getValueMap()); } } if (valueMap == null) valueMap = new HashMap(); // add by xhcao 2014.11.25 begin if (rootMap.size() == 0) { rootMap = this.convertValueMapToFPOMap(valueMap); } if (isExistInMap(replaceField, valueMap)) { replacedValue = FreeMarkerCommon.getValueByTempRule(rootMap, replaceFreemarkerField(replaceField)); } else { replacedValue = replaceField; } } // 固定值 else { replacedValue = replaceField; } replaceMap.put(replaceField, replacedValue); } } } return replaceMap; } private String replaceFreemarkerField(String replaceValue) { String src = replaceValue; String field = replaceValue; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; while (!"".equals(field) && begin >= 0 && end < len) { key = field.substring(begin + 2, end); src = src.replace(key, key.replace(".", "_")); field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); } return src; } private Map appendToValueMap(String replaceField, Map valueMap) { String field = replaceField; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; while (!"".equals(field) && begin >= 0 && end < len) { key = field.substring(begin + 2, end); if (!valueMap.containsKey(key)) { valueMap.put(key, key); } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); } return valueMap; } /** * 检查要替换的字段KEY是否全部存在于valueMap中 * * @param replaceField 查询模板中替换值的查询属性值 * @param valueMap dataSource.getValueMap() * @return */ private boolean isExistInMap(String replaceField, Map valueMap) { boolean res = true; String field = replaceField; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; while (!"".equals(field) && begin >= 0 && end < len) { key = field.substring(begin + 2, end); if (!valueMap.containsKey(key)) { System.out.println("变量:" + key + " 在 sourceData.getValueMap() 中不存在。"); return false; } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); res = true; } return res; } private IDataNode getLinkObjectDataNode(String objOid, Map conditionMap, DataModelProcessor processor, String queryTemplate, Map columnsMap, String linkType) throws VCIError, DocumentException { LinkedList dataNodeList = new LinkedList(); @SuppressWarnings("unchecked") Map[] valueMaps = new LinkedHashMap[0]; // conditionMap.put(QueryConditionConstants.FROM_OID, objOid); LinkObject[] los = processor.getLinkObjectByQueryTemplate(queryTemplate, conditionMap); Map> multiTypeLink = new LinkedHashMap>(); for (LinkObject lo : los) { if (multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, "t_btwname")) == null) { List cLink = new LinkedList(); cLink.add(lo); multiTypeLink.put(ObjectTool.getLOAttributeValue(lo, "t_btwname"), cLink); } else { multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, "t_btwname")).add(lo); } // 在LinkObject 加入 linkTypeName 属性 AttributeValue[] avs = Arrays.copyOfRange(lo.hisAttrValList, 0, lo.hisAttrValList.length + 1); AttributeValue av = new AttributeValue("linkTypeName".toLowerCase(), linkType); avs[avs.length - 1] = av; lo.hisAttrValList = avs; // 将数据对象加入到列表 IDataNode dataNode = new DefaultTableNode(); ClientLinkObject clo = new ClientLinkObject(); clo.setLinkObject(lo); dataNode.setMasterObject(clo); dataNodeList.add(dataNode); } Map> referenceKeyMap = processor.getReferenceCol(columnsMap); Iterator referenceKey = referenceKeyMap.keySet().iterator(); List referenceList = new LinkedList(); while (referenceKey.hasNext()) { referenceList.add(referenceKey.next()); } List> listRes = new LinkedList>(); Iterator itor = multiTypeLink.keySet().iterator(); while (itor.hasNext()) { String cType = itor.next(); List cLinkList = multiTypeLink.get(cType); valueMaps = CBOHelper.getLOValueMap(cLinkList.toArray(new LinkObject[] {})); Map rowRefMap = new LinkedHashMap(); Map rowKeyMap = new LinkedHashMap(); for (LinkObject lo : cLinkList.toArray(new LinkObject[] {})) { String oid = lo.oid; String refKey = ""; // XXX 在referenceList大于一的时候会落掉其他的参照查询 // 如果通过循环把其它的参照加进来的话查出的值是null // 测试使用MBOM下级零部件的修改按钮 if (referenceList.size() > 0) { refKey = referenceList.get(0); oid = ObjectTool.getLOAttributeValue(lo, refKey); } rowRefMap.put(oid, refKey); rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid); // if(referenceList.isEmpty()) { // rowRefMap.put(oid, refKey); // rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid); // } else { // for(String key : referenceList) { // refKey = key; // oid = ObjectTool.getLOAttributeValue(lo, refKey); // rowRefMap.put(oid, refKey); // rowKeyMap.put(ObjectUtility.getNewObjectID36(), oid); // } // } } Map secQueryMap = processor.getQueryLinkObjectCondition(linkType, rowKeyMap, rowRefMap, referenceKeyMap); RefPath[] refPaths = processor.queryReference(secQueryMap, cType); connectSecondQueryResult(valueMaps, refPaths, secQueryMap, referenceKeyMap); for (Map resMap : valueMaps) { listRes.add(resMap); } } for (int i = 0; i < listRes.size(); i++) { IDataNode dataNode = dataNodeList.get(i); dataNode.setValueMap(listRes.get(i)); } IDataNode dataNode = null; if (dataNodeList.size() != 0) { dataNode = dataNodeList.get(0); } return dataNode; } private IDataNode getBusinessObjectDataNode(String objOid, Map conditionMap, DataModelProcessor processor, String queryTemplate, Map columnsMap, String showType) throws VCIError, DocumentException { LinkedList dataNodeList = new LinkedList(); @SuppressWarnings("unchecked") Map[] valueMaps = new LinkedHashMap[0]; // 传入分页参数 BusinessObject[] objs = processor.getBusinessObjectByQueryTemplate(queryTemplate, conditionMap); Map> referenceKeyMap = processor.getReferenceCol(columnsMap); Iterator referenceKey = referenceKeyMap.keySet().iterator(); List referenceList = new LinkedList(); while (referenceKey.hasNext()) { referenceList.add(referenceKey.next()); } Map> rowRefMap = new LinkedHashMap>(); for (BusinessObject obj : objs) { String oid = obj.oid; Map refMap = new LinkedHashMap(); for (int j = 0; j < referenceList.size(); j++) { String refKey = referenceList.get(j); String refVal = ObjectTool.getBOAttributeValue(obj, refKey); refMap.put(refKey, refVal); } rowRefMap.put(oid, refMap); // 将数据对象加入到列表 IDataNode dataNode = new DefaultTableNode(); ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(obj); dataNode.setMasterObject(cbo); dataNodeList.add(dataNode); } Map emptypMap = new HashMap(); if (rowRefMap.size() == 1) { Iterator itor = rowRefMap.keySet().iterator(); while (itor.hasNext()) { Map crowMap = rowRefMap.get(itor.next()); Iterator rowMap = crowMap.keySet().iterator(); List removeList = new ArrayList(); while (rowMap.hasNext()) { String ckey = rowMap.next(); String value = crowMap.get(ckey); if (value == null || value.trim().equals("")) { removeList.add(ckey); } } int len = removeList.size(); for (int i = 0; i < len; i++) { List list = referenceKeyMap.get(removeList.get(i)); emptypMap.put(removeList.get(i), ""); for (int j = 0; j < list.size(); j++) { emptypMap.put(list.get(j), ""); } crowMap.remove(removeList.get(i)); referenceKeyMap.remove(removeList.get(i)); } } } Map secQueryMap = processor.getQueryBusinessObjectCondition(showType, rowRefMap, referenceKeyMap); RefPath[] refPaths = processor.queryReference(secQueryMap, showType); valueMaps = CBOHelper.getBOValueMap(objs); connectSecondQueryResult(valueMaps, refPaths, secQueryMap, referenceKeyMap); for (int i = 0; i < valueMaps.length; i++) { IDataNode dataNode = dataNodeList.get(i); valueMaps[i].putAll(emptypMap); dataNode.setValueMap(valueMaps[i]); } IDataNode dataNode = null; if (dataNodeList.size() != 0) { dataNode = dataNodeList.get(0); } return dataNode; } private void connectSecondQueryResult(Map[] res, RefPath[] refPaths, Map secQueryMap, Map> referenceKeyMap) { if (refPaths != null) { int colNum = secQueryMap.size(); for (int i = 0; i < res.length; i++) { Map rowVal = res[i]; for (int j = 0; j < colNum; j++) { String key = secQueryMap.keySet().toArray(new String[colNum])[j]; if (referenceKeyMap.containsKey(key)) { continue; } // TODO 获取value的显示值,如果为enum类型,应该显示名称 if (refPaths[j].values.length <= i) { continue; } String cVal = refPaths[j].values[i].value; rowVal.put(secQueryMap.keySet().toArray(new String[colNum])[j], cVal); } } } } /** * 将业务对象的数据值设置到UI控件上 * * @param cboObj BO、LO、或是文件夹对象 * @param reloadFromDB */ private void setValueToUIControl(Object cboObj, boolean reloadFromDB) { String oid = ""; if (cboObj instanceof ClientBusinessObject) { // 如果是BO对象 oid = ((ClientBusinessObject) cboObj).getBusinessObject().oid; } else if (cboObj instanceof ClientLinkObject) { // 如果是LO对象 oid = ((ClientLinkObject) cboObj).getLinkObject().oid; } else { } if (reloadFromDB) { dataNodeObject = getDataNodeFromBoLoId(oid); if (dataNodeObject == null) { dataNodeObject = new DefaultTableNode(); } } else { dataNodeObject.setMasterObject(cboObj); } if (dataNodeObject.getMaterObject() instanceof ClientBusinessObject) { this.cbo = (ClientBusinessObject) dataNodeObject.getMaterObject(); } else if (dataNodeObject.getMaterObject() instanceof ClientLinkObject) { this.clo = (ClientLinkObject) dataNodeObject.getMaterObject(); } Map objValMap = dataNodeObject.getValueMap(); HashMap comptMap = getCtrlComptMap(); for (Iterator i = comptMap.keySet().iterator(); i.hasNext();) { String field = i.next(); loadComboBoxData(field); // add by caill 解决点击修改时责任人不能根据选中的责任部门自动带入的问题 // String value = cbo.getAttributeValue(field); // if(value == null || "".equals(value)){ // value = dataNodeObject.getValueMap().get(field); // } String value = objValMap.get(field); if (field.equalsIgnoreCase("lcstatus")) { value = operation.transferLifecycle(value); } if (value == null) { value = ""; } // 如果 新查询的valueMap中不存在field的值,且field又设置过默认值, // 此时显示此设置的默认值 if (value.equals("") && getComptDefValMap().containsKey(field)) { value = getComptDefValMap().get(field); } if (!comptMap.containsKey(field)) continue; Component compt = comptMap.get(field); PRMItem item = itemMap.get(field); if (compt instanceof JTextComponent) { ((JTextComponent) compt).setText(value); } else if (compt instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) compt; AttribItem fieldDef = AttributeChecker.attrItemMap.get(field); ComboBoxModel model = cbx.getModel(); if ((fieldDef != null && fieldDef.vtDataType.equals("VTBoolean")) || isEnumAttr(field)) { // 遍历所有下拉框选项 for (int j = 0; j < model.getSize(); j++) { Object Obj = model.getElementAt(j); if (Obj instanceof VCIJComboBoxModelValueObject) { VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj; // 比较是否与业务对象属性值相同 if (value.equals(vo.getValue())) { model.setSelectedItem(vo); break; } } if (item.getItemCustomClass() != null && !item.getItemCustomClass().equals("")) { } } } else if (model != null && model.getSize() > 0) { // add by caill 使配置的下拉列表项显示名字而不是id for (int j = 0; j < model.getSize(); j++) { Object Obj = model.getElementAt(j); if (Obj instanceof VCIJComboBoxModelValueObject) { VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) Obj; // 比较是否与业务对象属性值相同 if (value.equals(vo.getValue())) { model.setSelectedItem(vo); break; } } if (item.getItemCustomClass() != null && !item.getItemCustomClass().equals("")) { } } } else { DefaultComboBoxModel cmodel = new DefaultComboBoxModel(); VCIJComboBoxModelValueObject voe = new VCIJComboBoxModelValueObject("", ""); VCIJComboBoxModelValueObject vo = new VCIJComboBoxModelValueObject(value, value); cmodel.addElement(voe); cmodel.addElement(vo); cmodel.setSelectedItem(vo); cbx.setModel(model); } } else if (compt instanceof ICustomControl) { ICustomControl ctrl = (ICustomControl) compt; // 将控件与数据主对象 ctrl.setDataNode(dataNodeObject); if (ctrl instanceof RefObjChooseControl) { String refObjField = item.getItemListVal(); String refObjKey = item.getItemField() + "." + refObjField; String refObjVal = value; if (objValMap.containsKey(refObjKey)) { refObjVal = objValMap.get(refObjKey); } else { // 重新加载对象 try { // 根据“item.getItemField()”参照属性获取btmName String itemField = item.getItemField(); if (itemField.indexOf(".") > 0) { String[] strs = itemField.split("\\."); itemField = strs[strs.length - 1]; } AttribItem attribItem = ApProvider.getAbItemByName(itemField); OtherInfo otherInfo = OtherInfo.getOtherInfoByText(attribItem.other); String btmName = otherInfo.getRefTypeName(); ClientBusinessObject tempbo = new ClientBusinessObjectOperation() .readBusinessObjectById(value, btmName); if (tempbo != null) { refObjVal = ObjectTool.getBOAttributeValue(tempbo.getBusinessObject(), refObjField); } if (refObjVal == null || refObjVal.equals("")) { // add xchao 2014.08.21 begin // 如果bo的refObjField属性值为空,则显示" " refObjVal = " "; // add xchao 2014.08.21 end } } catch (Exception e) { e.printStackTrace(); } } value = value + "," + refObjVal; } ctrl.setValue(value); } } } private boolean isEnumAttr(String field) { boolean res = false; String[] fields = field.split("\\."); AttribItem attr = ApProvider.getAbItemByName(fields[fields.length - 1]); if (attr == null) return false; String enumName = ApProvider.getOtherValueByType(attr.other, "enumName"); if (enumName == null || "".equals(enumName)) return false; EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName); if (enumItem == null) return false; res = true; return res; } // // /** // * 设置页面空间的值 // * 在编辑,浏览link对象的时候 // * 有可能使用的是BO的Form,也有可能是有的是LO的Form // * @param clo // */ // private void setValueToUIControl(ClientLinkObject clo, boolean // reloadFromDB){ // this.clo = clo; // } /** * 从控件中获取最新值 * * @return */ public Map getNewValueMapFromUI() { HashMap valueMap = new HashMap(); HashMap comptMap = getCtrlComptMap(); for (Iterator i = comptMap.keySet().iterator(); i.hasNext();) { String field = i.next(); Component compt = comptMap.get(field); String value = ""; if (compt instanceof JTextComponent) { value = ((JTextComponent) compt).getText(); } else if (compt instanceof VCIJComboBox) { VCIJComboBox cbx = (VCIJComboBox) compt; ComboBoxModel model = cbx.getModel(); Object selectObj = model.getSelectedItem(); if (selectObj instanceof VCIJComboBoxModelValueObject) { VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) selectObj; value = vo.getValue(); } } else if (compt instanceof ICustomControl) { ICustomControl ctrl = (ICustomControl) compt; value = ctrl.getValue(); } if (value instanceof String) { value = value.trim(); } valueMap.put(field, value); } return valueMap; } /** * 从控件中获取最新值 * * @return */ @Deprecated public Map getNewValueMap() { return this.getNewValueMapFromUI(); } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getContext() { return context; } public void setContext(String context) { this.context = context; } public PLDefination getDefination() { return defination; } public void setDefination(PLDefination defination) { this.defination = defination; } public DataModelFactory getFactory() { return factory; } public void setFactory(DataModelFactory factory) { this.factory = factory; } public Map getParamsMap() { return paramsMap; } public void setParamsMap(Map paramsMap) { this.paramsMap = paramsMap; } public HashMap getCtrlComptMap() { return ctrlComptMap; } public void setCtrlComptMap(HashMap ctrlComptMap) { this.ctrlComptMap = ctrlComptMap; } public Map getValueMapNew() { return valueMapNew; } public void setValueMapNew(Map valueMapNew) { this.valueMapNew = valueMapNew; } public Map getValueMapOriginal() { return valueMapOriginal; } public void setValueMapOriginal(Map valueMapOriginal) { this.valueMapOriginal = valueMapOriginal; } public OperateType getOperateType() { return operateType; } public void setOperateType(OperateType operateType) { this.operateType = operateType; } public int getTypeFlag() { return typeFlag; } public void setTypeFlag(int typeFlag) { this.typeFlag = typeFlag; } /** * 获得IDataNode * * @param isCheck 判断是否需要进行数据控件校验 * @return */ public IDataNode getDataNodeObject(boolean isCheck) { if (!setUIValueToMasterObject(dataNodeObject, isCheck)) { return null; } return dataNodeObject; } /** * 封装窗口数据 * * 在此进行数据校验 * * 此处不判断是创建BO对象还是创建LO对象 根据表单类型,如果表单类型是业务类型,直接创建BO对象 如果表单类型是link类型则创建LO和BO对象 * * 如果是选择窗口在封装数据时不需要校验to端对象的属性 * * @param dataNodeObject * @param isCheck 是否需要进行控件校验 */ @SuppressWarnings("deprecation") private boolean setUIValueToMasterObject(IDataNode dataNodeObject, boolean isCheck) { try { if (isAdd() || isEdit() || isSelect()) { // 业务对象属性校验 BusinessObjectAttributeChecker boacer = new BusinessObjectAttributeChecker( ClientContextVariable.getFrame() == null ? new JLabel() : ClientContextVariable.getFrame()); // 进行控件校验 Map valueMapNew = this.getNewValueMapFromUI(); // List itemList = itemMap; // 业务对象界面属性(此处的非空校验是在设置创建界面时设置的) if (itemMap.size() != 0 && isCheck) { Iterator it = itemMap.keySet().iterator(); while (it.hasNext()) { // 如果设置原色在界面上显示并且设置为必填项 PRMItem item = itemMap.get(it.next()); if (item.getItemCols() != null && !item.getItemCols().trim().equals("") && !item.getItemCols().equals("0") && item.getItemIsRequired() != null && item.getItemIsRequired().equals("1")) { String tempStr = valueMapNew.get(item.getItemField()); if (tempStr == null || tempStr.equals("")) { UIFUtils.showMessage(ClientContextVariable.getFrame(), "uifmodel.plm.uif.actions.validate.999", item.getItemName()); return false; } } } } // 进行属性校验,检验属性时只校验LO或BO对象固有的属性 if (typeFlag == 0) { // 表单上只有BO对象的属性 // 业务对象属性 Map boAttrMap = new HashMap(); // 此处的BO对象应该是在窗口初始化的时候set的一个空的业务对象 ClientBusinessObject cbo = null; // 构建一个空的BO对象,主要是用来或的BO对象所具有的属性 ClientBusinessObject emptyBO = null; if (isAdd()) { cbo = (ClientBusinessObject) dataNodeObject.getMaterObject(); emptyBO = cbo; } else if (isEdit()) { cbo = this.cbo; emptyBO = operation.createEmptyClientBusinessObject(this, cbo.getBusinessObject().btName); } else if (isSelect()) { cbo = (ClientBusinessObject) ((IDataNode) selectedDatas[0]).getMaterObject(); emptyBO = operation.createEmptyClientBusinessObject(this, cbo.getBusinessObject().btName); } // 得到业务对象属性集合 AttributeValue[] avs = emptyBO.getBusinessObject().newAttrValList; // 这三个属性是固定的 boAttrMap.put("id", valueMapNew.get("id") == null ? "" : valueMapNew.get("id")); boAttrMap.put("name", valueMapNew.get("name") == null ? "" : valueMapNew.get("name")); boAttrMap.put("description", valueMapNew.get("description") == null ? "" : valueMapNew.get("description")); if (avs != null && avs.length > 0) { for (AttributeValue av : avs) { String attrName = av.attrName.toLowerCase(); // 当时编辑时只需要设置页面上能够修改的属性,对于隐藏的属性不需要重新设置newAttrValList if (valueMapNew.containsKey(attrName)) { // add by zgy 2015-02,保证非UI界面的数据保留 if (isEdit()) { if (valueMapNew.containsKey(attrName)) { boAttrMap.put(attrName, valueMapNew.get(attrName) == null ? "" : valueMapNew.get(attrName)); } } else { boAttrMap.put(attrName, valueMapNew.get(attrName) == null ? "" : valueMapNew.get(attrName)); } } } } // 选择窗口不进行TO对象的属性校验 // 也不需要设置对象属性 if (!isSelect()) { boolean result = boacer.validateAttr(boAttrMap); if (!result) { return false; } serUIValueObject(boAttrMap, cbo, valueMapNew, ""); } Map valueMap = dataNodeObject.getValueMap(); if (valueMap != null && valueMap.size() > 0) { valueMap.putAll(valueMapNew); } dataNodeObject.setValueMap(valueMap); } else if (typeFlag == 1) { // 保单上BO的属性是以t_oid开头的和LO的属性 // link对象属性 Map loAttrMap = new HashMap(); // 业务对象属性 Map boAttrMap = new HashMap(); // 此处的LO对象应该是在窗口初始化的时候set的一个空的链接对象 ClientLinkObject clo = this.clo; clo.getLinkObject().ltName = defination.getLinkType(); // 构建一个空的LO对象,主要是用来获得LO对象所具有的属性 ClientLinkObject emptyLO = operation.createEmptyClientLinkObject(this, defination.getLinkType()); if (emptyLO == null) { return false; } // link对象属性 AttributeValue[] loav = emptyLO.getLinkObject().newAttrValList; if (loav != null && loav.length > 0) { for (AttributeValue av : loav) { String attrVal = ""; String attrName = av.attrName.toLowerCase(); if (valueMapNew.containsKey(attrName) && valueMapNew.get(attrName) != null) { attrVal = valueMapNew.get(attrName); loAttrMap.put(attrName, attrVal); } } } // 校验link对象属性 boolean result = boacer.validateAttr(loAttrMap); if (!result) { return false; } // 根据link的信息得到一个空的to端对象 ClientBusinessObject to = null; // 构建一个空的BO对象,主要是用来或的BO对象所具有的属性 ClientBusinessObject emptyBO = null; if (isAdd()) { to = operation.createEmptyClientBusinessObject(this, defination.getShowType()); emptyBO = to; } else if (isEdit()) { emptyBO = operation.createEmptyClientBusinessObject(this, clo.getLinkObject().toBTName); to = operation.reloadClientBusinessObject(this, clo.getLinkObject().toOid, clo.getLinkObject().toBTName); } else if (isSelect()) { IDataNode selectNode = (IDataNode) this.selectedDatas[0]; to = (ClientBusinessObject) selectNode.getMaterObject(); // XXX 表单类型中有目标对象的类型 该如何获得 if (clo.getLinkObject().toBTName == null || clo.getLinkObject().toBTName.equals("")) { emptyBO = to; } else { emptyBO = operation.createEmptyClientBusinessObject(this, clo.getLinkObject().toBTName); } } if (to == null || emptyBO == null) { return false; } // 如果对应form类型是link类型,则业务对象是以t_oid.或是t_oid开头的,其它的是link对象的属性 // 业务对象属性 AttributeValue[] avs = emptyBO.getBusinessObject().newAttrValList; // 这三个属性是固定的 String idVal = ""; String heard = "t_oid"; if (direction) { heard = "t_oid"; } else { heard = "f_oid"; } if (valueMapNew.containsKey(heard + ".id")) { idVal = valueMapNew.get(heard + ".id"); } else if (valueMapNew.containsKey(heard + "id")) { idVal = valueMapNew.get(heard + "id"); } boAttrMap.put("id", idVal); String nameVal = ""; if (valueMapNew.containsKey(heard + ".name")) { nameVal = valueMapNew.get(heard + ".name"); } else if (valueMapNew.containsKey(heard + "name")) { nameVal = valueMapNew.get(heard + "name"); } boAttrMap.put("name", nameVal); String descriptionVal = ""; if (valueMapNew.containsKey(heard + ".description")) { descriptionVal = valueMapNew.get(heard + ".description"); } else if (valueMapNew.containsKey(heard + "description")) { descriptionVal = valueMapNew.get(heard + "description"); } boAttrMap.put("description", descriptionVal); if (avs != null && avs.length > 0) { for (AttributeValue av : avs) { String attrVal = ""; String attrName = av.attrName.toLowerCase(); if (valueMapNew.containsKey(heard + "." + attrName)) { attrVal = valueMapNew.get(heard + "." + attrName); boAttrMap.put(attrName, attrVal == null ? "" : attrVal); } else if (valueMapNew.containsKey(heard + "" + attrName)) { attrVal = valueMapNew.get(heard + "" + attrName); boAttrMap.put(attrName, attrVal == null ? "" : attrVal); } } } // 如果是选择添加时,不需要校验选择的BO对象的属性,也不用设置BO对象的属性 if (!isSelect()) { result = boacer.validateAttr(boAttrMap); if (!result) { return false; } serUIValueObject(boAttrMap, to, valueMapNew, heard + "."); } // 设置LO,BO属性 serUIValueObject(loAttrMap, clo); ClientLOAndBOData clbo = new ClientLOAndBOData(); clbo.setData(clo, to); dataNodeObject.setMasterObject(clbo); dataNodeObject.setValueMap(valueMapNew); } } } catch (Exception e) { UIFUtils.showErrorMessage(this, e); return false; } return true; } /** * 设置BO对象属性 如果是创建时需要判断是否是主属性 如果是修改则将修改的信息全部保存到BO属性中 * * @param valueMap * @param cbo * @throws VCIError */ private void serUIValueObject(Map valueMap, ClientBusinessObject cbo, Map valueMapNew, String header) throws VCIError { Iterator it = valueMap.keySet().iterator(); while (it.hasNext()) { String field = it.next(); String value = valueMap.get(field); if (isAdd() || isSelect()) { cbo.setAttributeValue(field, value, true); } else if (isEdit()) { if ((field.equalsIgnoreCase("id") || field.equalsIgnoreCase("name") || field.equalsIgnoreCase("description")) && !valueMapNew.containsKey(header + field)) { continue; } cbo.setAttributeValue(field, value); } } } /** * 设置LO对象属性 * * @param valueMap * @param clo * @throws VCIError */ private void serUIValueObject(Map valueMap, ClientLinkObject clo) throws VCIError { Iterator it = valueMap.keySet().iterator(); while (it.hasNext()) { String field = it.next(); String value = valueMap.get(field); clo.setAttributeValue(field, value); } } public void setDataNodeObject(IDataNode dataNodeObject) { this.dataNodeObject = dataNodeObject; } private boolean isFreemarkTemplateContent(String itemValue) { return UIFUtils.isFreemarkTemplateContent(itemValue); } @Deprecated // by zhonggy 2015-06 public void setUIControlDefaultValue(IDataNode dataNode) { Iterator it = this.itemMap.keySet().iterator(); Map rootMap = this.convertValueMapToFPOMap(dataNode.getValueMap()); while (it.hasNext()) { String field = it.next(); PRMItem item = this.itemMap.get(field); Component compt = this.ctrlComptMap.get(field); if (item == null || compt == null) continue; String itemValue = item.getItemValue(); if (itemValue == null || "".equals(itemValue)) continue; String defaultValue = itemValue; // 如果是Freemark的模板格式 if (isFreemarkTemplateContent(itemValue)) { // update by xchao 2014.03.26 begin // 修复 如果模板规则中的属性(字段)在 dataNode.getValueMap() 中不存在时,则将计算后的值处理为空 // ${t_oid.notfound}-${f_oid.notfound} String rule = itemValue; int start = rule.indexOf("${"); int end = rule.indexOf("}"); boolean allFieldExistInMap = true; while (start >= 0 && end >= 0 && start < end && end < rule.length()) { String fieldRule = rule.substring(start + 2, end); rule = rule.substring(end + 1); if (!dataNode.getValueMap().containsKey(fieldRule)) { String tempValue = this.regionPanel.getBaseLayoutPanel().getValue(fieldRule); if (tempValue.equals(fieldRule)) { defaultValue = ""; } else { defaultValue = tempValue; } allFieldExistInMap = false; break; } start = rule.indexOf("${"); end = rule.indexOf("}"); } // update by xchao 2014.03.26 end if (allFieldExistInMap) { defaultValue = FreeMarkerCommon.getValueByTempRule(rootMap, itemValue.replace(".", "_")); defaultValue = this.regionPanel.getBaseLayoutPanel().getValue(defaultValue); } } else if (itemValue.indexOf("#") == 0) { defaultValue = getGloableVariableDefaultValue(itemValue); } else if (dataNode.getValueMap().containsKey(itemValue)) { defaultValue = dataNode.getValueMap().get(itemValue); } if (compt instanceof JTextComponent) { // 文本控件 JTextComponent txt = (JTextComponent) compt; txt.setText(defaultValue); } else if (compt instanceof VCIJComboBox) { // 枚举、值列表的下拉列表控件 VCIJComboBox cbx = (VCIJComboBox) compt; setComboxDefaultValue(item, cbx, defaultValue); } else if (compt instanceof RefObjChooseControl) { RefObjChooseControl roc = (RefObjChooseControl) compt; setRocDefaultValue(item, roc, defaultValue); } else if (compt instanceof DateTimeControl) { DateTimeControl dtc = (DateTimeControl) compt; dtc.setValue(defaultValue); } else if (compt instanceof BaseCustomControl) { BaseCustomControl bcc = (BaseCustomControl) compt; UserObject userObj = getUserObjectByName(defaultValue); if (userObj != null) { // 用户账号##VCI##用户姓名 存储值##VCI##显示值 String value = userObj.getUserName() + ICustomAttributeInteceptor.SPLIT_CHAR + userObj.getTrueName() + "(" + userObj.getUserName() + ")"; bcc.setValue(value); } } } } /** * 设置UI界面的全局默认值 */ @Deprecated // by zhonggy 2015-06 public void setUIGloableDefaultValue() { Iterator it = this.itemMap.keySet().iterator(); while (it.hasNext()) { String field = it.next(); PRMItem item = this.itemMap.get(field); Component compt = this.ctrlComptMap.get(field); if (item == null || compt == null) continue; String itemValue = item.getItemValue(); if (itemValue == null || "".equals(itemValue)) continue; String defaultValue = itemValue; // 如果是Freemark的模板格式 if (isFreemarkTemplateContent(itemValue)) { defaultValue = ""; String key = itemValue; String value = defaultValue; String valueFromUILayout = this.regionPanel.getBaseLayoutPanel().getValue(key); if (!valueFromUILayout.equals(key)) { value = valueFromUILayout; } defaultValue = value; } else if (itemValue.indexOf("#") == 0) { defaultValue = getGloableVariableDefaultValue(itemValue); } if (defaultValue == null || defaultValue.trim().equals("")) { continue; } if (compt instanceof JTextComponent) { // 文本控件 JTextComponent txt = (JTextComponent) compt; txt.setText(defaultValue); } else if (compt instanceof VCIJComboBox) { // 枚举、值列表的下拉列表控件 VCIJComboBox cbx = (VCIJComboBox) compt; setComboxDefaultValue(item, cbx, defaultValue); } else if (compt instanceof RefObjChooseControl) { RefObjChooseControl roc = (RefObjChooseControl) compt; setRocDefaultValue(item, roc, defaultValue); } else if (compt instanceof DateTimeControl) { DateTimeControl dtc = (DateTimeControl) compt; dtc.setValue(defaultValue); } else if (compt instanceof BaseCustomControl) { BaseCustomControl bcc = (BaseCustomControl) compt; UserObject userObj = getUserObjectByName(defaultValue); if (userObj != null) { // 用户账号##VCI##用户姓名 存储值##VCI##显示值 String value = userObj.getUserName() + ICustomAttributeInteceptor.SPLIT_CHAR + userObj.getTrueName() + "(" + userObj.getUserName() + ")"; bcc.setValue(value); } } } } public UserObject getUserObjectByName(String userName) { // 根据存储的值,通过查询,得到显示的值 UserObject userObj = null; try { userObj = new RightManagementClientDelegate().getUserObjectByUserName(userName); } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); VCIJOptionPane.showError(ClientContextVariable.getFrame(), "查询责任人显示值发生错误" + e.toString()); } return userObj; } private String getGloableVariableDefaultValue(String key) { if (key.equalsIgnoreCase("#CURRENTUSER.ID#")) { return ClientContextVariable.getVariablebyKey("CURRENTUSER.ID"); } else if (key.equalsIgnoreCase("#CURRENTTIME#")) { return getDataTime(); } else if (key.equalsIgnoreCase("#CURRENTUSER.EMAIL#")) { return ClientContextVariable.getVariablebyKey("CURRENTUSER.EMAIL"); } else if (key.equalsIgnoreCase("#CURRENTUSER.NAME#")) { return ClientContextVariable.getVariablebyKey("CURRENTUSER.NAME"); } else if (key.equalsIgnoreCase("#CURRENTUSER.SECRETGRADE#")) { return ClientContextVariable.getVariablebyKey("CURRENTUSER.SECRETGRADE"); } else if (key.equalsIgnoreCase("#CURRENTUSER.GROUPNUM#")) { return ClientContextVariable.getVariablebyKey("CURRENTUSER.GROUPNUM"); } return ""; } /** * 获取当前时间,暂时支持yyyy-MM-dd的格式显示 * * @return */ private String getDataTime() { String format = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(format); String dateString = sdf.format(Calendar.getInstance().getTime()); return dateString; } public void setComboxDefaultValue(PRMItem item, VCIJComboBox cbx, String defaultValue) { DefaultComboBoxModel cbxModel = (DefaultComboBoxModel) cbx.getModel(); int existIndex = getComboBoxValueIndex(cbxModel, defaultValue); if (existIndex >= 0) { cbx.setSelectedItem(cbxModel.getElementAt(existIndex)); } else { VCIJComboBoxModelValueObject cbxVo = new VCIJComboBoxModelValueObject(defaultValue, defaultValue); cbxModel.addElement(cbxVo); cbx.setModel(cbxModel); cbx.setSelectedItem(cbxVo); } } private int getComboBoxValueIndex(DefaultComboBoxModel cbxModel, String newValue) { int res = -1; for (int i = 0; i < cbxModel.getSize(); i++) { Object obj = cbxModel.getElementAt(i); if (obj instanceof VCIJComboBoxModelValueObject) { VCIJComboBoxModelValueObject cbxVO = (VCIJComboBoxModelValueObject) obj; if (cbxVO.getValue().equals(newValue)) { res = i; break; } } } return res; } public void setRocDefaultValue(PRMItem item, RefObjChooseControl roc, String defaultValue) { if ("".equals(defaultValue)) return; String type = item.getItemListTable(); String oid = defaultValue; String showColumn = item.getItemListVal(); ClientBusinessObject refCbo = getClientBusinessObjectbyByRefTypeAndOid(type, oid); if (refCbo == null) { return; } String showValue = ""; if (refCbo != null) { showValue = refCbo.getAttributeValue(showColumn); } String newValue = defaultValue + "," + showValue; roc.setValue(newValue); roc.firePropertyChangeManual(RefObjChooseControl.REF_OBJECT_CHANGED, "", CBOHelper.getBOValueMap(refCbo.getBusinessObject())); } private ClientBusinessObject getClientBusinessObjectbyByRefTypeAndOid(String type, String oid) { ClientBusinessObject cbo = null; try { QueryTemplate qt9 = new QueryTemplate(); qt9.setId("btmQuery"); qt9.setBtmType(type); qt9.setRightFlag(false); qt9.setType("btm"); qt9.setQueryChildrenFlag(true); List clauseList = new ArrayList(); clauseList.add("*"); qt9.setClauseList(clauseList); Map conditions = new HashMap(); conditions.put("oid", oid); Condition cond = OQTool.getCondition(conditions); qt9.setCondition(cond); BusinessObject[] bos = QTClient.getService().findBTMObjects(qt9.getId(), OQTool.qtTOXMl(qt9).asXML()); if (bos != null && bos.length > 0) { cbo = new ClientBusinessObject(); cbo.setBusinessObject(bos[0]); } } catch (VCIError e) { e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); } if (cbo == null || cbo.getOid().equals("")) { return null; } return cbo; } public Map convertValueMapToFPOMap(Map map) { Map rootMap = new LinkedHashMap(); Iterator it = map.keySet().iterator(); while (it.hasNext()) { String key = it.next(); String value = map.get(key); String valueFromUILayout = this.regionPanel.getBaseLayoutPanel().getValue(key); if (!valueFromUILayout.equals(key)) { value = valueFromUILayout; } else { // 尝试从表单控件上取值 if (value.equals(key)) { value = getValueFromUIControl(key); } } if (value == null) { value = ""; } String newKey = key.replace(".", "_"); FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value); rootMap.put(newKey, fpo); } return rootMap; } public Object[] getSelectedDatas() { return selectedDatas; } public void setSelectedDatas(Object[] selectedDatas) { this.selectedDatas = selectedDatas; } public boolean isDirection() { return direction; } public void setDirection(boolean direction) { this.direction = direction; } public HashMap getItemMap() { return itemMap; } public IRegionPanel getRegionPanel() { return regionPanel; } public void setRegionPanel(IRegionPanel regionPanel) { this.regionPanel = regionPanel; } /** * 各组件对应的默认值Map */ private Map comptDefValMap = new HashMap(); /** * 返回 各组件对应的默认值Map * * @return */ public Map getComptDefValMap() { return comptDefValMap; } /** * 设置 各组件对应的默认值Map * * @param hasDefValComptMap 各组件对应的默认值Map */ public void setComptDefValMap(Map comptDefValMap) { this.comptDefValMap = comptDefValMap; } private DefaultValueController defaultValueController = null; public void setUIFormFieldDefaultValue(AbstractBatchBusionessOperationAction sourceBtm, IDataNode iDataNode) { if (defaultValueController == null) { defaultValueController = new DefaultValueController(); defaultValueController.setFormPanel(this); } setComptDefValMap(defaultValueController.setUIFormFieldDefaultValue(sourceBtm, iDataNode)); } }