package com.vci.client.uif.engine.client.tree; 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.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObject; import com.vci.client.bof.ClientLinkObjectOperation; import com.vci.client.common.ConfigUtils; import com.vci.client.common.FreeMarkerCommon; import com.vci.client.common.FreemarkerParamObject; import com.vci.client.common.oq.OQTool; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer; import com.vci.client.omd.provider.ApProvider; import com.vci.client.oq.QTClient; import com.vci.client.oq.QTDClient; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.KJButton; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.VCIJSplitPane; import com.vci.client.ui.tree.VCIBaseTree; import com.vci.client.ui.tree.VCIBaseTreeNode; import com.vci.client.uif.actions.client.BusinessOperationAction; import com.vci.client.uif.actions.client.UIFUtils; import com.vci.client.uif.engine.client.AbstractRegionPanel; import com.vci.client.uif.engine.client.BasePanel; import com.vci.client.uif.engine.client.IRegionPanel; import com.vci.client.uif.engine.client.UIBaseLayoutPanel; import com.vci.client.uif.engine.client.UIHelper; import com.vci.client.uif.engine.client.UILayoutPanel; import com.vci.client.uif.engine.client.event.UIEventConstanct; import com.vci.client.uif.engine.client.tableArea.TablePanelButtonAreaPanel; import com.vci.client.uif.engine.common.CBOHelper; 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.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.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.qtm.QTInfo; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLCommandParameter; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLTabButton; import com.vci.corba.query.data.BOAndLO; import com.vci.mw.ClientContextVariable; import com.vci.omd.objects.OtherInfo; import com.vci.omd.utils.ObjectTool; /** * 导航树区域面板(内嵌导航树) */ public class TreePanel extends AbstractRegionPanel { private static final long serialVersionUID = -8980866528220213674L; //add by caill start private BusinessOperationAction boa = null; private ClientBusinessObject cbo = null; //add by caill end private JLabel searchLbl = new JLabel("查找:"); private JTextField searchTxt = new JTextField(); private KJButton searchBtn = new KJButton("", "search.gif"); private TreeNode rootNode = new TreeNode("",null); private VCIBaseTree tree = null; private TreePanelModel treeModel = null; private String cStr = null; private Map cSearMap = new HashMap(); private TreePanel instance = null; private boolean isUserClick = true; private String historySelectType = ""; private String historySelectContext = ""; private VCIJPanel palButtonArea = new VCIJPanel(); private TablePanelButtonAreaPanel tbap = null; private VCIJButton btnRefresh = VCISwingUtil.createVCIJButton("refresh", "", "刷新当前选择节点的数据", "refresh.png", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { refresh(); } }); public TreePanel() { treeModel = new TreePanelModel(rootNode, this); this.setDataModel(treeModel); setComponentPanel(this); } @Override public Component init() { this.historySelectType = this.getType(); this.setLayout(new BorderLayout()); JPanel searchPanl = getSearchPanel(); JPanel toolbarPanel = getToolbarPanel(); JScrollPane treePanel = getTreePanel(); JPanel treeArePanel = new JPanel(new BorderLayout()); if(tbap.getBtns().length <= 0){ treeArePanel.add(toolbarPanel, BorderLayout.NORTH); treeArePanel.add(treePanel, BorderLayout.CENTER); }else{ VCIJSplitPane mainSplitPane = new VCIJSplitPane(VCIJSplitPane.VERTICAL_SPLIT); mainSplitPane.setDividerSize(10); mainSplitPane.setDividerLocation(80); mainSplitPane.setContinuousLayout(true); mainSplitPane.setOneTouchExpandable(true); mainSplitPane.setLeftComponent(toolbarPanel); mainSplitPane.setRightComponent(treePanel); treeArePanel.add(mainSplitPane, BorderLayout.CENTER); } add(searchPanl, BorderLayout.NORTH); add(treeArePanel, BorderLayout.CENTER); this.setDataModel(dataModel); instance = this; return this; } private JPanel getToolbarPanel() { tbap = new TablePanelButtonAreaPanel(getTabId(), getType(), getContext(), getDefination(), null, this); tbap.init(); palButtonArea = tbap; VCIJPanel palTitleAndBtn = new VCIJPanel(new BorderLayout()); String tableTitle = "数据列表"; if(this.getTabPage() != null){ // TODO 等待 defination 对象增加 name 属性 tableTitle = getDefination().getName(); } palTitleAndBtn.add(UIHelper.getTitleBar(tableTitle, "base.png"), BorderLayout.NORTH); palTitleAndBtn.add(palButtonArea, BorderLayout.CENTER); return palTitleAndBtn; } /** * 初始创建导航树 */ private JScrollPane getTreePanel() { rootNode.setObj(getRootObject()); rootNode.setUserObject(getRootDisplayValue()); String rootOid = this.getBusinessObjectOid(this.getSourceData()); String linkType = this.getDefination().getLinkType(); String showType = this.getDefination().getShowType(); String showLinkAbs = this.getDefination().getShowLinkAbs(); if (linkType.equals("") && !showType.equals("") && !showLinkAbs.equals("")) { // 参照导航树特殊修正,modify by zhonggy 2015-09-17 ClientBusinessObject cbo = sourceData.getClientBusinessObject(); if (cbo == null || !cbo.getBusinessObject().btName.trim().equals(showType.trim())) { String separator = this.getDefination().getSeparator(); if (separator == null || separator.trim().equals("")) { separator = ","; } if(showLinkAbs.indexOf(separator)>0){ rootOid = showLinkAbs.split(",")[1]; } /*rootNode.setObj(null); // 这个地方先去掉“rootNode.setObj(Null)”by // ligang 2015-10-27; // //当时修改是因为mes项目中“对象修改属性卡 // --〉弹出参照属性选择界面(存在参照导航树)--〉参照导航树构造不出来”,暂这样删除,可能Mes项目还存在问题? // by zhonggy */ } } getTreeData(rootNode, rootOid, this.getDefination().getExpandMode(), isLink()); //treeModel = new TreePanelModel(rootNode, this); tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer(){ private static final long serialVersionUID = 6253740682089786968L; @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){ Component compt = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); VCIBaseTreeNode node = null; if(value instanceof VCIBaseTreeNode){ node = (VCIBaseTreeNode)value; } if(node != null){ if(node.isRoot()){ setIcon(VCISwingUtil.createImageIcon("house.png")); } } return compt; } }); //去掉树节点选择,此处执行时不会触发选择事件,会导致selectObject为空 //tree.setSelectionPath(new TreePath(rootNode)); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { int divSize = -1; JSplitPane mainSplitPane = null; UIBaseLayoutPanel uiBaseLayoutPanel = getBaseLayoutPanel(); if( uiBaseLayoutPanel != null){ if(uiBaseLayoutPanel instanceof UILayoutPanel){ mainSplitPane = ((UILayoutPanel)uiBaseLayoutPanel).getMainSplitPane(); if(mainSplitPane != null){ divSize = mainSplitPane.getDividerLocation(); } } } if(tree.getLastSelectedPathComponent() == null) return; //TODO 点击事件 setSelectedObjects(); String selectEventValue = getSelectionEventValue(); if (selectEventValue != null) { executeEventAction(e, selectEventValue); } else { moduleConfigTree_valueChanged(e); } if(mainSplitPane != null && divSize != -1){ mainSplitPane.setDividerLocation(divSize); } } }); //add by caill start 为树设置双击事件 tree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { final Map eventMap = getDefinationEventMap(); String dbClickEventClass = eventMap.get(UIEventConstanct.DBCLICK_EVENT_KEY); if(e.getButton() == 1 && e.getClickCount() == 2 && (dbClickEventClass != null && !"".equals(dbClickEventClass))){ PLTabButton[] buttons = getTabButtons(getTabId()); if (buttons == null) { return; } for (int i = 0; i < buttons.length; i++) { //当按钮中含有DBClickEvent设置的事件名字时,双击数据执行对应按钮点击时的效果 if (!dbClickEventClass.equals(buttons[i].plLabel)) { continue; } PLAction action; try { action = UITools.getService().getPLActionById(buttons[i].plActionOId); VCIJButton cbtn = new BasePanel().getVCIJButton(buttons[i], (IRegionPanel)getComponentPanel(), action); cbtn.doClick(); break; } catch (VCIError e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //当按钮中不含有DBClickEvent设置的事件名字时,由于tree没有对应表单,所以暂时没有设计默认效果 } } } }); //add by caill end tree.addTreeExpansionListener(new TreeExpansionListener() { @Override public void treeExpanded(TreeExpansionEvent e) { TreePath treepath = e.getPath(); treeExpanded_Handler(treepath); } @Override public void treeCollapsed(TreeExpansionEvent event) { // TODO Auto-generated method stub } }); this.setDataModel(treeModel); JScrollPane jsp = new JScrollPane(); jsp.getViewport().add(tree); return jsp; } //add by caill start /** * 获取事件上的参数 * @return */ protected Map getDefinationEventMap(){ Map map = new HashMap(); String[] eventKeys = getDefination().getEventKey().split(","); String[] eventValues = getDefination().getEventValue().split(","); for (int i = 0; i < eventKeys.length; i++) { String key = eventKeys[i]; if(key.trim().length() == 0) continue; if(i >= eventValues.length) continue; map.put(key, eventValues[i]); } return map; } //add by caill end private String getSelectionEventValue() { String eventKeys = this.getDefination().getEventKey(); if (eventKeys == null || eventKeys.length() == 0) { return null; } String eventVals = this.getDefination().getEventValue(); if (eventVals == null || eventVals.length() == 0) { return null; } String[] keys = eventKeys.split(","); String[] values = eventVals.split(","); if (keys.length != values.length) { return null; } for (int i = 0; i < keys.length; i++) { if (keys[i] != null && keys[i].equals(UIEventConstanct.SELECTION_EVENT_KEY)) { return values[i]; } } return null; } private void executeEventAction(TreeSelectionEvent e, String eventValue) { /* VCIJButton[] buttons = tbap.getBtns(); HashMap buttonParameters = null; for (int i = 0; i < buttons.length; i++) { if (eventValue.equals(buttons[i].getName())) { ActionListener[] als = buttons[i].getActionListeners(); for (int j = 0; j < als.length; j++) { if (als[j] instanceof ButtonActionListener) { ButtonActionListener bal = (ButtonActionListener)als[j]; buttonParameters = buildActionParamsMap(bal.getButton().plOId); break; } } break; } }*/ PLTabButton[] buttons = getTabButtons(getTabId()); if (buttons == null) { System.out.println("executeEventAction has error: not found an buttons."); return; } HashMap buttonParameters = null; for (int i = 0; i < buttons.length; i++) { if (eventValue.equals(buttons[i].plLabel)) { buttonParameters = buildActionParamsMap(buttons[i].plOId); break; } } if (buttonParameters == null) { System.out.println("executeEventAction has error: not found an buttons & parameters."); return; } TreePath treepath = e.getPath(); TreeNode treeNode = (TreeNode)treepath.getLastPathComponent(); Object[] selectObject = new Object[1]; selectObject[0] = treeNode.getObj(); Map valueMap = null; IDataNode dataNode = null; if (treeNode.getObj() instanceof IDataNode) { dataNode = (IDataNode) treeNode.getObj(); valueMap = dataNode.getValueMap(); } String cType = this.getBusinessObjectType(dataNode); String context = buttonParameters.get("context"); if (context != null) { if (isFreemarkExpression(context)) { Map rootMap = this.convertValueMapToFPOMap(valueMap); context = FreeMarkerCommon.getValueByTempRule(rootMap, context); } if (isFreemarkExpression(context)) { System.out.println("executeEventAction has error: context is freemarker exoression."); return; } } else if (buttonParameters.get("contextExpression") != null) { String contextExpression = buttonParameters.get("contextExpression"); context = getExpressionContext(contextExpression, valueMap); } else if (buttonParameters.get("contextProgram") != null || buttonParameters.get("contextMethod") != null) { context = getContextByCustomProgram(buttonParameters.get("contextProgram"), buttonParameters.get("contextMethod"), dataNode); } if (context == null) { System.out.println("executeEventAction has error: not found an context."); return; } String typeParamVal = buttonParameters.get("type"); if(typeParamVal != null && !"".equals(typeParamVal)){ if (isFreemarkExpression(typeParamVal)) { Map rootMap = this.convertValueMapToFPOMap(valueMap); typeParamVal = FreeMarkerCommon.getValueByTempRule(rootMap, context); } if (isFreemarkExpression(typeParamVal)) { System.out.println("executeEventAction has error: type is freemarker exoression."); return; } cType = typeParamVal; }else if (buttonParameters.get("typeExpression") != null) { String typeExpression = buttonParameters.get("typeExpression"); cType = getExpressionContext(typeExpression, valueMap); } else if (buttonParameters.get("typeProgram") != null || buttonParameters.get("typeMethod") != null) { cType = getContextByCustomProgram(buttonParameters.get("typeProgram"), buttonParameters.get("typeMethod"), dataNode); } if (cType == null) { System.out.println("executeEventAction has error: not found type."); return; } if (!cType.equals(this.historySelectType) || !context.equals(historySelectContext)) { System.out.println("executeEventAction pre execution. type:" + cType + " context:" + context ); // add by xchao 2016.09.29 begin // 按此处计算出的业务类型进行加载相关区域 this.getBaseLayoutPanel().reinitRightPanel(dataNode, cType, context); // add by xchao 2016.09.29 end System.out.println("executeEventAction has been execution. type:" + cType + " context:" + context ); historySelectType = cType; historySelectContext = context; return; } this.getDataModel().getUILayoutModel().notify(this.getDataModel()); } private void refresh(){ TreePath treePath = tree.getSelectionPath(); if(treePath == null){ VCIJOptionPane.showMessage(ClientContextVariable.getFrame(), "请先选择数据再进行此操作!"); return; } treeExpanded_Handler(treePath); tree.setSelectionPath(treePath); } private void treeExpanded_Handler(TreePath treePath){ TreeNode treeNode = (TreeNode)treePath.getLastPathComponent(); String cOid = ""; if (rootNode == treeNode) { //根节点的特殊处理 cOid = getBusinessObjectOid((IDataNode)treeNode.getObj()); String linkType = this.getDefination().getLinkType(); String showType = this.getDefination().getShowType(); String showLinkAbs = this.getDefination().getShowLinkAbs(); if (linkType.equals("") && !showType.equals("") && !showLinkAbs.equals("")) { // 参照导航树特殊修正,modify by zhonggy 2015-09-17 ClientBusinessObject cbo = sourceData.getClientBusinessObject(); if (cbo == null || !cbo.getBusinessObject().btName.trim().equals(showType.trim())) { String separator = this.getDefination().getSeparator(); if (separator == null || separator.trim().equals("")) { separator = ","; } if(showLinkAbs.indexOf(separator)>0){ cOid = showLinkAbs.split(",")[1]; } } } }else if(treeNode.getObj() instanceof IDataNode){ cOid = getBusinessObjectOid((IDataNode)treeNode.getObj()); } if (cOid == null || cOid.equals("")) { return; } getTreeData(treeNode, cOid, TreePanel.this.getDefination().getExpandMode(), isLink()); DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); dtm.reload(treeNode); } private void setSelectedObjects(){ TreeNode treeNode = (TreeNode) tree.getLastSelectedPathComponent(); // Object[] selectObject = new Object[1]; // selectObject[0] = treeNode.getObj(); TreePath[] selectedTreePaths = tree.getSelectionPaths(); if (selectedTreePaths == null) return; Object[] selectObject = new Object[selectedTreePaths.length]; for (int i = 0; i < selectedTreePaths.length; i++) { TreeNode node = (TreeNode) selectedTreePaths[i] .getLastPathComponent(); selectObject[i] = node.getObj(); } // 设置Model选择的对象为源对象,便于其他Model使用 this.treeModel.setSelectObjects(selectObject); this.treeModel.setClickObject(treeNode.getObj()); } /** * @Title :moduleConfigTree_valueChanged * @Description :树节点切换处理 * @param e */ private void moduleConfigTree_valueChanged(TreeSelectionEvent e) { TreePath treepath = e.getPath(); TreeNode treeNode = (TreeNode)treepath.getLastPathComponent(); if (!this.isUserClick) { this.setUserClick(true); return; } if (treeNode.getObj() instanceof IDataNode) { IDataNode dataNode = (IDataNode) treeNode.getObj(); String cType = this.getBusinessObjectType(dataNode); if (!cType.equals(this.historySelectType) && !cType.equalsIgnoreCase("folder") && !cType.equals("")) { this.getBaseLayoutPanel().reinitRightPanel(dataNode); historySelectType = cType; return; } } //将当前区域变动触发事件广播到本大页签其它区域(做相应刷新处理) //但是建议框架有一个广播前可广播变化的判断 by zhonggy 2015-02-05 //如:boolean allowNotifyChange = this.getDataModel().getUILayoutModel().preNotify(this.getDataModel()); //各接收preNotify()广播的如返回false,那么可提示原因 this.getDataModel().getUILayoutModel().notify(this.getDataModel()); } private JPanel getSearchPanel() { JPanel searchPanel = new JPanel(new GridBagLayout()); searchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { searchActionPerformed(arg0); } }); searchTxt.setPreferredSize(new Dimension(100, 23)); searchPanel.add(searchLbl, getGBC(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, 1)); searchPanel.add(searchTxt, getGBC(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, 1)); searchBtn.setMinimumSize(new Dimension(23, 23)); searchBtn.setMaximumSize(new Dimension(23, 23)); searchBtn.setPreferredSize(new Dimension(23, 23)); searchPanel.add(searchBtn, getGBC(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, 1)); btnRefresh.setMinimumSize(new Dimension(23, 23)); btnRefresh.setMaximumSize(new Dimension(23, 23)); btnRefresh.setPreferredSize(new Dimension(23, 23)); searchPanel.add(btnRefresh, getGBC(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, 1)); searchTxt.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if(!searchTxt.getText().trim().equals("") && e.getKeyCode() == KeyEvent.VK_ENTER){ searchBtn.doClick(); } } }); return searchPanel; } 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); } private void searchActionPerformed(ActionEvent arg0) { String searchVal = searchTxt.getText(); if (searchVal.equals("")) { JOptionPane.showMessageDialog(ClientContextVariable.getFrame(), "请填写需要查询的条件进行查找!"); return; } if (rootNode.toString().indexOf(searchVal) >= 0 && !isSearched(rootNode, searchVal)) { tree.setSelectionPath(new TreePath(rootNode.getPath())); } else { if (rootNode.getChildCount() == 0) { JOptionPane.showMessageDialog(ClientContextVariable.getFrame(), "导航树查找完毕!"); return; } this.setFinish(false); this.setCancel(false); startSearch(searchVal); } } private void startSearch(final String searchVal) { final SearchTipDialog[] tipDialog = new SearchTipDialog[1]; tipDialog[0] = new SearchTipDialog(ClientContextVariable.getFrame(), new Thread(){ public void run() { try{ iteratorTree(rootNode, searchVal); if (TreePanel.this.isFinish()) { return; } else { TreePanel.this.setFinish(true); JOptionPane.showMessageDialog(ClientContextVariable.getFrame(), "导航树查找完毕!"); } }catch(Exception e){ e.printStackTrace(); }finally{ tipDialog[0].setVisible(false); } } }, instance); tipDialog[0].setVisible(true); } private void iteratorTree(TreeNode parentNode, String searchVal) { int count = parentNode.getChildCount(); if (count == 0) { return; } for (int i = 0; i < count; i++) { if (isCancel()) { return; } TreeNode cNode = (TreeNode)parentNode.getChildAt(i); if (cNode.toString().indexOf(searchVal) >= 0 && !isSearched(cNode, searchVal)) { this.setFinish(true); tree.setSelectionPath(new TreePath(cNode.getPath())); return; } iteratorTree(cNode, searchVal); } } /** * 判断当前节点是否被查询过 * @param cNode * @param searchVal * @return */ private boolean isSearched(TreeNode cNode, String searchVal) { if (cStr == null) { cStr = searchVal; cSearMap.clear(); } else if (!cStr.equals(searchVal)) { cStr = searchVal; cSearMap.clear(); } String key = ""; Object nodeObj = cNode.getObj(); if (nodeObj instanceof String) { if (cSearMap.containsKey((String)nodeObj)) { return true; } else { cSearMap.put((String)nodeObj, nodeObj); } } else if(nodeObj instanceof IDataNode){ Object masterObj = (((IDataNode) nodeObj).getMaterObject()); if(masterObj instanceof ClientBusinessObject){ ClientBusinessObject cbo = (ClientBusinessObject)masterObj; key = cbo.getBusinessObject().oid; } else if(masterObj instanceof ClientLinkObject){ ClientLinkObject clo = (ClientLinkObject)masterObj; key = clo.getLinkObject().oid; } } else if(nodeObj instanceof BOAndLO) { BOAndLO bolo = (BOAndLO)nodeObj; key =bolo.bo.oid + bolo.lo.oid; } if (cSearMap.containsKey(key)) { return true; } else { cSearMap.put(key, nodeObj); } return false; } private QueryTemplate getQueryTemplate(String fromId, IDataNode sourceData) throws VCIError, DocumentException { String templateId = this.getDefination().getTemplateId(); QTInfo wrapper = ServiceProvider.getOMDService().getQTDService().getQT(templateId); QueryTemplate qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), templateId); Map replaceMap = this.getQueryTemplateReplaceMap(qt, sourceData); replaceMap.put("f_oid", fromId); //反向Link怎么办? -- zhonggy QueryTemplate qt_ = OQTool.replaceQTValues(qt, replaceMap); return qt_; } /** * 返回查询模板查询替换查询条件MAP * @param qt * @return */ private Map getQueryTemplateReplaceMap(QueryTemplate qt,IDataNode sourceData) { Map map = new HashMap(); Map valueMap = new HashMap(); Object masterObject = null; if (sourceData == null) { return map; } else { masterObject = sourceData.getMaterObject(); valueMap = sourceData.getValueMap(); } if (qt == null) return map; Condition cond = qt.getCondition(); if (cond == null) return map; 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); // add by xhao 2014.04.16 begin // 异常现象:查询模板显示,只定义了两个替换条件 // 但此时查询出的替换条件确有3三 // 第三个 ci对象不为空,但其leafInfo为空 // 因此针对此情况进行判空处理 if (ci == null) continue; LeafInfo li = ci.getLeafInfo(); if (li == null) continue; // add by xhao 2014.04.16 end // 替换值(对查询模板中"t_oid"/"f_oid"/"oid"的替换) String replaceField = li.getValue().getOrdinaryValue(); String replacedValue = ""; //这种替换不是很规范(有些混乱)!!! by zhonggy 2015-06 if (replaceField.equals("t_oid")) { replacedValue = CBOHelper.getBusinessObjectOid(sourceData); } else if (replaceField.equals("f_oid")) { replacedValue = CBOHelper.getBusinessObjectOid(sourceData); } else if (replaceField.equals("oid")) { if (masterObject instanceof ClientBusinessObject) { replacedValue = CBOHelper.getBusinessObjectOid(sourceData); } else if (masterObject instanceof ClientLinkObject) { replacedValue = CBOHelper.getLinkObjectOid(sourceData); } } // 基础固有查询条件 --> 也建议能统一(如统一通过"#基础条件#"表达) by zhonggy 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 (isFreemarkExpression(replaceField)) { valueMap = appendToValueMap(replaceField, valueMap); if (rootMap.size() == 0) { rootMap = this.convertValueMapToFPOMap(valueMap); } if (isExistInMap(replaceField, valueMap)) { replacedValue = FreeMarkerCommon.getValueByTempRule(rootMap, replaceField.replace(".", "_")); } else { replacedValue = replaceField; } } // 固定值 else { replacedValue = replaceField; } map.put(replaceField, replacedValue); } return map; } private Map appendToValueMap(String replaceField/*如:${x}-${y} */, 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; } /** * @Title :需要特殊处理replaceField中参照、枚举与生命周期值 * @Description : * @param replaceField * @param valueMap * @return */ private Map appendToValueMapExt(String replaceField/*如:${x}-${y} */, Map valueMap){ String field = replaceField; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; Map rtnMap = new HashMap(); while(!"".equals(field) && begin >= 0 && end < len){ key = field.substring(begin + 2, end); key = key.trim().toLowerCase(); if(!key.trim().equals("") && !valueMap.containsKey(key)){ //valueMap.put(key, "?"); //?表示可继续处理 //key = "t_oid.ownproduct.name" String[] keyStrings = key.split("\\."); if (keyStrings.length > 1) { String lastSplitStr = keyStrings[keyStrings.length -1]; String otherSplitStr = key.substring(0, key.length() - lastSplitStr.length() - 1); //t_oid.ownproduct if (valueMap.containsKey(otherSplitStr)) { String refValue = valueMap.get(otherSplitStr); if (refValue != null && refValue.trim().length() == 36) { // 有效参照属性定义 valueMap.put(key, "?"); //rtnMap.put(key, refValue); // 待参照处理集合 String refAttrName = otherSplitStr; if (refAttrName.split("\\.").length > 1) { refAttrName = refAttrName.split("\\.")[1]; }else { refAttrName = otherSplitStr; } AttribItem attribItem = ApProvider.getAbItemByName(refAttrName); OtherInfo otherInfo = OtherInfo.getOtherInfoByText(attribItem.other); String refTypeName = otherInfo.getRefTypeName(); String refAttrValue = ""; try { ClientBusinessObject object = (new ClientBusinessObjectOperation()).readBusinessObjectById(refValue, refTypeName); refAttrValue = object.getAttributeValue(lastSplitStr); String enumAttrDisplayValue = TreePanelUtil.getEnumAttrDisplayValue(lastSplitStr,refAttrValue); if (!enumAttrDisplayValue.equals("")) { //属于枚举属性 refAttrValue = enumAttrDisplayValue; }else { //额外判断是否生命周期属性 String lifeCycleStatusDisplay = TreePanelUtil.getLifeCycleStatusDisplay(lastSplitStr,refAttrValue); if (!lifeCycleStatusDisplay.equals("")) { refAttrValue = lifeCycleStatusDisplay; } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } if (refAttrValue == null) { refAttrValue = ""; } valueMap.put(key, refAttrValue); }else { //非有效参照属性[目前暂只支持一级参照],直接界面提示出来(方便提示用户修改) if (refValue == null || refValue.trim().equals("")) { valueMap.put(key, ""); }else{ valueMap.put(key, ""); } } }else { //非有效参照属性[目前暂只支持一级参照],直接界面提示出来(方便提示用户修改) valueMap.put(key, key); } }else { //非参照直接显示空 valueMap.put(key, ""); } }else if(!key.equals("")){ //处理枚举或生命周期属性 if (valueMap.containsKey(key)) { //如:emunAttr、lifecycleAttr String enumAttrDisplayValue = TreePanelUtil.getEnumAttrDisplayValue(key,valueMap.get(key)); if (!enumAttrDisplayValue.equals("")) { //属于枚举属性 valueMap.put(key, enumAttrDisplayValue); }else { //额外判断是否生命周期属性 String lifeCycleStatusDisplay = TreePanelUtil.getLifeCycleStatusDisplay(key,valueMap.get(key)); if (!lifeCycleStatusDisplay.equals("")) { valueMap.put(key, lifeCycleStatusDisplay); } } } } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); } return rtnMap; } /** * 检查要替换的字段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)){ return false; } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); res = true; } return res; } private 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.getBaseLayoutPanel().getValue(key); if(!valueFromUILayout.equals(key)){ value = valueFromUILayout; } if(value == null){ value = ""; } String newKey = key.replace(".", "_"); FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value); rootMap.put(newKey, fpo); } return rootMap; } /** * 判断指定字符是否是 freemaker表达式格式 * @param itemValue * @return */ @SuppressWarnings("unused") // unused By ZhongGY private boolean isFreemarkTemplateContent(String itemValue){ int startPos = itemValue.indexOf("${"); int endPos = itemValue.indexOf("}"); return (startPos >= 0 && endPos >= 0 && startPos < endPos); } /** * @Title :是否统一的参数表达式 * @Description : * @param expression * @param valueMap * @return */ private boolean isFreemarkExpression(String expression){ try { boolean res = true; String field = expression; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = null; while(!"".equals(field) && begin >= 0 && end < len){ key = field.substring(begin + 2, end); if (key == null || key.trim().equals("")) { return false; } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); res = true; } if (key == null || key.trim().equals("")) { return false; } return res; } catch (Exception e) { return false; } } /** * 判断获取的子节点是否为link类型 * @return */ private boolean isLink() { String linkType = this.getDefination().getLinkType(); if (linkType == null || linkType.trim().equals("")) { return false; } return true; } /** * 根据OID和类型名称获取指定的业务对象 * @param id * @param type * @return */ private IDataNode getBusinessObject(String id, String type) { IDataNode dataNode = new DefaultTableNode(); ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation(); try { ClientBusinessObject object = operation.readBusinessObjectById(id, type); dataNode.setMasterObject(object); dataNode.setValueMap(CBOHelper.getBOValueMap(object.getBusinessObject())); return dataNode; } catch (VCIError e) { e.printStackTrace(); } return null; } /** * 根据link oid和链接类型获取指定的链接对象 * @param id * @param type * @return */ private ClientLinkObject getLinkObject(String id, String type) { ClientLinkObjectOperation operation = new ClientLinkObjectOperation(); try { ClientLinkObject object = operation.readLinkObjectById(id, type); return object; } catch (Exception e) { e.printStackTrace(); } return null; } /** * 获取导航树树节点构成(以及树节点文本显示) * @Title :getTreeData * @Description : * @param parentNode :父节点 * @param boOID :业务对象OID * @param expandMode:逐层展开/全部展开 * @param isLink :是否Link构成树 */ private void getTreeData(TreeNode parentNode, String boOID, String expandMode, boolean isLink) { parentNode.removeAllChildren(); try { QueryTemplate qt = getQueryTemplate(boOID, (IDataNode)parentNode.getObj()); if (isLink) { BOAndLO[] bolos = QTClient.getService().getBOAndLOS(qt.getId(), OQTool.qtTOXMl(qt).asXML(), ""); for (int i = 0; i < bolos.length; i++) { /*TreeNode treeNode = new TreeNode(getDisplayValue(bolos[i].bo, bolos[i].lo), constructLinkNode(bolos[i].bo, bolos[i].lo));*/ IDataNode nodeData = constructLinkNode(bolos[i].bo, bolos[i].lo); TreeNode treeNode = new TreeNode(getDisplayValueExt(nodeData,bolos[i].bo, bolos[i].lo), nodeData); treeNode.setBusinessObject(bolos[i].bo); treeNode.setLinkObject(bolos[i].lo); if (bolos[i].lo.toNameOid.equals(bolos[i].bo.nameoid)) { treeNode.setToBO(true); //正向 }else{ treeNode.setToBO(false); //反向 } parentNode.insert(treeNode, parentNode.getChildCount()); if (expandMode != null && expandMode.equals("0")) { getTreeData(treeNode, bolos[i].bo.oid, expandMode, isLink); } else { QueryTemplate qtc = getQueryTemplate(bolos[i].bo.oid, (IDataNode)treeNode.getObj()); BOAndLO[] bolosc = QTClient.getService().getBOAndLOS(qtc.getId(), OQTool.qtTOXMl(qtc).asXML(), ""); boolean isLeaf = bolosc.length <= 0; treeNode.setLeaf(isLeaf); if(isLeaf){ treeNode.setExpand(true); } } } } else { //参照构成结构树 BusinessObject[] bos = QTClient.getService().findBTMObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML()); for (int i = 0; i < bos.length; i++) { IDataNode nodeData =constructBoNode(bos[i]); /*TreeNode treeNode = new TreeNode(getDisplayValue(bos[i], null), constructBoNode(bos[i]));*/ TreeNode treeNode = new TreeNode(getDisplayValueExt(nodeData,bos[i], null), nodeData); treeNode.setBusinessObject(bos[i]); parentNode.insert(treeNode, parentNode.getChildCount()); if (expandMode != null && expandMode.equals("0")) { getTreeData(treeNode, bos[i].oid, expandMode, isLink); } else { QueryTemplate qtc = getQueryTemplate(bos[i].oid, (IDataNode)treeNode.getObj()); BusinessObject[] bosc = QTClient.getService().findBTMObjects(qtc.getId(), OQTool.qtTOXMl(qtc).asXML()); boolean isLeaf = bosc.length <= 0; treeNode.setLeaf(isLeaf); if(isLeaf){ treeNode.setExpand(true); } } } } } catch (VCIError e) { e.printStackTrace(); } catch (DocumentException d) { d.printStackTrace(); } } private IDataNode constructBoNode(BusinessObject bo) { IDataNode dataNode = new DefaultTableNode(); ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(bo); dataNode.setMasterObject(cbo); //BO对象 dataNode.setValueMap(CBOHelper.getBOValueMap(bo)); //BO对象属性 return dataNode; } /** * 构建Link结构树节点数据对象 * @Title :constructLinkNode * @Description : * @param bo * @param lo * @return */ private IDataNode constructLinkNode(BusinessObject bo, LinkObject lo) { IDataNode dataNode = new DefaultTableNode(); ClientLinkObject lot = new ClientLinkObject(); lot.setLinkObject(lo); dataNode.setMasterObject(lot); Map dataMap = new HashMap(); //lo对象属性+bo对象属性(但未处理参照属性) //设置lo属性 for (int i = 0; i < lo.hisAttrValList.length; i++) { dataMap.put(lo.hisAttrValList[i].attrName.toLowerCase(), lo.hisAttrValList[i].attrVal); } //构建前缀 String suffix = ""; /*String direction = this.getDefination().getOrientation(); //展开方向不需要设置,通过查询模板即可明确方向,多此一举 modify by zhonggy 2015-06 if(direction != null && direction.equals("positive")){ suffix = "t_oid."; //正向 }else if (direction != null && direction.equals("opposite")){ suffix = "f_oid."; //反向 }*/ if (lo.toOid.equals(bo.oid)) { suffix = "t_oid."; //正向 dataNode.setForward(true); }else if (lo.fromOid.equals(bo.oid)){ suffix = "f_oid."; //反向 dataNode.setForward(false); }else { suffix = ""; //数据存在问题 } //设置bo属性 if (!suffix.equals("")) { for (int i = 0; i < bo.hisAttrValList.length; i++) { dataMap.put(suffix + bo.hisAttrValList[i].attrName.toLowerCase(), bo.hisAttrValList[i].attrVal); } } dataNode.setValueMap(dataMap); return dataNode; } /** * 返回 最后选择的树节点 */ public TreeNode getSelectTreeNode(){ return (TreeNode) tree.getLastSelectedPathComponent(); } /** * 获取根树节点名称 * @Title :getRootDisplayValue * @Description : * @return */ @SuppressWarnings("deprecation") public String getRootDisplayValue() { BusinessObject rootBO = null; LinkObject rootLO = null; if (this.getRootObject() == null || this.getRootObject().getMaterObject() == null) return ""; if (this.getRootObject().getMaterObject() instanceof String) { String rootContent = getDefination().getRootContent(); if(rootContent != null && !"".equals(rootContent)){ return rootContent; } //modify songyf 2014.11.12 修改文件类型的根节点在conf中查找, // 如果不存在则查找国际化文件,不存在 // 则返回设置的值 String name = (String) this.getRootObject().getMaterObject(); String showName = ConfigUtils.getConfigValue("uifmodel.plm.uif.engine.folder.name." + name); if(showName != null && !showName.equals("")) { try { showName = new String(showName.getBytes("ISO-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return showName; } showName = LocaleDisplay.getI18nString("uifmodel.plm.uif.engine.folder.name." + (String) this.getRootObject().getMaterObject(), "UIFModelAction", this.getLocale()); if(showName != null && !showName.equals("")) { name = showName; } if(name.equals("uifmodel.plm.uif.engine.folder.name." + (String) this.getRootObject().getMaterObject())){ name = UIFUtils.getI18nString("plm.uif.treePanel.rootContent"); } return name; } else if (this.getRootObject().getMaterObject() instanceof ClientBusinessObject) { rootBO = ((ClientBusinessObject)this.getRootObject().getMaterObject()).getBusinessObject(); } else if (this.getRootObject().getMaterObject() instanceof ClientLinkObject) { rootLO = ((ClientLinkObject)this.getRootObject().getMaterObject()).getLinkObject(); String suffix = ""; if (this.getRootObject().isForward()) { //初始加载树节点时已赋值 suffix = "t_oid."; //正向 }else { suffix = "f_oid"; //反向 } String lo_boid = this.getRootObject().getValueMap().get(suffix + "oid"); String lo_btmname= this.getRootObject().getValueMap().get(suffix + "btmname"); if (lo_boid != null && !lo_boid.trim().equals("") && lo_btmname != null && !lo_btmname.trim().equals("")) { IDataNode dataNode = this.getBusinessObject(lo_boid, lo_btmname); if (dataNode != null && dataNode.getMaterObject() != null && dataNode.getMaterObject() instanceof ClientBusinessObject) { rootBO = ((ClientBusinessObject)dataNode.getMaterObject()).getBusinessObject(); } } } if(rootBO != null || rootLO != null) { /*return getDisplayValueExt(this.getRootObject(),rootBO,rootLO); */ IDataNode nodeData = this.getRootObject(); String nodeText = ""; String displayStr = getDefination().getRootContent();//树节点文本显示统一定义(支持复杂表达式) if (displayStr == null || displayStr.trim().equals("")) { displayStr = this.getDefination().getShowAbs(); //树节点文本显示统一定义(支持复杂表达式) } if (isFreemarkExpression(displayStr)) { //新逻辑 Map valueMap = nodeData.getValueMap(); // Map refValueMap = appendToValueMapExt(displayStr, valueMap); Map rpoMap = new HashMap(); rpoMap = this.convertValueMapToFPOMap(valueMap); /*if (isExistInMap(displayStr, valueMap)) { nodeText = FreeMarkerCommon.getValueByTempRule(rpoMap, displayStr.replace(".", "_")); } else { nodeText = displayStr; }*/ nodeText = FreeMarkerCommon.getValueByTempRule(rpoMap, displayStr.replace(".", "_")); }else { //原逻辑 String displayValue = getDisplayValue(rootBO,rootLO,true); if (displayValue != null && !displayValue.trim().equals("")) { nodeText = displayValue; }else { nodeText = displayStr; } } return nodeText; }else { return null; } } private IDataNode sourceData = null; // @Override /** * 根据结构树定义统一修正源对象 by zhongGY 2015-06-17 */ public IDataNode getRootObject() { if (sourceData == null) { sourceData = super.getSourceData(); if (sourceData == null || sourceData.getMaterObject() == null) { return sourceData; } Object masterOBJ = sourceData.getMaterObject(); /*Map valueMap = sourceData.getValueMap();*/ String linkType = this.getDefination().getLinkType(); if (linkType != null && !linkType.trim().equals("")) { //Link链接类型构造树 BusinessObject bo = null; LinkObject lo = null; if (masterOBJ instanceof ClientLinkObject) { ClientLinkObject lot = (ClientLinkObject)masterOBJ; if (lot.getLinkObject().ltName.trim().toLowerCase().equals(linkType.trim().toLowerCase())) { return sourceData; } } bo = sourceData.getClientBusinessObject().getBusinessObject(); lo = new LinkObject(); lo.ltName = linkType; lo.hisAttrValList = new AttributeValue[] {}; lo.newAttrValList = new AttributeValue[] {}; String direction = this.getDefination().getOrientation(); //展开方向设置目前仅在构造根节点有用 by zhonggy 2015-06 if(direction != null && direction.equals("positive")){ //suffix = "t_oid."; 正向 lo.toBTName = bo.btName; lo.toNameOid = bo.nameoid; lo.toOid=bo.oid; lo.toRevOid = bo.revisionid; lo.hisAttrValList = new AttributeValue[] { new AttributeValue("t_oid", bo.oid), new AttributeValue("T_REVISIONOID".toLowerCase(), bo.revisionid), new AttributeValue("T_NAMEOID".toLowerCase(), bo.nameoid), new AttributeValue("T_BTWNAME".toLowerCase(), bo.btName) }; }else if (direction != null && direction.equals("opposite")){ //suffix = "f_oid.";反向 lo.fromBTName = bo.btName; lo.fromNameOid = bo.nameoid; lo.fromOid=bo.oid; lo.fromRevOid = bo.revisionid; lo.hisAttrValList = new AttributeValue[] { new AttributeValue("f_oid", bo.oid), new AttributeValue("f_REVISIONOID".toLowerCase(), bo.revisionid), new AttributeValue("f_NAMEOID".toLowerCase(), bo.nameoid), new AttributeValue("f_BTWNAME".toLowerCase(), bo.btName) }; } sourceData = this.constructLinkNode(bo, lo) ; }else { String bizType = this.getDefination().getShowType(); if (bizType != null && !bizType.trim().equals("")) { //参照结构够成树 if (masterOBJ instanceof ClientBusinessObject) { return sourceData; } BusinessObject bo = null; if (sourceData.getClientBusinessObject() != null && sourceData.getClientBusinessObject().getBusinessObject() != null) { bo = sourceData.getClientBusinessObject().getBusinessObject(); if (bo != null && bo.btName.equals(bizType)) { sourceData = this.constructBoNode(bo); return sourceData; } } //如果顶级节点为配置的字符串时,将其转换为BO modify by liucq 2015-11-24 bo = new BusinessObject(); String emptyBoOid = ""; if (getDefination().getShowLinkAbs() != null && getDefination().getShowLinkAbs().split(",").length == 2) { emptyBoOid = getDefination().getShowLinkAbs().split(",")[1]; } else { emptyBoOid = this.getType(); } sourceData = new DefaultTableNode(); sourceData.setMasterObject(emptyBoOid); sourceData.setValueMap(new HashMap()); return sourceData; } } } return sourceData; } @SuppressWarnings("unused") private String getDisplayBOValue(BusinessObject bo) { String displayStr = this.getDefination().getShowAbs(); String separator = this.getDefination().getSeparator(); String[] displayArray = displayStr.split(separator); String displayText = ""; boolean isFirst = true; for (int i = 0; i < displayArray.length; i++) { if (isFirst) { isFirst = false; } else { displayText += " "; } displayText += ObjectTool.getBOAttributeValue(bo, displayArray[i]); } return displayText; } /** * 获取树节点文本的统一显示(可统一基于表达式) Add By ZhongGY 2015-06 * @Title :getDisplayValueExt * @Description : * @return */ private String getDisplayValueExt(IDataNode nodeData,BusinessObject bo,LinkObject lo){ String nodeText = ""; String displayStr = this.getDefination().getShowAbs(); //树节点文本显示统一定义(支持复杂表达式) if (isFreemarkExpression(displayStr)) { //新逻辑 Map valueMap = nodeData.getValueMap(); //Map refValueMap = @SuppressWarnings("unused") appendToValueMapExt(displayStr, valueMap); Map rpoMap = new HashMap(); rpoMap = this.convertValueMapToFPOMap(valueMap); /*if (isExistInMap(displayStr, valueMap)) { nodeText = FreeMarkerCommon.getValueByTempRule(rpoMap, displayStr.replace(".", "_")); } else { nodeText = displayStr; }*/ nodeText = FreeMarkerCommon.getValueByTempRule(rpoMap, displayStr.replace(".", "_")); }else { //原逻辑 nodeText = getDisplayValue(bo,lo,false); } return nodeText; } /** * @Title :树节点文本显示处理(OLD) * @Description : * @param bo:树节点关联的BO对象 * @param lo:树节点关联的LO对象 * @return */ private String getDisplayValue(BusinessObject bo, LinkObject lo,boolean isRootNode) { String displayStr = this.getDefination().getShowAbs(); //树节点文本显示统一定义(支持复杂表达式) if (isRootNode) { displayStr = this.getDefination().getRootContent(); } String linkStr = this.getDefination().getShowLinkAbs(); //显示Link属性(可废弃) String separator = this.getDefination().getSeparator(); //分隔符(可废弃) String[] displayArray = displayStr.split(separator); //所有显示属性(需要重新处理) String[] linkArray = linkStr.split(separator); //单独link属性(可废弃) String linkType = this.getDefination().getLinkType(); //获取Link类型 String displayText = ""; boolean isFirst = true; for (int i = 0; i < displayArray.length; i++) { if (isFirst) { isFirst = false; } else { displayText += " "; } if (bo != null) { displayText += ObjectTool.getBOAttributeValue(bo, displayArray[i]); } } if (linkType == null || linkType.trim().equals("")) { return displayText; } //如果存在Link类型属性显示 for (int i = 0; i < linkArray.length; i++) { if (isFirst) { isFirst = false; } else { displayText += " "; } displayText += ObjectTool.getLOAttributeValue(lo, linkArray[i]); } if(isRootNode && displayText.trim().equals("")){ displayText = this.getDefination().getRootContent(); } return displayText; } private void refreshTreeNode() { TreeNode treeNode = (TreeNode)this.tree.getSelectionPath().getLastPathComponent(); String treeObjOid = ""; String treeObjType = ""; if (treeNode.getObj() instanceof IDataNode) { IDataNode dataNode = (IDataNode) treeNode.getObj(); if (dataNode.getMaterObject() instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject)dataNode.getMaterObject(); treeObjOid = cbo.getOid(); treeObjType = cbo.getBtmName(); IDataNode cDataNode = this.getBusinessObject(treeObjOid, treeObjType); ClientBusinessObject tempCbo = (ClientBusinessObject) cDataNode.getMaterObject(); if(tempCbo.getBusinessObject().oid.equals("")) { treeNode = (TreeNode) treeNode.getParent(); } else { BusinessObject bo = ((ClientBusinessObject)cDataNode.getMaterObject()).getBusinessObject(); String nodeText = this.getDisplayValueExt(cDataNode,bo, null); treeNode.setUserObject(nodeText);//getDisplayBOValue() treeNode.setObj(cDataNode); } } else if (dataNode.getMaterObject() instanceof ClientLinkObject) { ClientLinkObject clo = (ClientLinkObject)dataNode.getMaterObject(); String suffix = ""; /*String direction = this.getDefination().getOrientation(); //展开方向不需要设置,通过查询模板即可明确方向,多此一举 modify by zhonggy 2015-06 if(direction != null && direction.equals("positive")){ suffix = "t_oid."; }else if (direction != null && direction.equals("opposite")){ suffix = "f_oid."; }*/ if (dataNode.isForward()) { //初始加载树节点时已赋值 suffix = "t_oid."; //正向 }else { suffix = "f_oid"; //反向 } BusinessObject bo = ((ClientBusinessObject)this.getBusinessObject(dataNode.getValueMap().get(suffix + "oid"), dataNode.getValueMap().get(suffix + "btmname")).getMaterObject()).getBusinessObject(); LinkObject lo = this.getLinkObject(clo.getOid(), clo.getLoName()).getLinkObject(); if((lo == null || lo.oid.equals("")) && treeNode.getParent() != null) { treeNode = (TreeNode) treeNode.getParent(); } else { if (lo == null || lo.oid.equals("")) { lo = clo.getLinkObject(); } treeNode.setBusinessObject(bo); treeNode.setLinkObject(lo); /*treeNode.setUserObject(this.getDisplayValue(bo, lo));*/ //private String getDisplayValueExt(IDataNode nodeData,BusinessObject bo,LinkObject lo){ IDataNode nodeData = constructLinkNode(bo, lo); treeNode.setUserObject(this.getDisplayValueExt(nodeData,bo, lo)); //modify by zhongGY ClientLinkObject currentClo = new ClientLinkObject(); currentClo.setLinkObject(lo); dataNode.setMasterObject(currentClo); treeNode.setObj(nodeData); } } } this.setUserClick(false); treeExpanded_Handler(new TreePath(treeNode.getPath())); if(tree.isPathSelected(new TreePath(treeNode.getPath()))) { setSelectedObjects(); } else { tree.setSelectionPath(new TreePath(treeNode.getPath())); } tree.updateUI(); // add by xchao 2014.04.16 begin // 修复 此刷新之后,切换树节点时,在 // moduleConfigTree_valueChanged 事件处理中会判断 isUserClick,如果等于false,则不进行刷新 // 而此时是需要刷新的,因此将其设置为 true this.setUserClick(true); // add by xchao 2014.04.16 end } public boolean isUserClick() { return isUserClick; } public void setUserClick(boolean isUserClick) { this.isUserClick = isUserClick; } public VCIBaseTree getTree(){ return tree; } private HashMap buildActionParamsMap(String buttonOid){ HashMap paramsMap = new HashMap(); // 查询出Button上定义的参数,传递给Action // 一般必须要定义 type、context // 即:表明该Buttonr要操作哪个业务类型、使用该业务类型的哪个上下文 // 在Action 的具体的实现中,将提取上面两个参数,进行相关初始化操作 try { PLCommandParameter[] btnParams = UITools.getService().getPLCommandParametersByCommandOId(buttonOid); for(PLCommandParameter cp : btnParams){ String key = cp.plKey; String value = cp.plValue; paramsMap.put(key, value); } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } return paramsMap; } private String getExpressionContext(String contextExpression, Map valueMap) { HashMap equalMap = new HashMap(); HashMap notequalMap = new HashMap(); String[] contextExpArray = contextExpression.split(";"); for (int i = 0; i < contextExpArray.length; i++) { String context = contextExpArray[i].substring(contextExpArray[i].indexOf(")") + 1); String singleConditionStr = contextExpArray[i].substring(contextExpArray[i].indexOf("(") + 1, contextExpArray[i].indexOf(")")); String[] conditionArray = singleConditionStr.split(","); for (int j = 0; j < conditionArray.length; j++) { if (conditionArray[j].indexOf("!=") > 0) { String[] conditions = conditionArray[j].split("!="); notequalMap.put(conditions[0], conditions[1]); } else if (conditionArray[j].indexOf("=") > 0) { String[] conditions = conditionArray[j].split("="); equalMap.put(conditions[0], conditions[1]); } } boolean isRight = isRightContext(context, valueMap, equalMap, notequalMap); if (isRight) { return context; } equalMap.clear(); notequalMap.clear(); } return null; } private boolean isRightContext(String context, Map valueMap, Map equalMap, Map notequalMap) { boolean rs = false; Iterator itor = equalMap.keySet().iterator(); while (itor.hasNext()) { String key = itor.next(); String selectVal = valueMap.get(key); String value = equalMap.get(key); if (selectVal == null || value == null) { return false; } if (selectVal.equals(value)) { rs = true; } else { rs = false; return rs; } } itor = notequalMap.keySet().iterator(); while (itor.hasNext()) { String key = itor.next(); String selectVal = valueMap.get(key); String value = notequalMap.get(key); if (selectVal == null || value == null) { return rs; } if (!selectVal.equals(value)) { rs = true; } else { rs = false; return rs; } } return rs; } private PLTabButton[] getTabButtons(String tabId){ PLTabButton[] buttons = null; try { PLPageDefination[] pageDef = UITools.getService().getPLPageDefinationsByPageContextOId(tabId); String pageDefId = pageDef[0].plOId; buttons = UITools.getService().getPLTabButtonsByTableOId(pageDefId); } catch (VCIError e) { e.printStackTrace(); } return buttons; } private String getContextByCustomProgram(String program, String method, IDataNode dataNode) { try { @SuppressWarnings("rawtypes") Class c=Class.forName(program); Object obj=c.newInstance(); @SuppressWarnings("unchecked") Method m = c.getMethod(method,new Class[]{Object.class}); Object rs = m.invoke(obj,new Object[]{dataNode}); if (rs != null) { return rs.toString(); } } catch (Throwable e) { e.printStackTrace(); } return null; } /** * 刷新界面 ?by zhonggy 2015-07 */ public void refreshUI(){ this.refreshTreeNode(); } }